#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 EXIT_SUCCESS;
int /*<<< orphan*/ fill_arr(int *, char *);
int /*<<< orphan*/ free(int *);
long long get_num_ints(char *);
long long intsort(int *, long long);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  long long int num_ints;
  long long int iterations = 1;
  num_ints = get_num_ints("./randnums.txt");
  printf("%lli ints in file, allocating memory ...", num_ints);
  int *arr_ptr = malloc(sizeof(int) * num_ints);
  printf(" DONE!\n");
  fill_arr(arr_ptr, "./randnums.txt");
  long long int ret = 0;
  while ((ret = intsort(arr_ptr, num_ints)) != 0) {
    iterations++;
  }
  printf("%lli iterations made\n", iterations);
  free(arr_ptr);
  return (EXIT_SUCCESS);
}


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)
movq   $0x1,-0x20(%rbp)
lea    0xe7b(%rip),%rdi
call   1080 <get_num_ints@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1060 <fill_arr@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <intsort@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1205 <main+0xa5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d9 <main+0x79>
mov    -0x20(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%r12
mov    %r12,%rdi
call   1090 <get_num_ints@plt>
mov    %rax,%r14
lea    0xe7e(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe9c(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <fill_arr@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <intsort@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    11d0 <main+0x60>
lea    0xe4d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"./randnums.txt\00"
@.str.1 = [41 x i8] c"%lli ints in file, allocating memory ...\00"
@.str.2 = [8 x i8] c" DONE!\0A\00"
@.str.3 = [22 x i8] c"%lli iterations made\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %7
%10 = call i64 @get_num_ints(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = load i64, i64* %6
%14 = mul i64 4, %13
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32*, i32** %8
%19 = call i32 @fill_arr(i32* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %9
br label %20
20: ; preds = %25, %2
%21 = load i32*, i32** %8
%22 = load i64, i64* %6
%23 = call i64 @intsort(i32* %21, i64 %22)
store i64 %23, i64* %9
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i64, i64* %7
%27 = add nsw i64 %26, 1
store i64 %27, i64* %7
br label %20
28: ; preds = %20
%29 = load i64, i64* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %29)
%31 = load i32*, i32** %8
%32 = call i32 @free(i32* %31)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}

LLVM IR (-O2):
@.str = [15 x i8] c"./randnums.txt\00"
@.str.1 = [41 x i8] c"%lli ints in file, allocating memory ...\00"
@.str.3 = [22 x i8] c"%lli iterations made\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [7 x i8] c" DONE!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @get_num_ints(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%5 = trunc i64 %3 to i32
%6 = shl i32 %5, 2
%7 = tail call i32* @malloc(i32 %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @fill_arr(i32* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %10, %2
%11 = phi i64 [ 1, %2 ], [ %14, %10 ]
%12 = tail call i64 @intsort(i32* %7, i64 %3)
%13 = icmp eq i64 %12, 0
%14 = add nuw nsw i64 %11, 1
br i1 %13, label %15, label %10
15: ; preds = %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %11)
%17 = tail call i32 @free(i32* %7)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}