#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int readfile(const char *pa, char *b) {
  char *p;
  FILE *f;
  f = fopen(pa, "r");
  if (f == 0)
    return -1;
  p = b;
  do {
    p += fread(p, 1, 256 - (p - b), f);
  } while (!feof(f) && 256 - (p - b));
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<readfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117b <readfile+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <readfile+0xcb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    11f0 <readfile+0xb0>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1183 <readfile+0x43>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b9 <readfile+0x79>
mov    %rax,%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edx
sub    %ebx,%edx
add    $0x100,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11ad <readfile+0x6d>
movslq %ebp,%rax
add    %rax,%rbx
mov    %r14,%rax
sub    %rbx,%rax
cmp    $0xffffffffffffff00,%rax
jne    1170 <readfile+0x30>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11be <readfile+0x7e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @readfile(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = ptrtoint i8* %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i8* [ %15, %7 ], [ %1, %5 ]
%9 = ptrtoint i8* %8 to i64
%10 = sub i64 %6, %9
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 256
%13 = tail call i32 @fread(i8* %8, i32 1, i32 %12, i32* %3)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
%16 = tail call i32 @feof(i32* %3)
%17 = icmp ne i32 %16, 0
%18 = ptrtoint i8* %15 to i64
%19 = sub i64 %6, %18
%20 = icmp eq i64 %19, -256
%21 = select i1 %17, i1 true, i1 %20
br i1 %21, label %22, label %7
22: ; preds = %7
%23 = tail call i32 @fclose(i32* %3)
br label %24
24: ; preds = %2, %22
%25 = phi i32 [ 0, %22 ], [ -1, %2 ]
ret i32 %25
}