#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 *inArr, int numItems) {
  int i = 0, j = 0, key = 0, k = 0;
  if ((inArr == NULL) || (numItems <= 0)) {
    printf("Input Error! Can't continue further\n");
    return;
  }
  for (i = 1; i < numItems; i++) {
    key = inArr[i];
    j = i - 1;
    while ((j >= 0) && (inArr[j] > key)) {
      inArr[j + 1] = inArr[j];
      j--;
    }
    inArr[j + 1] = key;
  }
  printf("\nSorted Array:");
  for (j = 0; j < numItems; j++) {
    printf("\t%d", inArr[j]);
  }
  printf("\n");
}


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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1150 <insertionSort+0x40>
cmpl   $0x0,-0xc(%rbp)
jg     1163 <insertionSort+0x53>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1260 <insertionSort+0x150>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120a <insertionSort+0xfa>
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,-0x1d(%rbp)
jl     11b0 <insertionSort+0xa0>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x18(%rbp),%eax
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11c0 <insertionSort+0xb0>
jmp    11e9 <insertionSort+0xd9>
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
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <insertionSort+0x7d>
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    116a <insertionSort+0x5a>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1252 <insertionSort+0x142>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121f <insertionSort+0x10f>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertionSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a1 <insertionSort+0x71>
mov    %esi,%r14d
test   %esi,%esi
jle    11a1 <insertionSort+0x71>
mov    %rdi,%rbx
mov    %r14d,%r15d
cmp    $0x1,%r14d
jbe    11b7 <insertionSort+0x87>
mov    $0x1,%eax
jmp    116f <insertionSort+0x3f>
cs nopw 0x0(%rax,%rax,1)
movslq %edx,%rdx
mov    %ecx,(%rbx,%rdx,4)
add    $0x1,%rax
cmp    %r15,%rax
je     11c7 <insertionSort+0x97>
mov    (%rbx,%rax,4),%ecx
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%rdx),%rsi
mov    %esi,%edi
mov    (%rbx,%rdi,4),%edi
cmp    %ecx,%edi
jle    1160 <insertionSort+0x30>
mov    %edi,(%rbx,%rdx,4)
lea    0x1(%rsi),%rdi
mov    %rsi,%rdx
cmp    $0x1,%rdi
jg     1180 <insertionSort+0x50>
xor    %edx,%edx
jmp    1160 <insertionSort+0x30>
lea    0xe6b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11da <insertionSort+0xaa>
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jle    1206 <insertionSort+0xd6>
lea    0xe2e(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11f0 <insertionSort+0xc0>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Input Error! Can't continue further\0A\00"
@.str.1 = [15 x i8] c"\0ASorted Array:\00"
@.str.2 = [4 x i8] c"\09%d\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @insertionSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %83
16: ; preds = %11
store i32 1, i32* %5
br label %17
17: ; preds = %62, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %65
21: ; preds = %17
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
store i32 %26, i32* %7
%27 = load i32, i32* %5
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %6
br label %29
29: ; preds = %42, %21
%30 = load i32, i32* %6
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i32*, i32** %3
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %7
%39 = icmp sgt i32 %37, %38
br label %40
40: ; preds = %32, %29
%41 = phi i1 [ false, %29 ], [ %39, %32 ]
br i1 %41, label %42, label %55
42: ; preds = %40
%43 = load i32*, i32** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = load i32*, i32** %3
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %48, i64 %51
store i32 %47, i32* %52
%53 = load i32, i32* %6
%54 = add nsw i32 %53, -1
store i32 %54, i32* %6
br label %29
55: ; preds = %40
%56 = load i32, i32* %7
%57 = load i32*, i32** %3
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %57, i64 %60
store i32 %56, i32* %61
br label %62
62: ; preds = %55
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %17
65: ; preds = %17
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %67
67: ; preds = %78, %65
%68 = load i32, i32* %6
%69 = load i32, i32* %4
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %81
71: ; preds = %67
%72 = load i32*, i32** %3
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %71
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %67
81: ; preds = %67
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %83
83: ; preds = %81, %14
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"\0ASorted Array:\00"
@.str.2 = [4 x i8] c"\09%d\00"
@str = [36 x i8] c"Input Error! Can't continue further\00"
define void @insertionSort(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
%4 = icmp slt i32 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = icmp ugt i32 %1, 1
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %38
10: ; preds = %6
%11 = zext i32 %1 to i64
br label %14
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %49
14: ; preds = %10, %28
%15 = phi i64 [ 1, %10 ], [ %33, %28 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
br label %18
18: ; preds = %14, %25
%19 = phi i64 [ %15, %14 ], [ %20, %25 ]
%20 = add nsw i64 %19, -1
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = icmp sgt i32 %23, %17
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = getelementptr inbounds i32, i32* %0, i64 %19
store i32 %23, i32* %26
%27 = icmp sgt i64 %19, 1
br i1 %27, label %18, label %28
28: ; preds = %25, %18
%29 = phi i64 [ 0, %25 ], [ %19, %18 ]
%30 = shl i64 %29, 32
%31 = ashr exact i64 %30, 32
%32 = getelementptr inbounds i32, i32* %0, i64 %31
store i32 %17, i32* %32
%33 = add nuw nsw i64 %15, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %14
35: ; preds = %28
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp sgt i32 %1, 0
br i1 %37, label %38, label %47
38: ; preds = %8, %35
%39 = zext i32 %1 to i64
br label %40
40: ; preds = %38, %40
%41 = phi i64 [ 0, %38 ], [ %45, %40 ]
%42 = getelementptr inbounds i32, i32* %0, i64 %41
%43 = load i32, i32* %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = add nuw nsw i64 %41, 1
%46 = icmp eq i64 %45, %39
br i1 %46, label %47, label %40
47: ; preds = %40, %35
%48 = tail call i32 @putchar(i32 10)
br label %49
49: ; preds = %47, %12
ret void
}