#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
bool load(char buf[], const char *fname, int size) {
  FILE *f;
  int len;
  f = fopen(fname, "r");
  if (f == NULL) {
    len = 0;
  } else {
    len = fread(buf, sizeof(char), size, f);
    fclose(f);
  }
  buf[len] = '\0';
  buf[len + 1] = '\0';
  return len > 0;
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116e <load+0x3e>
movl   $0x0,-0x24(%rbp)
jmp    118f <load+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x24(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xeb9(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1176 <load+0x46>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    1178 <load+0x48>
xor    %ebx,%ebx
movslq %ebx,%rcx
movw   $0x0,(%r15,%rcx,1)
xor    %eax,%eax
test   %ecx,%ecx
setg   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @load(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @fread(i8* %0, i32 1, i32 %2, i32* %4)
%8 = tail call i32 @fclose(i32* %4)
br label %9
9: ; preds = %3, %6
%10 = phi i32 [ %7, %6 ], [ 0, %3 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
%13 = add nsw i32 %10, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
%16 = icmp sgt i32 %10, 0
%17 = zext i1 %16 to i32
ret i32 %17
}