#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*/ assert(int);
int *insertion_sort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("insertion sort\n");
  int sorted[6] = {1, 2, 3, 4, 5, 6};
  int sortable[6] = {5, 2, 4, 6, 1, 3};
  int *result = insertion_sort(sortable, 6);
  for (int i = 0; i < 6; i++) {
    printf("expected: %d actual: %d\n", sorted[i], result[i]);
    assert(sorted[i] == result[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0xedc(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xedb(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xed8(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x6,%esi
call   1050 <insertion_sort@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x6,-0x4c(%rbp)
jge    1201 <main+0xd1>
movslq -0x4c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x4c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    -0x48(%rbp),%rcx
movslq -0x4c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11a8 <main+0x78>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xee3(%rip),%rdi
call   1030 <puts@plt>
mov    0xeb6(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x6,%esi
call   1060 <insertion_sort@plt>
mov    %rax,%rbx
mov    (%rax),%edx
lea    0xe95(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x1,(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x4(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x2,0x4(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x3,0x8(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0xc(%rbx),%edx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x4,0xc(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x10(%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x5,0x10(%rbx)
sete   %dil
call   1050 <assert@plt>
mov    0x14(%rbx),%edx
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x6,0x14(%rbx)
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"insertion sort\0A\00"
@__const.main.sorted = [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6]
@__const.main.sortable = [6 x i32] [i32 5, i32 2, i32 4, i32 6, i32 1, i32 3]
@.str.1 = [25 x i8] c"expected: %d actual: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i32]
%3 = alloca [6 x i32]
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [6 x i32]* %2 to i8*
%8 = bitcast [6 x i32]* %3 to i8*
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%10 = call i32* @insertion_sort(i32* %9, i32 6)
store i32* %10, i32** %4
store i32 0, i32* %5
br label %11
11: ; preds = %37, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 6
br i1 %13, label %14, label %40
14: ; preds = %11
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %23)
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = icmp eq i32 %28, %33
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
br label %37
37: ; preds = %14
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %11
40: ; preds = %11
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@__const.main.sortable = [6 x i32] [i32 5, i32 2, i32 4, i32 6, i32 1, i32 3]
@.str.1 = [25 x i8] c"expected: %d actual: %d\0A\00"
@str = [15 x i8] c"insertion sort\00"
define i32 @main() {
%1 = alloca [6 x i32]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%3 = bitcast [6 x i32]* %1 to i8*
%4 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%5 = call i32* @insertion_sort(i32* %4, i32 6)
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %6)
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds i32, i32* %5, i64 1
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %13)
%15 = load i32, i32* %12
%16 = icmp eq i32 %15, 2
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds i32, i32* %5, i64 2
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %20)
%22 = load i32, i32* %19
%23 = icmp eq i32 %22, 3
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds i32, i32* %5, i64 3
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %27)
%29 = load i32, i32* %26
%30 = icmp eq i32 %29, 4
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = getelementptr inbounds i32, i32* %5, i64 4
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %34)
%36 = load i32, i32* %33
%37 = icmp eq i32 %36, 5
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = getelementptr inbounds i32, i32* %5, i64 5
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 %41)
%43 = load i32, i32* %40
%44 = icmp eq i32 %43, 6
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
ret i32 0
}