#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 */
char *alloca(scalar_t__);
int /*<<< orphan*/ big_file_set_error_message2(char *, char *, int, char *,
                                               char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
FILE *open_a_file(char *basename, int fileid, char *mode) {
  char *filename = alloca(strlen(basename) + 128);
  if (fileid == -1) {
    sprintf(filename, "%s%s", basename, "header");
  } else if (fileid == -2) {
    sprintf(filename, "%s%s", basename, "attr");
  } else if (fileid == -3) {
    sprintf(filename, "%s%s", basename, "attr-v2");
  } else {
    sprintf(filename,
            "%s"
            "%06X",
            basename, fileid);
  }
  FILE *fp = fopen(filename, mode);
  {
    if (fp == NULL) {
      big_file_set_error_message2(
          "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/marcel-sl/fastpm/refs/heads/master/"
          "bigfile/bigfile.c",
          238, filename, mode, strerror(errno));
      goto ex_fopen;
    };
  };
ex_fopen:
  return fp;
}


x86 assembly (clang, -O0):
<open_a_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x80,%rdi
call   1040 <alloca@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11bb <open_a_file+0x5b>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe58(%rip),%rsi
lea    0xe56(%rip),%rcx
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1236 <open_a_file+0xd6>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    11e7 <open_a_file+0x87>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe2c(%rip),%rsi
lea    0xe31(%rip),%rcx
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1231 <open_a_file+0xd1>
cmpl   $0xfffffffd,-0xc(%rbp)
jne    1213 <open_a_file+0xb3>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe00(%rip),%rsi
lea    0xe0a(%rip),%rcx
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    122c <open_a_file+0xcc>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1231 <open_a_file+0xd1>
jmp    1236 <open_a_file+0xd6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1298 <open_a_file+0x138>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    %eax,%r9d
lea    0xd9e(%rip),%rdi
lea    0xdcd(%rip),%rsi
mov    $0xee,%edx
call   1060 <big_file_set_error_message2@plt>
jmp    129d <open_a_file+0x13d>
jmp    129d <open_a_file+0x13d>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_a_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x80(%rax),%rdi
call   1040 <alloca@plt>
mov    %rax,%r15
cmp    $0xfffffffd,%ebp
je     11a2 <open_a_file+0x42>
cmp    $0xfffffffe,%ebp
je     11b2 <open_a_file+0x52>
cmp    $0xffffffff,%ebp
jne    11cf <open_a_file+0x6f>
lea    0xe67(%rip),%rsi
lea    0xe65(%rip),%rcx
jmp    11c0 <open_a_file+0x60>
lea    0xe57(%rip),%rsi
lea    0xe61(%rip),%rcx
jmp    11c0 <open_a_file+0x60>
lea    0xe47(%rip),%rsi
lea    0xe4c(%rip),%rcx
mov    %r15,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    11e5 <open_a_file+0x85>
lea    0xe43(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <open_a_file+0xc7>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe13(%rip),%rdi
lea    0xe42(%rip),%rsi
mov    $0xee,%edx
mov    %r15,%rcx
mov    %r14,%r8
mov    %eax,%r9d
call   1060 <big_file_set_error_message2@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [7 x i8] c"header\00"
@.str.2 = [5 x i8] c"attr\00"
@.str.3 = [8 x i8] c"attr-v2\00"
@.str.4 = [7 x i8] c"%s%06X\00"
@.str.5 = [54 x i8] c"Failed to open physical file `%s' with mode `%s' (%s)\00"
@.str.6 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/marcel-sl/fastpm/refs/heads/master/bigfile/bigfile.c\00"
@errno = global i32 0
define i32* @open_a_file(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 128
%12 = call i8* @alloca(i64 %11)
store i8* %12, i8** %7
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = load i8*, i8** %4
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %40
19: ; preds = %3
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, -2
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %39
26: ; preds = %19
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, -3
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = load i8*, i8** %4
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %38
33: ; preds = %26
%34 = load i8*, i8** %7
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %35, i32 %36)
br label %38
38: ; preds = %33, %29
br label %39
39: ; preds = %38, %22
br label %40
40: ; preds = %39, %15
%41 = load i8*, i8** %7
%42 = load i8*, i8** %6
%43 = call i32* @fopen(i8* %41, i8* %42)
store i32* %43, i32** %8
%44 = load i32*, i32** %8
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %52
46: ; preds = %40
%47 = load i8*, i8** %7
%48 = load i8*, i8** %6
%49 = load i32, i32* @errno
%50 = call i32 @strerror(i32 %49)
%51 = call i32 @big_file_set_error_message2(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 238, i8* %47, i8* %48, i32 %50)
br label %53
52: ; preds = %40
br label %53
53: ; preds = %52, %46
%54 = load i32*, i32** %8
ret i32* %54
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [7 x i8] c"header\00"
@.str.2 = [5 x i8] c"attr\00"
@.str.3 = [8 x i8] c"attr-v2\00"
@.str.4 = [7 x i8] c"%s%06X\00"
@.str.5 = [54 x i8] c"Failed to open physical file `%s' with mode `%s' (%s)\00"
@.str.6 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/marcel-sl/fastpm/refs/heads/master/bigfile/bigfile.c\00"
@errno = global i32 0
define noalias i32* @open_a_file(i8* %0, i32 %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 128
%6 = tail call i8* @alloca(i64 %5)
switch i32 %1, label %13 [
i32 -1, label %7
i32 -2, label %9
i32 -3, label %11
]
7: ; preds = %3
%8 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %15
9: ; preds = %3
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %15
11: ; preds = %3
%12 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %15
13: ; preds = %3
%14 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %1)
br label %15
15: ; preds = %9, %13, %11, %7
%16 = tail call i32* @fopen(i8* %6, i8* %2)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
%21 = tail call i32 @big_file_set_error_message2(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 238, i8* %6, i8* %2, i32 %20)
br label %22
22: ; preds = %15, %18
ret i32* %16
}