#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*/ bubble_sort(int *, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *, char *);
int *read_array(char *, int *, int *);
int main(int argc, char *argv[]) {
  int length, *num;
  char *fname = "rand.txt";
  printf("reading from %s\n", fname);
  num = read_array(fname, num, &length);
  print_array(num, length);
  bubble_sort(num, length);
  print_array(num, length);
  free(num);
  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)
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <read_array@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <bubble_sort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xead(%rip),%rdi
lea    0xe9d(%rip),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <read_array@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   1040 <print_array@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1070 <bubble_sort@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1040 <print_array@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"rand.txt\00"
@.str.1 = [17 x i8] c"reading from %s\0A\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i8*, i8** %8
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %8
%12 = load i32*, i32** %7
%13 = call i32* @read_array(i8* %11, i32* %12, i32* %6)
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = load i32, i32* %6
%16 = call i32 @print_array(i32* %14, i32 %15)
%17 = load i32*, i32** %7
%18 = load i32, i32* %6
%19 = call i32 @bubble_sort(i32* %17, i32 %18)
%20 = load i32*, i32** %7
%21 = load i32, i32* %6
%22 = call i32 @print_array(i32* %20, i32 %21)
%23 = load i32*, i32** %7
%24 = call i32 @free(i32* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"rand.txt\00"
@.str.1 = [17 x i8] c"reading from %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = call i32* @read_array(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* undef, i32* %3)
%7 = load i32, i32* %3
%8 = call i32 @print_array(i32* %6, i32 %7)
%9 = load i32, i32* %3
%10 = call i32 @bubble_sort(i32* %6, i32 %9)
%11 = load i32, i32* %3
%12 = call i32 @print_array(i32* %6, i32 %11)
%13 = call i32 @free(i32* %6)
ret i32 0
}