#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*/ __raise__(char *, char *, int, char *, char *,
                             int /*<<< orphan*/);
char *_path_join(char const *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
FILE *_big_file_open_a_file(const char *basename, int fileid, char *mode,
                            int raise) {
  char *filename;
  int unbuffered = 0;
  if (fileid == -1) {
    filename = _path_join(basename, "header");
  } else if (fileid == -2) {
    filename = _path_join(basename, "attr");
  } else if (fileid == -3) {
    filename = _path_join(basename, "attr-v2");
  } else {
    char d[128];
    sprintf(d, "%06X", fileid);
    filename = _path_join(basename, d);
    unbuffered = 1;
  }
  FILE *fp = fopen(filename, mode);
  if (!raise && fp == NULL) {
    goto ex_fopen;
  }
  {
    if (fp == NULL) {
      __raise__("Failed to open physical file `%s' with mode `%s' (%s)",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/rainwoodman/fastPM/refs/"
                "heads/master/depends/bigfile/bigfile.c",
                1932, filename, mode, strerror(errno));
      goto ex_fopen;
    };
  };
  if (unbuffered) {
    setbuf(fp, NULL);
  }
ex_fopen:
  free(filename);
  return fp;
}


x86 assembly (clang, -O0):
<_big_file_open_a_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b3 <_big_file_open_a_file+0x43>
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1050 <_path_join@plt>
mov    %rax,-0x28(%rbp)
jmp    1234 <_big_file_open_a_file+0xc4>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    11d6 <_big_file_open_a_file+0x66>
mov    -0x8(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <_path_join@plt>
mov    %rax,-0x28(%rbp)
jmp    122f <_big_file_open_a_file+0xbf>
cmpl   $0xfffffffd,-0xc(%rbp)
jne    11f9 <_big_file_open_a_file+0x89>
mov    -0x8(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1050 <_path_join@plt>
mov    %rax,-0x28(%rbp)
jmp    122a <_big_file_open_a_file+0xba>
lea    -0xb0(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe0a(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1050 <_path_join@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    122f <_big_file_open_a_file+0xbf>
jmp    1234 <_big_file_open_a_file+0xc4>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1265 <_big_file_open_a_file+0xf5>
cmpq   $0x0,-0xb8(%rbp)
jne    1265 <_big_file_open_a_file+0xf5>
jmp    12e4 <_big_file_open_a_file+0x174>
cmpq   $0x0,-0xb8(%rbp)
jne    12c5 <_big_file_open_a_file+0x155>
mov    -0x28(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0xc8(%rbp),%rcx
mov    -0xc0(%rbp),%r8
mov    %eax,%r9d
lea    0xd6a(%rip),%rdi
lea    0xd99(%rip),%rsi
mov    $0x78c,%edx
call   1080 <__raise__@plt>
jmp    12e4 <_big_file_open_a_file+0x174>
cmpl   $0x0,-0x2c(%rbp)
je     12df <_big_file_open_a_file+0x16f>
mov    -0xb8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
jmp    12e4 <_big_file_open_a_file+0x174>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0xb8(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_big_file_open_a_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
cmp    $0xfffffffd,%esi
je     11a2 <_big_file_open_a_file+0x32>
mov    %esi,%edx
cmp    $0xfffffffe,%esi
je     11ab <_big_file_open_a_file+0x3b>
cmp    $0xffffffff,%edx
jne    11c2 <_big_file_open_a_file+0x52>
lea    0xe60(%rip),%rsi
jmp    11b2 <_big_file_open_a_file+0x42>
lea    0xe63(%rip),%rsi
jmp    11b2 <_big_file_open_a_file+0x42>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1050 <_path_join@plt>
mov    %rax,%rbx
mov    $0x1,%r12b
jmp    11e5 <_big_file_open_a_file+0x75>
lea    0xe4b(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <_path_join@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %r15d,%r15d
jne    11fd <_big_file_open_a_file+0x8d>
test   %rbp,%rbp
je     1242 <_big_file_open_a_file+0xd2>
test   %rbp,%rbp
je     1213 <_big_file_open_a_file+0xa3>
test   %r12b,%r12b
jne    1242 <_big_file_open_a_file+0xd2>
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <setbuf@plt>
jmp    1242 <_big_file_open_a_file+0xd2>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf1(%rip),%rdi
lea    0xe20(%rip),%rsi
mov    $0x78c,%edx
mov    %rbx,%rcx
mov    %r14,%r8
mov    %eax,%r9d
call   1080 <__raise__@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"header\00"
@.str.1 = [5 x i8] c"attr\00"
@.str.2 = [8 x i8] c"attr-v2\00"
@.str.3 = [5 x i8] c"%06X\00"
@.str.4 = [54 x i8] c"Failed to open physical file `%s' with mode `%s' (%s)\00"
@.str.5 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/rainwoodman/fastPM/refs/heads/master/depends/bigfile/bigfile.c\00"
@errno = global i32 0
define i32* @_big_file_open_a_file(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [128 x i8]
%12 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %10
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = call i8* @_path_join(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %9
br label %39
18: ; preds = %4
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = call i8* @_path_join(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %9
br label %38
24: ; preds = %18
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -3
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = call i8* @_path_join(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %29, i8** %9
br label %37
30: ; preds = %24
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%36 = call i8* @_path_join(i8* %34, i8* %35)
store i8* %36, i8** %9
store i32 1, i32* %10
br label %37
37: ; preds = %30, %27
br label %38
38: ; preds = %37, %21
br label %39
39: ; preds = %38, %15
%40 = load i8*, i8** %9
%41 = load i8*, i8** %7
%42 = call i32* @fopen(i8* %40, i8* %41)
store i32* %42, i32** %12
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %39
%46 = load i32*, i32** %12
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %49
48: ; preds = %45
br label %65
49: ; preds = %45, %39
%50 = load i32*, i32** %12
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i8*, i8** %9
%54 = load i8*, i8** %7
%55 = load i32, i32* @errno
%56 = call i32 @strerror(i32 %55)
%57 = call i32 @__raise__(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.5, i64 0, i64 0), i32 1932, i8* %53, i8* %54, i32 %56)
br label %65
58: ; preds = %49
%59 = load i32, i32* %10
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32*, i32** %12
%63 = call i32 @setbuf(i32* %62, i32* null)
br label %64
64: ; preds = %61, %58
br label %65
65: ; preds = %64, %52, %48
%66 = load i8*, i8** %9
%67 = call i32 @free(i8* %66)
%68 = load i32*, i32** %12
ret i32* %68
}

LLVM IR (-O2):
@.str = [7 x i8] c"header\00"
@.str.1 = [5 x i8] c"attr\00"
@.str.2 = [8 x i8] c"attr-v2\00"
@.str.3 = [5 x i8] c"%06X\00"
@.str.4 = [54 x i8] c"Failed to open physical file `%s' with mode `%s' (%s)\00"
@.str.5 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/rainwoodman/fastPM/refs/heads/master/depends/bigfile/bigfile.c\00"
@errno = global i32 0
define noalias i32* @_big_file_open_a_file(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [128 x i8]
switch i32 %1, label %12 [
i32 -1, label %6
i32 -2, label %8
i32 -3, label %10
]
6: ; preds = %4
%7 = tail call i8* @_path_join(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
8: ; preds = %4
%9 = tail call i8* @_path_join(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
10: ; preds = %4
%11 = tail call i8* @_path_join(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %16
12: ; preds = %4
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%14 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%15 = call i8* @_path_join(i8* %0, i8* %13)
br label %16
16: ; preds = %8, %12, %10, %6
%17 = phi i1 [ true, %8 ], [ false, %12 ], [ true, %10 ], [ true, %6 ]
%18 = phi i8* [ %9, %8 ], [ %15, %12 ], [ %11, %10 ], [ %7, %6 ]
%19 = call i32* @fopen(i8* %18, i8* %2)
%20 = icmp eq i32 %3, 0
%21 = icmp eq i32* %19, null
%22 = and i1 %20, %21
br i1 %22, label %31, label %23
23: ; preds = %16
br i1 %21, label %24, label %28
24: ; preds = %23
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 @__raise__(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.5, i64 0, i64 0), i32 1932, i8* %18, i8* %2, i32 %26)
br label %31
28: ; preds = %23
br i1 %17, label %31, label %29
29: ; preds = %28
%30 = call i32 @setbuf(i32* %19, i32* null)
br label %31
31: ; preds = %28, %29, %16, %24
%32 = call i32 @free(i8* %18)
ret i32* %19
}