#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ open_file(int /*<<< orphan*/ **, char *, char *, int, char *);
int main(int argc, char **argv) {
  FILE *fp;
  if (open_file(&fp, "foo_bar", "w", 13,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/alexhilton/miscellaneous/"
                "refs/heads/master/linux/linux-prog-24-codes/testmacs.c")) {
    exit(EXIT_FAILURE);
  } else {
    fputs("this text proves we scribbled in the file.\n", fp);
    fclose(fp);
  }
  if (open_file(&fp, "bar_baz", "r", 21,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/alexhilton/miscellaneous/"
                "refs/heads/master/linux/linux-prog-24-codes/testmacs.c")) {
    exit(EXIT_FAILURE);
  } else {
    fclose(fp);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    0xea0(%rip),%rdx
mov    $0xd,%ecx
lea    0xe96(%rip),%r8
call   1040 <open_file@plt>
cmp    $0x0,%rax
je     1191 <main+0x51>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xf18(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x18(%rbp),%rdi
lea    0xf2b(%rip),%rsi
lea    0xe4a(%rip),%rdx
mov    $0x15,%ecx
lea    0xe42(%rip),%r8
call   1040 <open_file@plt>
cmp    $0x0,%rax
je     11e5 <main+0xa5>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rsi
lea    0xeb9(%rip),%rdx
lea    0xeb4(%rip),%r8
mov    %rsp,%rdi
mov    $0xd,%ecx
call   1040 <open_file@plt>
test   %rax,%rax
jne    11bf <main+0x7f>
mov    (%rsp),%rcx
lea    0xf41(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    (%rsp),%rdi
call   1030 <fclose@plt>
lea    0xf4e(%rip),%rsi
lea    0xe6d(%rip),%rdx
lea    0xe6a(%rip),%r8
mov    %rsp,%rdi
mov    $0x15,%ecx
call   1040 <open_file@plt>
test   %rax,%rax
jne    11bf <main+0x7f>
mov    (%rsp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"foo_bar\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [170 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/alexhilton/miscellaneous/refs/heads/master/linux/linux-prog-24-codes/testmacs.c\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [44 x i8] c"this text proves we scribbled in the file.\0A\00"
@.str.4 = [8 x i8] c"bar_baz\00"
@.str.5 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 @open_file(i32** %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 13, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32*, i32** %6
%14 = call i32 @fputs(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %12
%18 = call i64 @open_file(i32** %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %17
%24 = load i32*, i32** %6
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foo_bar\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [170 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/alexhilton/miscellaneous/refs/heads/master/linux/linux-prog-24-codes/testmacs.c\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [44 x i8] c"this text proves we scribbled in the file.\0A\00"
@.str.4 = [8 x i8] c"bar_baz\00"
@.str.5 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i64 @open_file(i32** %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 13, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = load i32*, i32** %3
%12 = call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64 43, i64 1, i32* %11)
%13 = load i32*, i32** %3
%14 = call i32 @fclose(i32* %13)
%15 = call i64 @open_file(i32** %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
ret i32 0
}