#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned int fread(unsigned int *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int read_file(char *filename, unsigned int **sourceInts, unsigned int *length) {
  unsigned int *source;
  unsigned int t;
  FILE *infile;
  infile = fopen(filename, "rb");
  if (infile == NULL)
    return 30;
  if (fseek(infile, 0, SEEK_END) != 0)
    return 1;
  *length = ftell(infile) / (sizeof(unsigned int));
  source = (unsigned int *)malloc((*length) * sizeof(unsigned int));
  if (source == NULL)
    return 1;
  rewind(infile);
  t = fread(source, sizeof(unsigned int), (size_t)(*length), infile);
  if (t != *length)
    return 1;
  *sourceInts = source;
  fclose(infile);
  return 0;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11af <read_file+0x3f>
movl   $0x1e,-0x4(%rbp)
jmp    1278 <read_file+0x108>
mov    -0x38(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     11d9 <read_file+0x69>
movl   $0x1,-0x4(%rbp)
jmp    1278 <read_file+0x108>
mov    -0x38(%rbp),%rdi
call   1060 <ftell@plt>
cltq
shr    $0x2,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121c <read_file+0xac>
movl   $0x1,-0x4(%rbp)
jmp    1278 <read_file+0x108>
mov    -0x38(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
je     125d <read_file+0xed>
movl   $0x1,-0x4(%rbp)
jmp    1278 <read_file+0x108>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1200 <read_file+0x90>
mov    %rax,%rbx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1205 <read_file+0x95>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ecx
sar    $0x2,%ecx
mov    %ecx,(%r15)
and    $0xfffffffc,%eax
mov    %eax,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1205 <read_file+0x95>
mov    %rax,%r12
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    (%r15),%edx
mov    %r12,%rdi
mov    $0x4,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    (%r15),%eax
jne    1205 <read_file+0x95>
mov    %r12,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
jmp    1205 <read_file+0x95>
mov    $0x1e,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @read_file(i8* %0, i32** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 30, i32* %4
br label %58
16: ; preds = %3
%17 = load i32*, i32** %10
%18 = load i32, i32* @SEEK_END
%19 = call i64 @fseek(i32* %17, i32 0, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %4
br label %58
22: ; preds = %16
%23 = load i32*, i32** %10
%24 = call i32 @ftell(i32* %23)
%25 = sext i32 %24 to i64
%26 = udiv i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = load i32*, i32** %7
store i32 %27, i32* %28
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = zext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i32*
store i32* %35, i32** %8
%36 = load i32*, i32** %8
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %39
38: ; preds = %22
store i32 1, i32* %4
br label %58
39: ; preds = %22
%40 = load i32*, i32** %10
%41 = call i32 @rewind(i32* %40)
%42 = load i32*, i32** %8
%43 = load i32*, i32** %7
%44 = load i32, i32* %43
%45 = zext i32 %44 to i64
%46 = load i32*, i32** %10
%47 = call i32 @fread(i32* %42, i32 4, i64 %45, i32* %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = load i32*, i32** %7
%50 = load i32, i32* %49
%51 = icmp ne i32 %48, %50
br i1 %51, label %52, label %53
52: ; preds = %39
store i32 1, i32* %4
br label %58
53: ; preds = %39
%54 = load i32*, i32** %8
%55 = load i32**, i32*** %6
store i32* %54, i32** %55
%56 = load i32*, i32** %10
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %4
br label %58
58: ; preds = %53, %52, %38, %21, %15
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @read_file(i8* nocapture %0, i32** nocapture writeonly %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @fseek(i32* %4, i32 0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = tail call i32 @ftell(i32* %4)
%12 = ashr i32 %11, 2
store i32 %12, i32* %2
%13 = and i32 %11, -4
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = icmp eq i64 %14, 0
br i1 %16, label %26, label %17
17: ; preds = %10
%18 = tail call i32 @rewind(i32* %4)
%19 = load i32, i32* %2
%20 = zext i32 %19 to i64
%21 = tail call i32 @fread(i32* %15, i32 4, i64 %20, i32* %4)
%22 = load i32, i32* %2
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
store i32* %15, i32** %1
%25 = tail call i32 @fclose(i32* %4)
br label %26
26: ; preds = %17, %10, %6, %3, %24
%27 = phi i32 [ 0, %24 ], [ 30, %3 ], [ 1, %6 ], [ 1, %10 ], [ 1, %17 ]
ret i32 %27
}