#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 */
struct SsRuntime {
  int dummy;
};
struct SsParseBuffer {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, size_t);
int /*<<< orphan*/ fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int ssParse(struct SsRuntime *, struct SsParseBuffer *, char *, size_t);
int /*<<< orphan*/ stderr;
int ssLoad(struct SsRuntime *rt, struct SsParseBuffer *pb, char *p, size_t n,
           const char *name) {
  FILE *fd;
  size_t m;
  if ((fd = fopen(name, "rb")) == NULL)
    return -1;
  fseek(fd, 0, SEEK_END);
  if ((m = ftell(fd)) >= n)
    do {
      fprintf(stderr,
              "ssError: "
              "File (%u) is too large for buffer (%u)\n",
              m, n);
      return -1;
    } while (0);
  rewind(fd);
  fread(p, m, 1, fd);
  p[m] = 0;
  return ssParse(rt, pb, p, n);
}


x86 assembly (clang, -O0):
<ssLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b6 <ssLoad+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <ssLoad+0xe2>
mov    -0x38(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x40(%rbp)
cmp    -0x28(%rbp),%rax
jb     120f <ssLoad+0x9f>
jmp    11e6 <ssLoad+0x76>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <ssLoad+0xe2>
mov    -0x38(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <ssParse@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssLoad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe72(%rip),%rsi
mov    %r8,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     121f <ssLoad+0xaf>
mov    %rax,%rbx
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbp
cmp    %r13,%rax
jae    1204 <ssLoad+0x94>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movb   $0x0,(%r14,%rbp,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <ssParse@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.SsRuntime = type { i32 }
%struct.SsParseBuffer = type { i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [49 x i8] c"ssError: File (%u) is too large for buffer (%u)\0A\00"
define i32 @ssLoad(%struct.SsRuntime* %0, %struct.SsParseBuffer* %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.SsRuntime*
%8 = alloca %struct.SsParseBuffer*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i64
store %struct.SsRuntime* %0, %struct.SsRuntime** %7
store %struct.SsParseBuffer* %1, %struct.SsParseBuffer** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
%14 = load i8*, i8** %11
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 -1, i32* %6
br label %48
18: ; preds = %5
%19 = load i32*, i32** %12
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32*, i32** %12
%23 = call i64 @ftell(i32* %22)
store i64 %23, i64* %13
%24 = load i64, i64* %10
%25 = icmp uge i64 %23, %24
br i1 %25, label %26, label %33
26: ; preds = %18
br label %27
27: ; preds = %26
%28 = load i32, i32* @stderr
%29 = load i64, i64* %13
%30 = load i64, i64* %10
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %29, i64 %30)
store i32 -1, i32* %6
br label %48
32: ; No predecessors!
br label %33
33: ; preds = %32, %18
%34 = load i32*, i32** %12
%35 = call i32 @rewind(i32* %34)
%36 = load i8*, i8** %9
%37 = load i64, i64* %13
%38 = load i32*, i32** %12
%39 = call i32 @fread(i8* %36, i64 %37, i32 1, i32* %38)
%40 = load i8*, i8** %9
%41 = load i64, i64* %13
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8 0, i8* %42
%43 = load %struct.SsRuntime*, %struct.SsRuntime** %7
%44 = load %struct.SsParseBuffer*, %struct.SsParseBuffer** %8
%45 = load i8*, i8** %9
%46 = load i64, i64* %10
%47 = call i32 @ssParse(%struct.SsRuntime* %43, %struct.SsParseBuffer* %44, i8* %45, i64 %46)
store i32 %47, i32* %6
br label %48
48: ; preds = %33, %27, %17
%49 = load i32, i32* %6
ret i32 %49
}

LLVM IR (-O2):
%struct.SsRuntime = type { i32 }
%struct.SsParseBuffer = type { i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [49 x i8] c"ssError: File (%u) is too large for buffer (%u)\0A\00"
define i32 @ssLoad(%struct.SsRuntime* %0, %struct.SsParseBuffer* %1, i8* %2, i64 %3, i8* nocapture %4) {
%6 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %5
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %6, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %6)
%12 = icmp ult i64 %11, %3
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %11, i64 %3)
br label %21
16: ; preds = %8
%17 = tail call i32 @rewind(i32* %6)
%18 = tail call i32 @fread(i8* %2, i64 %11, i32 1, i32* %6)
%19 = getelementptr inbounds i8, i8* %2, i64 %11
store i8 0, i8* %19
%20 = tail call i32 @ssParse(%struct.SsRuntime* %0, %struct.SsParseBuffer* %1, i8* %2, i64 %3)
br label %21
21: ; preds = %5, %16, %13
%22 = phi i32 [ -1, %13 ], [ %20, %16 ], [ -1, %5 ]
ret i32 %22
}