#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 atoi(char const *);
int *calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ insertionsort(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char const *argv[]) {
  srand(time(NULL));
  int *nums = calloc(argc - 1, sizeof(int));
  for (int i = 0; i < argc - 1; i++) {
    nums[i] = atoi(argv[i + 1]);
  }
  puts("Your arguments:");
  for (int i = 0; i < argc - 1; i++)
    printf("%d ", nums[i]);
  puts("\n");
  insertionsort(nums, argc - 1);
  puts("Your arguments (sorted):");
  for (int i = 0; i < argc - 1; i++)
    printf("%d ", nums[i]);
  free(nums);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1203 <main+0x83>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <main+0x41>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    124c <main+0xcc>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdd7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1216 <main+0x96>
lea    0xdc1(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1060 <insertionsort@plt>
lea    0xda8(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12b0 <main+0x130>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd73(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127a <main+0xfa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r14d
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    -0x1(%r14),%r15d
mov    %r15d,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,%r13
cmp    $0x1,%r14d
jle    1228 <main+0xa8>
mov    %r15d,0x4(%rsp)
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rbx),%r15
mov    0x8(%r12,%rbx,8),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x0(%r13,%rbx,4)
mov    %r15,%rbx
cmp    %r15,%rbp
jne    11d0 <main+0x50>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%r14d
mov    0x4(%rsp),%r15d
jl     1288 <main+0x108>
xor    %ebx,%ebx
lea    0xe01(%rip),%r12
nop
mov    0x0(%r13,%rbx,4),%esi
mov    %r12,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1210 <main+0x90>
jmp    1234 <main+0xb4>
lea    0xdd1(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %r15d,%esi
call   1060 <insertionsort@plt>
lea    0xdc4(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%r14d
jl     12ab <main+0x12b>
mov    %r15d,%ebp
xor    %ebx,%ebx
lea    0xda7(%rip),%r14
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <main+0xf0>
jmp    12ab <main+0x12b>
lea    0xd85(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %r15d,%esi
call   1060 <insertionsort@plt>
lea    0xd70(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Your arguments:\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [25 x i8] c"Your arguments (sorted):\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = call i32* @calloc(i32 %13, i32 4)
store i32* %14, i32** %6
store i32 0, i32* %7
br label %15
15: ; preds = %32, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
%28 = load i32*, i32** %6
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %20
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %15
35: ; preds = %15
%36 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %37
37: ; preds = %49, %35
%38 = load i32, i32* %8
%39 = load i32, i32* %4
%40 = sub nsw i32 %39, 1
%41 = icmp slt i32 %38, %40
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = load i32*, i32** %6
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %37
52: ; preds = %37
%53 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32*, i32** %6
%55 = load i32, i32* %4
%56 = sub nsw i32 %55, 1
%57 = call i32 @insertionsort(i32* %54, i32 %56)
%58 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %9
br label %59
59: ; preds = %71, %52
%60 = load i32, i32* %9
%61 = load i32, i32* %4
%62 = sub nsw i32 %61, 1
%63 = icmp slt i32 %60, %62
br i1 %63, label %64, label %74
64: ; preds = %59
%65 = load i32*, i32** %6
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
%69 = load i32, i32* %68
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %64
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %59
74: ; preds = %59
%75 = load i32*, i32** %6
%76 = call i32 @free(i32* %75)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Your arguments:\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [25 x i8] c"Your arguments (sorted):\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = add nsw i32 %0, -1
%6 = tail call i32* @calloc(i32 %5, i32 4)
%7 = icmp sgt i32 %0, 1
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %24
10: ; preds = %2
%11 = zext i32 %5 to i64
br label %16
12: ; preds = %16
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br i1 %7, label %14, label %37
14: ; preds = %12
%15 = zext i32 %5 to i64
br label %30
16: ; preds = %10, %16
%17 = phi i64 [ 0, %10 ], [ %18, %16 ]
%18 = add nuw nsw i64 %17, 1
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i32, i32* %6, i64 %17
store i32 %21, i32* %22
%23 = icmp eq i64 %18, %11
br i1 %23, label %12, label %16
24: ; preds = %30, %8
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @insertionsort(i32* %6, i32 %5)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br i1 %7, label %28, label %41
28: ; preds = %24
%29 = zext i32 %5 to i64
br label %43
30: ; preds = %14, %30
%31 = phi i64 [ 0, %14 ], [ %35, %30 ]
%32 = getelementptr inbounds i32, i32* %6, i64 %31
%33 = load i32, i32* %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i64 %31, 1
%36 = icmp eq i64 %35, %15
br i1 %36, label %24, label %30
37: ; preds = %12
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = tail call i32 @insertionsort(i32* %6, i32 %5)
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %43, %37, %24
%42 = tail call i32 @free(i32* %6)
ret i32 0
43: ; preds = %28, %43
%44 = phi i64 [ 0, %28 ], [ %48, %43 ]
%45 = getelementptr inbounds i32, i32* %6, i64 %44
%46 = load i32, i32* %45
%47 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %44, 1
%49 = icmp eq i64 %48, %29
br i1 %49, label %41, label %43
}