#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ int64_t;
typedef int /*<<< orphan*/ dst;

/* Variables and functions */
size_t sorter_binary_insertion_find(scalar_t__ *, scalar_t__, size_t);
void sorter_binary_insertion_sort_start(int64_t *dst, const size_t start,
                                        const size_t size) {
  size_t i;
  for (i = start; i < size; i++) {
    size_t j;
    int64_t x;
    size_t location;
    if (((dst[i - 1]) - (dst[i])) <= 0) {
      continue;
    }
    x = dst[i];
    location = sorter_binary_insertion_find(dst, x, i);
    for (j = i - 1; j >= location; j--) {
      dst[j + 1] = dst[j];
      if (j == 0) {
        break;
      }
    }
    dst[location] = x;
  }
}


x86 assembly (clang, -O0):
<sorter_binary_insertion_sort_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1204 <sorter_binary_insertion_sort_start+0xf4>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    (%rcx,%rdx,8),%rax
cmp    $0x0,%rax
jg     1165 <sorter_binary_insertion_sort_start+0x55>
jmp    11f3 <sorter_binary_insertion_sort_start+0xe3>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <sorter_binary_insertion_find@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jb     11e3 <sorter_binary_insertion_sort_start+0xd3>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,0x8(%rax,%rcx,8)
cmpq   $0x0,-0x28(%rbp)
jne    11cd <sorter_binary_insertion_sort_start+0xbd>
jmp    11e3 <sorter_binary_insertion_sort_start+0xd3>
jmp    11d2 <sorter_binary_insertion_sort_start+0xc2>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1196 <sorter_binary_insertion_sort_start+0x86>
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <sorter_binary_insertion_sort_start+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_binary_insertion_sort_start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rdx,%rsi
jae    118e <sorter_binary_insertion_sort_start+0x7e>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    -0x2(%rsi),%r13
jmp    1141 <sorter_binary_insertion_sort_start+0x31>
nop
mov    %r12,(%rbx,%rax,8)
add    $0x1,%r15
add    $0x1,%r13
cmp    %r14,%r15
je     118e <sorter_binary_insertion_sort_start+0x7e>
mov    (%rbx,%r15,8),%r12
cmp    %r12,-0x8(%rbx,%r15,8)
jle    1134 <sorter_binary_insertion_sort_start+0x24>
lea    -0x1(%r15),%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <sorter_binary_insertion_find@plt>
cmp    %rax,%rbp
jb     1130 <sorter_binary_insertion_sort_start+0x20>
mov    %r13,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rbx,%rcx,8),%rdx
mov    %rdx,0x10(%rbx,%rcx,8)
cmp    $0xffffffffffffffff,%rcx
je     1130 <sorter_binary_insertion_sort_start+0x20>
lea    -0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jae    1170 <sorter_binary_insertion_sort_start+0x60>
jmp    1130 <sorter_binary_insertion_sort_start+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sorter_binary_insertion_sort_start(i64* %0, i64 %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64* %0, i64** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%11 = load i64, i64* %5
store i64 %11, i64* %7
br label %12
12: ; preds = %65, %3
%13 = load i64, i64* %7
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %68
16: ; preds = %12
%17 = load i64*, i64** %4
%18 = load i64, i64* %7
%19 = sub i64 %18, 1
%20 = getelementptr inbounds i64, i64* %17, i64 %19
%21 = load i64, i64* %20
%22 = load i64*, i64** %4
%23 = load i64, i64* %7
%24 = getelementptr inbounds i64, i64* %22, i64 %23
%25 = load i64, i64* %24
%26 = sub nsw i64 %21, %25
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %16
br label %65
29: ; preds = %16
%30 = load i64*, i64** %4
%31 = load i64, i64* %7
%32 = getelementptr inbounds i64, i64* %30, i64 %31
%33 = load i64, i64* %32
store i64 %33, i64* %9
%34 = load i64*, i64** %4
%35 = load i64, i64* %9
%36 = load i64, i64* %7
%37 = call i64 @sorter_binary_insertion_find(i64* %34, i64 %35, i64 %36)
store i64 %37, i64* %10
%38 = load i64, i64* %7
%39 = sub i64 %38, 1
store i64 %39, i64* %8
br label %40
40: ; preds = %57, %29
%41 = load i64, i64* %8
%42 = load i64, i64* %10
%43 = icmp uge i64 %41, %42
br i1 %43, label %44, label %60
44: ; preds = %40
%45 = load i64*, i64** %4
%46 = load i64, i64* %8
%47 = getelementptr inbounds i64, i64* %45, i64 %46
%48 = load i64, i64* %47
%49 = load i64*, i64** %4
%50 = load i64, i64* %8
%51 = add i64 %50, 1
%52 = getelementptr inbounds i64, i64* %49, i64 %51
store i64 %48, i64* %52
%53 = load i64, i64* %8
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %44
br label %60
56: ; preds = %44
br label %57
57: ; preds = %56
%58 = load i64, i64* %8
%59 = add i64 %58, -1
store i64 %59, i64* %8
br label %40
60: ; preds = %55, %40
%61 = load i64, i64* %9
%62 = load i64*, i64** %4
%63 = load i64, i64* %10
%64 = getelementptr inbounds i64, i64* %62, i64 %63
store i64 %61, i64* %64
br label %65
65: ; preds = %60, %28
%66 = load i64, i64* %7
%67 = add i64 %66, 1
store i64 %67, i64* %7
br label %12
68: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @sorter_binary_insertion_sort_start(i64* %0, i64 %1, i64 %2) {
%4 = icmp ult i64 %1, %2
br i1 %4, label %5, label %31
5: ; preds = %3, %28
%6 = phi i64 [ %29, %28 ], [ %1, %3 ]
%7 = add i64 %6, -1
%8 = getelementptr inbounds i64, i64* %0, i64 %7
%9 = load i64, i64* %8
%10 = getelementptr inbounds i64, i64* %0, i64 %6
%11 = load i64, i64* %10
%12 = icmp sgt i64 %9, %11
br i1 %12, label %13, label %28
13: ; preds = %5
%14 = tail call i64 @sorter_binary_insertion_find(i64* %0, i64 %11, i64 %6)
%15 = icmp ult i64 %7, %14
br i1 %15, label %26, label %16
16: ; preds = %13, %16
%17 = phi i64 [ %23, %16 ], [ %7, %13 ]
%18 = getelementptr inbounds i64, i64* %0, i64 %17
%19 = load i64, i64* %18
%20 = add i64 %17, 1
%21 = getelementptr inbounds i64, i64* %0, i64 %20
store i64 %19, i64* %21
%22 = icmp eq i64 %17, 0
%23 = add i64 %17, -1
%24 = icmp ult i64 %23, %14
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %16
26: ; preds = %16, %13
%27 = getelementptr inbounds i64, i64* %0, i64 %14
store i64 %11, i64* %27
br label %28
28: ; preds = %5, %26
%29 = add nuw i64 %6, 1
%30 = icmp eq i64 %29, %2
br i1 %30, label %31, label %5
31: ; preds = %28, %3
ret void
}