#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int FileProxy_ReadFile(char *filename, char *buf, int size) {
  FILE *ifp;
  int ch;
  int count = 0;
  if ((ifp = fopen(filename, "r")) == NULL) {
    return (1);
  }
  while ((ch = fgetc(ifp)) != EOF) {
    if (count < size) {
      buf[count] = ch;
      count++;
    }
  }
  fclose(ifp);
  return (0);
}


x86 assembly (clang, -O0):
<FileProxy_ReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1174 <FileProxy_ReadFile+0x44>
movl   $0x1,-0x4(%rbp)
jmp    11ce <FileProxy_ReadFile+0x9e>
jmp    1179 <FileProxy_ReadFile+0x49>
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
je     11be <FileProxy_ReadFile+0x8e>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b9 <FileProxy_ReadFile+0x89>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1179 <FileProxy_ReadFile+0x49>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileProxy_ReadFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1172 <FileProxy_ReadFile+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e87(%rip),%r15
cmp    (%r15),%eax
jne    1180 <FileProxy_ReadFile+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1177 <FileProxy_ReadFile+0x47>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    119d <FileProxy_ReadFile+0x6d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
je     1166 <FileProxy_ReadFile+0x36>
cmp    %r12d,%ebp
jge    1190 <FileProxy_ReadFile+0x60>
movslq %ebp,%rcx
mov    %al,(%r14,%rcx,1)
add    $0x1,%ebp
jmp    1190 <FileProxy_ReadFile+0x60>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @FileProxy_ReadFile(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 1, i32* %4
br label %38
15: ; preds = %3
br label %16
16: ; preds = %34, %15
%17 = load i32*, i32** %8
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %9
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = load i32, i32* %10
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i32, i32* %9
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %6
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %34
34: ; preds = %25, %21
br label %16
35: ; preds = %16
%36 = load i32*, i32** %8
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %4
br label %38
38: ; preds = %35, %14
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @FileProxy_ReadFile(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = tail call i32 @fgetc(i32* %4)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %24, label %10
10: ; preds = %6, %19
%11 = phi i32 [ %21, %19 ], [ %7, %6 ]
%12 = phi i32 [ %20, %19 ], [ 0, %6 ]
%13 = icmp slt i32 %12, %2
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = trunc i32 %11 to i8
%16 = sext i32 %12 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %15, i8* %17
%18 = add nsw i32 %12, 1
br label %19
19: ; preds = %14, %10
%20 = phi i32 [ %18, %14 ], [ %12, %10 ]
%21 = tail call i32 @fgetc(i32* %4)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %10
24: ; preds = %19, %6
%25 = tail call i32 @fclose(i32* %4)
br label %26
26: ; preds = %3, %24
%27 = phi i32 [ 0, %24 ], [ 1, %3 ]
ret i32 %27
}