#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, int);
void insertionSort(int *arr, int size) {
  for (int i = 0; i < size; i++)
    for (int k = i; k > 0; k--)
      if (arr[k] < arr[k - 1])
        swap(arr, k, k - 1);
}


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    119b <insertionSort+0x8b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1188 <insertionSort+0x78>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1175 <insertionSort+0x65>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <swap@plt>
jmp    117a <insertionSort+0x6a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <insertionSort+0x28>
jmp    118d <insertionSort+0x7d>
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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
jle    117d <insertionSort+0x6d>
mov    %rdi,%r14
mov    %esi,%r15d
mov    $0xffffffffffffffff,%r12
xor    %r13d,%r13d
jmp    113d <insertionSort+0x2d>
nop
add    $0x1,%r13
add    $0x1,%r12
cmp    %r15,%r13
je     117d <insertionSort+0x6d>
mov    %r12,%rbx
test   %r13d,%r13d
jne    1161 <insertionSort+0x51>
jmp    1130 <insertionSort+0x20>
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%rax
add    $0x1,%rbx
cmp    $0x1,%rbx
mov    %rax,%rbx
jle    1130 <insertionSort+0x20>
mov    0x4(%r14,%rbx,4),%eax
mov    %ebx,%ecx
cmp    (%r14,%rcx,4),%eax
jge    1150 <insertionSort+0x40>
lea    0x1(%rbx),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <swap@plt>
jmp    1150 <insertionSort+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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 = %40, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %43
11: ; preds = %7
%12 = load i32, i32* %5
store i32 %12, i32* %6
br label %13
13: ; preds = %36, %11
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %13
%17 = load i32*, i32** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %3
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %22, i64 %25
%27 = load i32, i32* %26
%28 = icmp slt i32 %21, %27
br i1 %28, label %29, label %35
29: ; preds = %16
%30 = load i32*, i32** %3
%31 = load i32, i32* %6
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 1
%34 = call i32 @swap(i32* %30, i32 %31, i32 %33)
br label %35
35: ; preds = %29, %16
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, -1
store i32 %38, i32* %6
br label %13
39: ; preds = %13
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %7
43: ; 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 %10
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %11
%7 = phi i64 [ 0, %4 ], [ %12, %11 ]
%8 = trunc i64 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %11, label %14
10: ; preds = %11, %2
ret void
11: ; preds = %27, %6
%12 = add nuw nsw i64 %7, 1
%13 = icmp eq i64 %12, %5
br i1 %13, label %10, label %6
14: ; preds = %6, %27
%15 = phi i64 [ %18, %27 ], [ %7, %6 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = add nsw i64 %15, -1
%19 = and i64 %18, 4294967295
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = load i32, i32* %20
%22 = icmp slt i32 %17, %21
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = trunc i64 %18 to i32
%25 = trunc i64 %15 to i32
%26 = tail call i32 @swap(i32* %0, i32 %25, i32 %24)
br label %27
27: ; preds = %14, %23
%28 = icmp sgt i64 %15, 1
br i1 %28, label %14, label %11
}