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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
long file_length(char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int,
                           char const *);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
struct gges_bnf_grammar *gges_parse_bnf(char *);
char *reallocate(int /*<<< orphan*/ *, long, int, char *, int, int);
int /*<<< orphan*/ stderr;
struct gges_bnf_grammar *gges_load_bnf(const char *file_name) {
  FILE *f;
  char *data;
  long flen;
  struct gges_bnf_grammar *g;
  flen = file_length(file_name);
  f = fopen(file_name, "r");
  if (f == NULL) {
    fprintf(stderr, "%s:%d - ERROR: Failed to open file %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/master/src/"
            "grammar.c",
            95, file_name);
    exit(EXIT_FAILURE);
  }
  data = reallocate(NULL, (flen + 1), (sizeof(char)),
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/"
                    "heads/master/src/grammar.c",
                    99, false);
  fread(data, 1, flen, f);
  data[flen] = '\0';
  fclose(f);
  g = gges_parse_bnf(data);
  free(data);
  return g;
}


x86 assembly (clang, -O0):
<gges_load_bnf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <file_length@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11fb <gges_load_bnf+0x6b>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%r8
lea    0xe26(%rip),%rsi
lea    0xe46(%rip),%rdx
mov    $0x5f,%ecx
call   1070 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1,%edx
lea    0xe16(%rip),%rcx
mov    $0x63,%r8d
xor    %r9d,%r9d
call   1060 <reallocate@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1090 <gges_parse_bnf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gges_load_bnf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1080 <file_length@plt>
mov    %rax,%r14
lea    0xe56(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1222 <gges_load_bnf+0x92>
mov    %rax,%r12
mov    %r14,%rsi
add    $0x1,%rsi
lea    0xe61(%rip),%rcx
xor    %edi,%edi
mov    $0x1,%edx
mov    $0x63,%r8d
xor    %r9d,%r9d
call   1060 <reallocate@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r12,%rcx
call   1040 <fread@plt>
movb   $0x0,(%rbx,%r14,1)
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1090 <gges_parse_bnf@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
lea    0xdf0(%rip),%rdx
mov    $0x5f,%ecx
mov    %r15,%r8
call   1070 <fprintf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.gges_bnf_grammar = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"%s:%d - ERROR: Failed to open file %s\0A\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/master/src/grammar.c\00"
@EXIT_FAILURE = global i32 0
define %struct.gges_bnf_grammar* @gges_load_bnf(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.gges_bnf_grammar*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @file_length(i8* %7)
store i64 %8, i64* %5
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 95, i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %1
%20 = load i64, i64* %5
%21 = add nsw i64 %20, 1
%22 = call i8* @reallocate(i32* null, i64 %21, i32 1, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 99, i32 0)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = load i64, i64* %5
%25 = load i32*, i32** %3
%26 = call i32 @fread(i8* %23, i32 1, i64 %24, i32* %25)
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
%32 = load i8*, i8** %4
%33 = call %struct.gges_bnf_grammar* @gges_parse_bnf(i8* %32)
store %struct.gges_bnf_grammar* %33, %struct.gges_bnf_grammar** %6
%34 = load i8*, i8** %4
%35 = call i32 @free(i8* %34)
%36 = load %struct.gges_bnf_grammar*, %struct.gges_bnf_grammar** %6
ret %struct.gges_bnf_grammar* %36
}

LLVM IR (-O2):
%struct.gges_bnf_grammar = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"%s:%d - ERROR: Failed to open file %s\0A\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/master/src/grammar.c\00"
@EXIT_FAILURE = global i32 0
define %struct.gges_bnf_grammar* @gges_load_bnf(i8* %0) {
%2 = tail call i64 @file_length(i8* %0)
%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 %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 95, i8* %0)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = add nsw i64 %2, 1
%12 = tail call i8* @reallocate(i32* null, i64 %11, i32 1, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 99, i32 0)
%13 = tail call i32 @fread(i8* %12, i32 1, i64 %2, i32* %3)
%14 = getelementptr inbounds i8, i8* %12, i64 %2
store i8 0, i8* %14
%15 = tail call i32 @fclose(i32* %3)
%16 = tail call %struct.gges_bnf_grammar* @gges_parse_bnf(i8* %12)
%17 = tail call i32 @free(i8* %12)
ret %struct.gges_bnf_grammar* %16
}