#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int slurp(char *filename, char *buf, int bufl) {
  int l, ll;
  FILE *fp;
  if ((fp = fopen(filename, "r")) == 0) {
    perror(filename);
    exit(1);
  }
  l = 0;
  while (l < bufl && (ll = fread(buf + l, 1, bufl - l, fp)) > 0)
    l += ll;
  fclose(fp);
  if (l == bufl) {
    fprintf(stderr, "%s: too big, max size: %d\n", filename, bufl - 1);
    exit(1);
  }
  buf[l] = 0;
  return l;
}


x86 assembly (clang, -O0):
<slurp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a4 <slurp+0x44>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x29(%rbp)
jge    11e7 <slurp+0x87>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
setg   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f7 <slurp+0x97>
jmp    1205 <slurp+0xa5>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11ab <slurp+0x4b>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1243 <slurp+0xe3>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
lea    0xdce(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slurp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d1 <slurp+0x71>
mov    %rax,%r12
xor    %ebp,%ebp
test   %ebx,%ebx
jle    11b2 <slurp+0x52>
nopw   0x0(%rax,%rax,1)
movslq %ebp,%rax
lea    (%r15,%rax,1),%rdi
mov    %ebx,%edx
sub    %eax,%edx
mov    $0x1,%esi
mov    %r12,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11b2 <slurp+0x52>
add    %eax,%ebp
cmp    %ebx,%ebp
jl     1190 <slurp+0x30>
mov    %r12,%rdi
call   1040 <fclose@plt>
cmp    %ebx,%ebp
je     11e3 <slurp+0x83>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
add    $0xffffffff,%ebx
lea    0xe0c(%rip),%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"%s: too big, max size: %d\0A\00"
define i32 @slurp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
store i32 0, i32* %7
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = sub nsw i32 %27, %28
%30 = load i32*, i32** %9
%31 = call i32 @fread(i8* %26, i32 1, i32 %29, i32* %30)
store i32 %31, i32* %8
%32 = icmp sgt i32 %31, 0
br label %33
33: ; preds = %22, %18
%34 = phi i1 [ false, %18 ], [ %32, %22 ]
br i1 %34, label %35, label %39
35: ; preds = %33
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = add nsw i32 %37, %36
store i32 %38, i32* %7
br label %18
39: ; preds = %33
%40 = load i32*, i32** %9
%41 = call i32 @fclose(i32* %40)
%42 = load i32, i32* %7
%43 = load i32, i32* %6
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %52
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %4
%48 = load i32, i32* %6
%49 = sub nsw i32 %48, 1
%50 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %47, i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %39
%53 = load i8*, i8** %5
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"%s: too big, max size: %d\0A\00"
define i32 @slurp(i8* %0, i8* nocapture %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 %8, label %6
6: ; preds = %3
%7 = icmp sgt i32 %2, 0
br i1 %7, label %13, label %21
8: ; preds = %3
%9 = tail call i32 @perror(i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %13
%12 = icmp slt i32 %20, %2
br i1 %12, label %13, label %21
13: ; preds = %6, %11
%14 = phi i32 [ %20, %11 ], [ 0, %6 ]
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = sub nsw i32 %2, %14
%18 = tail call i32 @fread(i8* %16, i32 1, i32 %17, i32* %4)
%19 = icmp sgt i32 %18, 0
%20 = add nsw i32 %18, %14
br i1 %19, label %11, label %21
21: ; preds = %13, %11, %6
%22 = phi i32 [ 0, %6 ], [ %20, %11 ], [ %14, %13 ]
%23 = tail call i32 @fclose(i32* %4)
%24 = icmp eq i32 %22, %2
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = add nsw i32 %2, -1
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = sext i32 %22 to i64
%32 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 0, i8* %32
ret i32 %22
}