#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*/ printf(char *);
int /*<<< orphan*/ swap(int *, int *);
int insert_sort(int *array, int left, int right) {
  printf("this is insert_sort\r\n");
  int i, j, length = right - left + 1;
  for (i = 1; i < length; i++) {
    for (j = i; j > 0; j--) {
      if (array[j - 1] > array[j])
        swap(&array[j], &array[j - 1]);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<insert_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11db <insert_sort+0xbb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11c8 <insert_sort+0xa8>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11b5 <insert_sort+0x95>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <swap@plt>
jmp    11ba <insert_sort+0x9a>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <insert_sort+0x43>
jmp    11cd <insert_sort+0xad>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <insert_sort+0x31>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
sub    %ebx,%ebp
mov    %rbp,(%rsp)
jle    11b7 <insert_sort+0x97>
mov    (%rsp),%rax
add    $0x1,%eax
mov    %rax,(%rsp)
lea    0x4(%r15),%r12
mov    $0x1,%r13d
mov    $0x2,%r14d
jmp    1182 <insert_sort+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13
add    $0x1,%r14
add    $0x4,%r12
cmp    (%rsp),%r13
je     11b7 <insert_sort+0x97>
mov    %r12,%rbx
mov    %r14,%rbp
jmp    119e <insert_sort+0x7e>
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbp
add    $0xfffffffffffffffc,%rbx
cmp    $0x1,%rbp
jle    1170 <insert_sort+0x50>
lea    -0x2(%rbp),%eax
mov    (%r15,%rax,4),%ecx
cmp    (%rbx),%ecx
jle    1190 <insert_sort+0x70>
lea    (%r15,%rax,4),%rsi
mov    %rbx,%rdi
call   1040 <swap@plt>
jmp    1190 <insert_sort+0x70>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"this is insert_sort\0D\0A\00"
define i32 @insert_sort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %9
store i32 1, i32* %7
br label %15
15: ; preds = %53, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %9
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %56
19: ; preds = %15
%20 = load i32, i32* %7
store i32 %20, i32* %8
br label %21
21: ; preds = %49, %19
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %52
24: ; preds = %21
%25 = load i32*, i32** %4
%26 = load i32, i32* %8
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
%30 = load i32, i32* %29
%31 = load i32*, i32** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = icmp sgt i32 %30, %35
br i1 %36, label %37, label %48
37: ; preds = %24
%38 = load i32*, i32** %4
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32*, i32** %4
%43 = load i32, i32* %8
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %42, i64 %45
%47 = call i32 @swap(i32* %41, i32* %46)
br label %48
48: ; preds = %37, %24
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, -1
store i32 %51, i32* %8
br label %21
52: ; preds = %21
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %15
56: ; preds = %15
ret i32 1
}

LLVM IR (-O2):
@str = [21 x i8] c"this is insert_sort\0D\00"
define i32 @insert_sort(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%5 = icmp sgt i32 %2, %1
br i1 %5, label %6, label %28
6: ; preds = %3
%7 = add i32 %2, 1
%8 = sub i32 %7, %1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %6, %25
%11 = phi i64 [ 1, %6 ], [ %26, %25 ]
br label %12
12: ; preds = %10, %23
%13 = phi i64 [ %11, %10 ], [ %14, %23 ]
%14 = add nsw i64 %13, -1
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = getelementptr inbounds i32, i32* %0, i64 %13
%19 = load i32, i32* %18
%20 = icmp sgt i32 %17, %19
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = tail call i32 @swap(i32* %18, i32* %16)
br label %23
23: ; preds = %12, %21
%24 = icmp sgt i64 %13, 1
br i1 %24, label %12, label %25
25: ; preds = %23
%26 = add nuw nsw i64 %11, 1
%27 = icmp eq i64 %26, %9
br i1 %27, label %28, label %10
28: ; preds = %25, %3
ret i32 1
}