# Submission a3468977...

Challenge Integer sorting zac.creditmint.eth 2018-01-27 302438
``````/**
* This file is part of the 1st Solidity Gas Golfing Contest.
*
*/

pragma solidity ^0.4.23;

contract Sort {
/**
* @dev Sorts a list of integers in ascending order.
*
* The input list may be of any length.
*
* @param input The list of integers to sort.
* @return The sorted list.
*/

function sort(uint[] input) external view returns(uint[]) {
assembly {
calldatacopy(0, 0x04, calldatasize)
if eq(calldatasize, 0x44) {
return(0x00, 0x40)
}
let it := 0x60
let size := sub(calldatasize, 0x24)
check_if_perfect_start:
jumpi(check_if_perfect_start, lt(it, end))
return(0x00, add(end, 0x40)) // hey it's perfect!
check_if_perfect_skip:
it := 0x60
check_if_reverse_start:
jumpi(check_if_reverse_start, lt(it, end))
it := size
end := msize
for {} gt(it, 0x20) {} {
it := sub(it, 0x20)
}
mstore(sub(end, 0x40), 0x20)
return(sub(end, 0x40), add(size, 0x60)) // hey it's reversed!
check_if_reverse_skip:

hoareQuickSort(0x40, size)

function hoareQuickSort(p_low, p_high) {
if lt(p_low, p_high) {
let pi := hoarePartition(p_low, p_high)
hoareQuickSort(p_low, pi)
}
}
function hoarePartition(p_low, p_high) -> j {
let factor := add(p_low, mul(mulmod(gas, 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47, div(sub(p_high, p_low), 0x20)), 0x20))
let i := sub(p_low, 0x20)
let t
jump(partition_start)
partition_swap:
mstore(i, t)
partition_start:
increase_i: