#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 avail_space(char *, unsigned long long *);
int chdir(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int open_file_in_dir(char *cwd, char *dir, char *fname,
                     unsigned long long filesize) {
  int status = 0;
  if (cwd == NULL) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 25,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
      };
      status = -1;
      goto BYE;
    };
  }
  if (dir == NULL) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 26,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
      };
      status = -1;
      goto BYE;
    };
  }
  if (fname == NULL) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 27,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
      };
      status = -1;
      goto BYE;
    };
  }
  FILE *fp = NULL;
  if (filesize > 0) {
    unsigned long long space_available;
    status = avail_space(dir, &space_available);
    {
      if ((status) < 0) {
        {
          {
            fprintf(stderr, "Line %3d of File %s \n", 33,
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                    "heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
          };
          status = (status);
          goto BYE;
        }
      }
    };
    if (space_available <= filesize) {
      fprintf(stderr, "Space (%llu bytes) in directory [%s] not available \n",
              filesize, dir);
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 37,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
        };
        status = -1;
        goto BYE;
      };
    }
  }
  status = chdir(dir);
  {
    if ((status) < 0) {
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 41,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
        };
        status = (status);
        goto BYE;
      }
    }
  };
  if (status != 0) {
    fprintf(stderr, "Directory [%s] not accessible \n", dir);
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 44,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
      };
      status = -1;
      goto BYE;
    };
  }
  fp = fopen(fname, "wb");
  {
    if (fp == NULL) {
      fprintf(stderr, "Unable to open file %s for %s \n", fname, "wb");
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 48,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
        };
        status = -1;
        goto BYE;
      };
    }
  };
  {
    if ((fp) != NULL) {
      fclose((fp));
      (fp) = NULL;
    }
  };
  status = chdir(cwd);
  {
    if ((status) < 0) {
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 51,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c");
        };
        status = (status);
        goto BYE;
      }
    }
  };
BYE:
  return (status);
}


x86 assembly (clang, -O0):
<open_file_in_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a9 <open_file_in_dir+0x59>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    $0x19,%edx
lea    0xe80(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
cmpq   $0x0,-0x10(%rbp)
jne    11e3 <open_file_in_dir+0x93>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    $0x1a,%edx
lea    0xe46(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
cmpq   $0x0,-0x18(%rbp)
jne    121d <open_file_in_dir+0xcd>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    $0x1b,%edx
lea    0xe0c(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    12d9 <open_file_in_dir+0x189>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <avail_space@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1278 <open_file_in_dir+0x128>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    $0x21,%edx
lea    0xdb0(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     12d4 <open_file_in_dir+0x184>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
mov    $0x25,%edx
lea    0xd55(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
jmp    12d9 <open_file_in_dir+0x189>
mov    -0x10(%rbp),%rdi
call   1050 <chdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    131d <open_file_in_dir+0x1cd>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
mov    $0x29,%edx
lea    0xd0b(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
cmpl   $0x0,-0x24(%rbp)
je     1371 <open_file_in_dir+0x221>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
lea    0xcae(%rip),%rsi
mov    $0x2c,%edx
lea    0xcb8(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
mov    -0x18(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13e1 <open_file_in_dir+0x291>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd6b(%rip),%rsi
lea    0xd61(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
lea    0xc3e(%rip),%rsi
mov    $0x30,%edx
lea    0xc48(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
cmpq   $0x0,-0x30(%rbp)
je     13fd <open_file_in_dir+0x2ad>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <chdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1441 <open_file_in_dir+0x2f1>
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
lea    0xbdd(%rip),%rsi
mov    $0x33,%edx
lea    0xbe7(%rip),%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1446 <open_file_in_dir+0x2f6>
jmp    1446 <open_file_in_dir+0x2f6>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file_in_dir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11f1 <open_file_in_dir+0xa1>
mov    %rsi,%rbx
test   %rsi,%rsi
je     120f <open_file_in_dir+0xbf>
mov    %rdx,%r14
test   %rdx,%rdx
je     122d <open_file_in_dir+0xdd>
mov    %rcx,%r12
mov    %rdi,%rbp
test   %rcx,%rcx
je     11a8 <open_file_in_dir+0x58>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <avail_space@plt>
test   %eax,%eax
js     1266 <open_file_in_dir+0x116>
cmp    %r12,0x8(%rsp)
jbe    1291 <open_file_in_dir+0x141>
mov    %rbx,%rdi
call   1050 <chdir@plt>
test   %eax,%eax
js     1270 <open_file_in_dir+0x120>
je     12dc <open_file_in_dir+0x18c>
mov    0x2e1b(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xf1d(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe1d(%rip),%rsi
lea    0xe2c(%rip),%rcx
mov    $0x2c,%edx
jmp    1249 <open_file_in_dir+0xf9>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
lea    0xe0e(%rip),%rcx
mov    $0x19,%edx
jmp    1249 <open_file_in_dir+0xf9>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
lea    0xdf0(%rip),%rcx
mov    $0x1a,%edx
jmp    1249 <open_file_in_dir+0xf9>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
lea    0xdd2(%rip),%rcx
mov    $0x1b,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
mov    $0x21,%edx
jmp    12b9 <open_file_in_dir+0x169>
mov    %eax,%r15d
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
lea    0xd8c(%rip),%rcx
mov    $0x29,%edx
jmp    12d0 <open_file_in_dir+0x180>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    $0x25,%edx
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
lea    0xd46(%rip),%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1256 <open_file_in_dir+0x106>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1329 <open_file_in_dir+0x1d9>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1050 <chdir@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1256 <open_file_in_dir+0x106>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xce5(%rip),%rsi
lea    0xcf4(%rip),%rcx
mov    $0x33,%edx
jmp    12d0 <open_file_in_dir+0x180>
mov    0x2cb0(%rip),%rbx
mov    (%rbx),%edi
lea    0xdd6(%rip),%rsi
lea    0xdcc(%rip),%rcx
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xcad(%rip),%rsi
lea    0xcbc(%rip),%rcx
mov    $0x30,%edx
jmp    1249 <open_file_in_dir+0xf9>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c\00"
@.str.2 = [53 x i8] c"Space (%llu bytes) in directory [%s] not available \0A\00"
@.str.3 = [32 x i8] c"Directory [%s] not accessible \0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [32 x i8] c"Unable to open file %s for %s \0A\00"
define i32 @open_file_in_dir(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 0, i32* %9
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %98
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %98
23: ; preds = %17
%24 = load i8*, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %98
29: ; preds = %23
store i32* null, i32** %10
%30 = load i64, i64* %8
%31 = icmp ugt i64 %30, 0
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = load i8*, i8** %6
%34 = call i32 @avail_space(i8* %33, i64* %11)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* %9
store i32 %40, i32* %9
br label %98
41: ; preds = %32
%42 = load i64, i64* %11
%43 = load i64, i64* %8
%44 = icmp ule i64 %42, %43
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = load i64, i64* %8
%48 = load i8*, i8** %6
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i64 %47, i8* %48)
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 37, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %98
52: ; preds = %41
br label %53
53: ; preds = %52, %29
%54 = load i8*, i8** %6
%55 = call i32 @chdir(i8* %54)
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 41, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
%61 = load i32, i32* %9
store i32 %61, i32* %9
br label %98
62: ; preds = %53
%63 = load i32, i32* %9
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = load i8*, i8** %6
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %67)
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 44, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %98
71: ; preds = %62
%72 = load i8*, i8** %7
%73 = call i32* @fopen(i8* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %73, i32** %10
%74 = load i32*, i32** %10
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %82
76: ; preds = %71
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %7
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %98
82: ; preds = %71
%83 = load i32*, i32** %10
%84 = icmp ne i32* %83, null
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32*, i32** %10
%87 = call i32 @fclose(i32* %86)
store i32* null, i32** %10
br label %88
88: ; preds = %85, %82
%89 = load i8*, i8** %5
%90 = call i32 @chdir(i8* %89)
store i32 %90, i32* %9
%91 = load i32, i32* %9
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %88
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
%96 = load i32, i32* %9
store i32 %96, i32* %9
br label %98
97: ; preds = %88
br label %98
98: ; preds = %97, %93, %76, %65, %58, %45, %37, %26, %20, %14
%99 = load i32, i32* %9
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/DEPRECATED_Q2/AUX/open_file_in_dir.c\00"
@.str.2 = [53 x i8] c"Space (%llu bytes) in directory [%s] not available \0A\00"
@.str.3 = [32 x i8] c"Directory [%s] not accessible \0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [32 x i8] c"Unable to open file %s for %s \0A\00"
define i32 @open_file_in_dir(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i64
%6 = icmp eq i8* %0, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
10: ; preds = %4
%11 = icmp eq i8* %1, null
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
15: ; preds = %10
%16 = icmp eq i8* %2, null
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
20: ; preds = %15
%21 = icmp eq i64 %3, 0
br i1 %21, label %38, label %22
22: ; preds = %20
%23 = bitcast i64* %5 to i8*
%24 = call i32 @avail_space(i8* %1, i64* %5)
%25 = icmp slt i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %22
%27 = load i64, i64* %5
%28 = icmp ugt i64 %27, %3
br i1 %28, label %37, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i64 %3, i8* %1)
br label %32
32: ; preds = %22, %29
%33 = phi i32 [ 37, %29 ], [ 33, %22 ]
%34 = phi i32 [ -1, %29 ], [ %24, %22 ]
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %33, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
37: ; preds = %26
br label %38
38: ; preds = %37, %20
%39 = call i32 @chdir(i8* %1)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 41, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
44: ; preds = %38
%45 = icmp eq i32 %39, 0
br i1 %45, label %51, label %46
46: ; preds = %44
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 44, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
51: ; preds = %44
%52 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
59: ; preds = %51
%60 = call i32 @fclose(i32* %52)
%61 = call i32 @chdir(i8* %0)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %32, %7, %12, %17, %41, %46, %54, %63, %59
%67 = phi i32 [ -1, %7 ], [ -1, %12 ], [ -1, %17 ], [ %39, %41 ], [ -1, %46 ], [ -1, %54 ], [ %61, %63 ], [ %61, %59 ], [ %34, %32 ]
ret i32 %67
}