#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 *);
void insertionSort(int *array, int size) {
  if (size < 2) {
    printf("The array is less than 2, nothing to sort\n");
    return;
  }
  if (array == NULL) {
    printf("The array is empty\n");
    return;
  }
  int j = 0;
  int i = 0;
  int key = 0;
  for (j = 1; j < size; j++) {
    key = array[j];
    i = j - 1;
    while ((i >= 0) && (array[i] > key)) {
      array[i + 1] = array[i];
      i = i - 1;
    }
    array[i + 1] = key;
  }
}


x86 assembly (clang, -O0):
<insertionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    113a <insertionSort+0x2a>
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
jmp    1212 <insertionSort+0x102>
cmpq   $0x0,-0x8(%rbp)
jne    1156 <insertionSort+0x46>
lea    0xedf(%rip),%rdi
call   1030 <printf@plt>
jmp    1212 <insertionSort+0x102>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1212 <insertionSort+0x102>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jl     11b8 <insertionSort+0xa8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x18(%rbp),%eax
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11c8 <insertionSort+0xb8>
jmp    11f1 <insertionSort+0xe1>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1195 <insertionSort+0x85>
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <insertionSort+0x62>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertionSort>:
cmp    $0x2,%esi
jge    1121 <insertionSort+0x11>
lea    0xef7(%rip),%rdi
jmp    1030 <puts@plt>
test   %rdi,%rdi
je     1182 <insertionSort+0x72>
mov    %esi,%r8d
mov    $0x1,%r9d
jmp    114f <insertionSort+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %ecx,%rax
mov    %edx,(%rdi,%rax,4)
add    $0x1,%r9
cmp    %r8,%r9
je     1181 <insertionSort+0x71>
mov    (%rdi,%r9,4),%edx
mov    %r9,%rcx
cs nopw 0x0(%rax,%rax,1)
lea    -0x1(%rcx),%rsi
mov    %esi,%eax
mov    (%rdi,%rax,4),%eax
cmp    %edx,%eax
jle    1140 <insertionSort+0x30>
mov    %eax,(%rdi,%rcx,4)
lea    0x1(%rsi),%rax
mov    %rsi,%rcx
cmp    $0x1,%rax
jg     1160 <insertionSort+0x50>
xor    %ecx,%ecx
jmp    1140 <insertionSort+0x30>
ret
lea    0xe77(%rip),%rdi
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"The array is less than 2, nothing to sort\0A\00"
@.str.1 = [20 x i8] c"The array is empty\0A\00"
define void @insertionSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %66
12: ; preds = %2
%13 = load i32*, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %66
17: ; preds = %12
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %5
br label %18
18: ; preds = %63, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %66
22: ; preds = %18
%23 = load i32*, i32** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %7
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %6
br label %30
30: ; preds = %43, %22
%31 = load i32, i32* %6
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32*, i32** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %7
%40 = icmp sgt i32 %38, %39
br label %41
41: ; preds = %33, %30
%42 = phi i1 [ false, %30 ], [ %40, %33 ]
br i1 %42, label %43, label %56
43: ; preds = %41
%44 = load i32*, i32** %3
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = load i32*, i32** %3
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
store i32 %48, i32* %53
%54 = load i32, i32* %6
%55 = sub nsw i32 %54, 1
store i32 %55, i32* %6
br label %30
56: ; preds = %41
%57 = load i32, i32* %7
%58 = load i32*, i32** %3
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %58, i64 %61
store i32 %57, i32* %62
br label %63
63: ; preds = %56
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %18
66: ; preds = %10, %15, %18
ret void
}

LLVM IR (-O2):
@str = [19 x i8] c"The array is empty\00"
@str.2 = [42 x i8] c"The array is less than 2, nothing to sort\00"
define void @insertionSort(i32* %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = icmp eq i32* %0, null
br i1 %5, label %29, label %6
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %22
%9 = phi i64 [ 1, %6 ], [ %27, %22 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
br label %12
12: ; preds = %8, %19
%13 = phi i64 [ %9, %8 ], [ %14, %19 ]
%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 = icmp sgt i32 %17, %11
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %17, i32* %20
%21 = icmp sgt i64 %13, 1
br i1 %21, label %12, label %22
22: ; preds = %19, %12
%23 = phi i64 [ 0, %19 ], [ %13, %12 ]
%24 = shl i64 %23, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds i32, i32* %0, i64 %25
store i32 %11, i32* %26
%27 = add nuw nsw i64 %9, 1
%28 = icmp eq i64 %27, %7
br i1 %28, label %32, label %8
29: ; preds = %4, %2
%30 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %4 ]
%31 = tail call i32 @puts(i8* dereferenceable(1) %30)
br label %32
32: ; preds = %22, %29
ret void
}