#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 main(void) {
  int arr[10] = {26, 34543, 17, 31, 13, 543, 456, 1, 0, 2};
  int idx, cmp, shift, tmp;
  printf("Insertion Sort\n");
  printf("Before Sorting: \n");
  for (idx = 0; idx < 10; idx++) {
    printf("%d\t", arr[idx]);
  }
  printf("\n");
  for (cmp = 1; cmp < 10; cmp++) {
    for (idx = 0; idx < cmp; idx++) {
      if (arr[idx] > arr[cmp]) {
        tmp = arr[idx];
        arr[idx] = arr[cmp];
        for (shift = cmp; shift > idx; shift--)
          arr[shift] = arr[shift - 1];
        arr[shift + 1] = tmp;
      }
    }
  }
  printf("After Sorting: \n");
  for (idx = 0; idx < 10; idx++) {
    printf("%d\t", arr[idx]);
  }
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1195 <main+0x75>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1167 <main+0x47>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x38(%rbp)
cmpl   $0xa,-0x38(%rbp)
jge    1261 <main+0x141>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    124e <main+0x12e>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
movslq -0x38(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jle    123b <main+0x11b>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x40(%rbp)
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    122c <main+0x10c>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x3c(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fe <main+0xde>
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    1240 <main+0x120>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bb <main+0x9b>
jmp    1253 <main+0x133>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11aa <main+0x8a>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    12a4 <main+0x184>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1276 <main+0x156>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0xee4(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xecd(%rip),%rdi
call   1040 <puts@plt>
lea    0xed0(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb1(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1a,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x86ef,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1f,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x21f,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1c8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%r10d
movabs $0x200000000,%r9
movabs $0xffffffff00000000,%rdx
ff ff ff
movabs $0x100000000,%r8
jmp    124d <main+0x11d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r10
add    %r8,%r9
cmp    $0xa,%r10
je     129f <main+0x16f>
xor    %edi,%edi
jmp    1269 <main+0x139>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rdi
cmp    %r10,%rdi
je     1240 <main+0x110>
mov    (%rsp,%rdi,4),%ebx
mov    (%rsp,%r10,4),%eax
cmp    %eax,%ebx
jle    1260 <main+0x130>
mov    %eax,(%rsp,%rdi,4)
mov    %r9,%rcx
mov    %r10,%rax
nopl   (%rax)
add    %rdx,%rcx
mov    -0x4(%rsp,%rax,4),%esi
mov    %esi,(%rsp,%rax,4)
lea    -0x1(%rax),%rsi
mov    %rsi,%rax
cmp    %rdi,%rsi
jg     1280 <main+0x150>
sar    $0x1e,%rcx
mov    %ebx,(%rsp,%rcx,1)
jmp    1260 <main+0x130>
lea    0xda6(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%esi
lea    0xd73(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.arr = [10 x i32] [i32 26, i32 34543, i32 17, i32 31, i32 13, i32 543, i32 456, i32 1, i32 0, i32 2]
@.str = [16 x i8] c"Insertion Sort\0A\00"
@.str.1 = [18 x i8] c"Before Sorting: \0A\00"
@.str.2 = [4 x i8] c"%d\09\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [17 x i8] c"After Sorting: \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [10 x i32]* %2 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %10
10: ; preds = %19, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %10
22: ; preds = %10
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %24
24: ; preds = %82, %22
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 10
br i1 %26, label %27, label %85
27: ; preds = %24
store i32 0, i32* %3
br label %28
28: ; preds = %78, %27
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %81
32: ; preds = %28
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = icmp sgt i32 %36, %40
br i1 %41, label %42, label %77
42: ; preds = %32
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %44
%46 = load i32, i32* %45
store i32 %46, i32* %6
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %52
store i32 %50, i32* %53
%54 = load i32, i32* %4
store i32 %54, i32* %5
br label %55
55: ; preds = %68, %42
%56 = load i32, i32* %5
%57 = load i32, i32* %3
%58 = icmp sgt i32 %56, %57
br i1 %58, label %59, label %71
59: ; preds = %55
%60 = load i32, i32* %5
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %66
store i32 %64, i32* %67
br label %68
68: ; preds = %59
%69 = load i32, i32* %5
%70 = add nsw i32 %69, -1
store i32 %70, i32* %5
br label %55
71: ; preds = %55
%72 = load i32, i32* %6
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %75
store i32 %72, i32* %76
br label %77
77: ; preds = %71, %32
br label %78
78: ; preds = %77
%79 = load i32, i32* %3
%80 = add nsw i32 %79, 1
store i32 %80, i32* %3
br label %28
81: ; preds = %28
br label %82
82: ; preds = %81
%83 = load i32, i32* %4
%84 = add nsw i32 %83, 1
store i32 %84, i32* %4
br label %24
85: ; preds = %24
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %87
87: ; preds = %96, %85
%88 = load i32, i32* %3
%89 = icmp slt i32 %88, 10
br i1 %89, label %90, label %99
90: ; preds = %87
%91 = load i32, i32* %3
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %92
%94 = load i32, i32* %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %94)
br label %96
96: ; preds = %90
%97 = load i32, i32* %3
%98 = add nsw i32 %97, 1
store i32 %98, i32* %3
br label %87
99: ; preds = %87
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [10 x i32] [i32 26, i32 34543, i32 17, i32 31, i32 13, i32 543, i32 456, i32 1, i32 0, i32 2]
@.str.2 = [4 x i8] c"%d\09\00"
@str = [15 x i8] c"Insertion Sort\00"
@str.5 = [17 x i8] c"Before Sorting: \00"
@str.6 = [16 x i8] c"After Sorting: \00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 26)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 34543)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 17)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 31)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 13)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 543)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 456)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %0, %41
%17 = phi i64 [ 1, %0 ], [ %42, %41 ]
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %17
br label %19
19: ; preds = %16, %38
%20 = phi i64 [ 0, %16 ], [ %39, %38 ]
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %18
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %19
store i32 %23, i32* %21
br label %26
26: ; preds = %25, %26
%27 = phi i64 [ %17, %25 ], [ %28, %26 ]
%28 = add nsw i64 %27, -1
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %27
store i32 %30, i32* %31
%32 = icmp sgt i64 %28, %20
br i1 %32, label %26, label %33
33: ; preds = %26
%34 = shl i64 %28, 32
%35 = add i64 %34, 4294967296
%36 = ashr exact i64 %35, 32
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %36
store i32 %22, i32* %37
br label %38
38: ; preds = %19, %33
%39 = add nuw nsw i64 %20, 1
%40 = icmp eq i64 %39, %17
br i1 %40, label %41, label %19
41: ; preds = %38
%42 = add nuw nsw i64 %17, 1
%43 = icmp eq i64 %42, 10
br i1 %43, label %44, label %16
44: ; preds = %41
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%51 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%52 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%53 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
%56 = load i32, i32* %54
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %53
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %52
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %51
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %50
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %49
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %48
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %47
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %46
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %45
%75 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %74)
%76 = tail call i32 @putchar(i32 10)
ret i32 0
}