#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*/ dump(int *);
int /*<<< orphan*/ insertion_sort(int *);
int random();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int unsorted[20 + 1] = {0};
  srand(time(NULL));
  int i = 0;
  for (i = 0; i < 20; i++) {
    unsorted[i] = random() % 1000;
  }
  unsorted[20] = -1;
  dump(unsorted);
  insertion_sort(unsorted);
  dump(unsorted);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1030 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x14,-0x74(%rbp)
jge    11d6 <main+0x76>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq -0x74(%rbp),%rax
mov    %edx,-0x70(%rbp,%rax,4)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11a7 <main+0x47>
movl   $0xffffffff,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <dump@plt>
lea    -0x70(%rbp),%rdi
call   1080 <insertion_sort@plt>
lea    -0x70(%rbp),%rdi
call   1040 <dump@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <random@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    1180 <main+0x30>
movl   $0xffffffff,0x50(%rsp)
ff
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <dump@plt>
mov    %rbx,%rdi
call   1070 <insertion_sort@plt>
mov    %rbx,%rdi
call   1030 <dump@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [21 x i32]* %6 to i8*
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
store i32 0, i32* %7
store i32 0, i32* %7
br label %11
11: ; preds = %20, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 20
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = call i32 (...) @random()
%16 = srem i32 %15, 1000
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %18
store i32 %16, i32* %19
br label %20
20: ; preds = %14
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %11
23: ; preds = %11
%24 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 20
store i32 -1, i32* %24
%25 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%26 = call i32 @dump(i32* %25)
%27 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%28 = call i32 @insertion_sort(i32* %27)
%29 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%30 = call i32 @dump(i32* %29)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [21 x i32]
%4 = bitcast [21 x i32]* %3 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ 0, %2 ], [ %12, %7 ]
%9 = tail call i32 (...) @random()
%10 = srem i32 %9, 1000
%11 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 %8
store i32 %10, i32* %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 20
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 20
store i32 -1, i32* %15
%16 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 0
%17 = call i32 @dump(i32* %16)
%18 = call i32 @insertion_sort(i32* %16)
%19 = call i32 @dump(i32* %16)
ret i32 0
}