#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 */

/* Variables and functions */
int /*<<< orphan*/ exchange(unsigned long *, unsigned long *);
void insertion_sort(unsigned long *numray, unsigned long n) {
  unsigned long c, d;
  for (c = 1; c < n; c++)
    for (d = c; d > 0 && numray[d] < numray[d - 1]; d--)
      exchange(&numray[d], &numray[d - 1]);
}


x86 assembly (clang, -O0):
<insertion_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ce <insertion_sort+0xbe>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
jbe    1170 <insertion_sort+0x60>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
cmp    (%rcx,%rdx,8),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1180 <insertion_sort+0x70>
jmp    11b8 <insertion_sort+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <exchange@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    113e <insertion_sort+0x2e>
jmp    11bd <insertion_sort+0xad>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <insertion_sort+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertion_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%rsi
jb     117f <insertion_sort+0x6f>
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x8,%r15
mov    $0x1,%r12d
mov    $0xffffffffffffffff,%r13
jmp    1151 <insertion_sort+0x41>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x8,%r15
add    $0xffffffffffffffff,%r13
cmp    %r14,%r12
je     117f <insertion_sort+0x6f>
mov    %r13,%rbp
mov    %r15,%rdi
nopw   0x0(%rax,%rax,1)
mov    (%rdi),%rax
cmp    -0x8(%rdi),%rax
jae    1140 <insertion_sort+0x30>
lea    -0x8(%rdi),%rbx
mov    %rbx,%rsi
call   1030 <exchange@plt>
mov    %rbx,%rdi
inc    %rbp
jne    1160 <insertion_sort+0x50>
jmp    1140 <insertion_sort+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @insertion_sort(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
store i64 1, i64* %5
br label %7
7: ; preds = %42, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %45
11: ; preds = %7
%12 = load i64, i64* %5
store i64 %12, i64* %6
br label %13
13: ; preds = %38, %11
%14 = load i64, i64* %6
%15 = icmp ugt i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i64*, i64** %3
%18 = load i64, i64* %6
%19 = getelementptr inbounds i64, i64* %17, i64 %18
%20 = load i64, i64* %19
%21 = load i64*, i64** %3
%22 = load i64, i64* %6
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i64, i64* %21, i64 %23
%25 = load i64, i64* %24
%26 = icmp ult i64 %20, %25
br label %27
27: ; preds = %16, %13
%28 = phi i1 [ false, %13 ], [ %26, %16 ]
br i1 %28, label %29, label %41
29: ; preds = %27
%30 = load i64*, i64** %3
%31 = load i64, i64* %6
%32 = getelementptr inbounds i64, i64* %30, i64 %31
%33 = load i64*, i64** %3
%34 = load i64, i64* %6
%35 = sub i64 %34, 1
%36 = getelementptr inbounds i64, i64* %33, i64 %35
%37 = call i32 @exchange(i64* %32, i64* %36)
br label %38
38: ; preds = %29
%39 = load i64, i64* %6
%40 = add i64 %39, -1
store i64 %40, i64* %6
br label %13
41: ; preds = %27
br label %42
42: ; preds = %41
%43 = load i64, i64* %5
%44 = add i64 %43, 1
store i64 %44, i64* %5
br label %7
45: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @insertion_sort(i64* %0, i64 %1) {
%3 = icmp ugt i64 %1, 1
br i1 %3, label %4, label %20
4: ; preds = %2, %17
%5 = phi i64 [ %18, %17 ], [ 1, %2 ]
br label %6
6: ; preds = %4, %14
%7 = phi i64 [ %10, %14 ], [ %5, %4 ]
%8 = getelementptr inbounds i64, i64* %0, i64 %7
%9 = load i64, i64* %8
%10 = add i64 %7, -1
%11 = getelementptr inbounds i64, i64* %0, i64 %10
%12 = load i64, i64* %11
%13 = icmp ult i64 %9, %12
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = tail call i32 @exchange(i64* %8, i64* %11)
%16 = icmp eq i64 %10, 0
br i1 %16, label %17, label %6
17: ; preds = %14, %6
%18 = add nuw i64 %5, 1
%19 = icmp eq i64 %18, %1
br i1 %19, label %20, label %4
20: ; preds = %17, %2
ret void
}