#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  printf("How large is the array you want to sort?\n");
  int n;
  scanf("%d", &n);
  int i;
  int a[1000];
  printf("Input %d values for your array: ", n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int j;
  for (j = 1; j < n; j++) {
    int key = a[j];
    i = j - 1;
    while (i >= 0 && a[i] > key) {
      a[i + 1] = a[i];
      i--;
    }
    a[i + 1] = key;
  }
  printf("The sorted array is:\n");
  for (i = 0; i < n; i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a0 <main+0x80>
movslq -0xc(%rbp),%rax
lea    -0xfb0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe9d(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1168 <main+0x48>
movl   $0x1,-0xfb4(%rbp)
mov    -0xfb4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1269 <main+0x149>
movslq -0xfb4(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
mov    %eax,-0xfb8(%rbp)
mov    -0xfb4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xfb9(%rbp)
jl     1205 <main+0xe5>
movslq -0xc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
cmp    -0xfb8(%rbp),%eax
setg   %al
mov    %al,-0xfb9(%rbp)
mov    -0xfb9(%rbp),%al
test   $0x1,%al
jne    1218 <main+0xf8>
jmp    1240 <main+0x120>
movslq -0xc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%ecx
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11d9 <main+0xb9>
mov    -0xfb8(%rbp),%ecx
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    11aa <main+0x8a>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b1 <main+0x191>
movslq -0xc(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    127e <main+0x15e>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xfb0,%rsp
lea    0xed5(%rip),%rdi
call   1040 <puts@plt>
lea    0xea1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1213 <main+0xd3>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe6c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11a0 <main+0x60>
mov    %eax,%eax
cmp    $0x2,%eax
jl     1213 <main+0xd3>
mov    $0x1,%ecx
jmp    11e0 <main+0xa0>
nopl   0x0(%rax,%rax,1)
movslq %esi,%rsi
mov    %edx,0x10(%rsp,%rsi,4)
add    $0x1,%rcx
cmp    %rax,%rcx
je     1213 <main+0xd3>
mov    0x10(%rsp,%rcx,4),%edx
mov    %rcx,%rsi
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rsi),%rdi
mov    %edi,%ebx
mov    0x10(%rsp,%rbx,4),%ebx
cmp    %edx,%ebx
jle    11d0 <main+0x90>
mov    %ebx,0x10(%rsp,%rsi,4)
lea    0x1(%rdi),%rbx
mov    %rdi,%rsi
cmp    $0x1,%rbx
jg     11f0 <main+0xb0>
xor    %esi,%esi
jmp    11d0 <main+0x90>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0x10c>
lea    0xdf7(%rip),%r14
xor    %ebx,%ebx
nop
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1230 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Input %d values for your array: \00"
@.str.4 = [4 x i8] c"%d \00"
@str = [41 x i8] c"How large is the array you want to sort?\00"
@str.6 = [21 x i8] c"The sorted array is:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = bitcast [1000 x i32]* %2 to i8*
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %15, label %44
11: ; preds = %15
%12 = icmp sgt i32 %20, 1
br i1 %12, label %13, label %44
13: ; preds = %11
%14 = zext i32 %20 to i64
br label %23
15: ; preds = %0, %15
%16 = phi i64 [ %19, %15 ], [ 0, %0 ]
%17 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %11
23: ; preds = %13, %37
%24 = phi i64 [ 1, %13 ], [ %42, %37 ]
%25 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
br label %27
27: ; preds = %23, %34
%28 = phi i64 [ %24, %23 ], [ %29, %34 ]
%29 = add nsw i64 %28, -1
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = icmp sgt i32 %32, %26
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %28
store i32 %32, i32* %35
%36 = icmp sgt i64 %28, 1
br i1 %36, label %27, label %37
37: ; preds = %34, %27
%38 = phi i64 [ 0, %34 ], [ %28, %27 ]
%39 = shl i64 %38, 32
%40 = ashr exact i64 %39, 32
%41 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %40
store i32 %26, i32* %41
%42 = add nuw nsw i64 %24, 1
%43 = icmp eq i64 %42, %14
br i1 %43, label %44, label %23
44: ; preds = %37, %0, %11
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
%46 = load i32, i32* %1
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %44, %48
%49 = phi i64 [ %53, %48 ], [ 0, %44 ]
%50 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = add nuw nsw i64 %49, 1
%54 = load i32, i32* %1
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %48, label %57
57: ; preds = %48, %44
%58 = call i32 @putchar(i32 10)
ret i32 0
}