#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*/ swap(int *, int *);
void insertionSort(int *arr, int n) {
  int i, j;
  for (i = 0; i < n; ++i) {
    j = i;
    while ((j > 0) && (arr[j - 1] > arr[j])) {
      swap(&arr[j - 1], &arr[j]);
      j--;
    }
  }
}


x86 assembly (clang, -O0):
<insertionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c0 <insertionSort+0xb0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jle    1168 <insertionSort+0x58>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1178 <insertionSort+0x68>
jmp    11ad <insertionSort+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <insertionSort+0x28>
jmp    11b2 <insertionSort+0xa2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <insertionSort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertionSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1174 <insertionSort+0x64>
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %r12d,%r12d
mov    $0x1,%r15d
jmp    113d <insertionSort+0x2d>
nopl   (%rax)
add    $0x1,%r12d
add    $0x1,%r15d
cmp    %r14d,%r12d
je     1174 <insertionSort+0x64>
test   %r12d,%r12d
je     1130 <insertionSort+0x20>
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%eax
lea    -0x1(%rax),%ebp
add    $0xfffffffe,%eax
mov    (%rbx,%rax,4),%ecx
cmp    (%rbx,%rbp,4),%ecx
jle    1130 <insertionSort+0x20>
lea    (%rbx,%rax,4),%rdi
lea    (%rbx,%rbp,4),%rsi
call   1030 <swap@plt>
cmp    $0x1,%ebp
jg     1150 <insertionSort+0x40>
jmp    1130 <insertionSort+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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