#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 */

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ EPERM;
int /*<<< orphan*/ close(int);
int creat(char *, int);
scalar_t__ errno;
scalar_t__ getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd;
  if (argc < 2)
    return 125;
  if ((fd = creat(argv[1], 0644)) < 0) {
    if (getenv("PANDORA_TEST_SUCCESS")) {
      perror("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/"
             "t004_creat.c");
      return 1;
    }
    if (getenv("PANDORA_TEST_EEXIST") && errno == EEXIST)
      return 0;
    if (getenv("PANDORA_TEST_EPERM") && errno == EPERM)
      return 0;
    perror("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/"
           "t004_creat.c");
    return 1;
  }
  if (argc > 2)
    write(fd, argv[2], strlen(argv[2]));
  close(fd);
  return getenv("PANDORA_TEST_SUCCESS") ? 0 : 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118c <main+0x2c>
movl   $0x7d,-0x4(%rbp)
jmp    12c7 <main+0x167>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1268 <main+0x108>
lea    0xe4f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11d8 <main+0x78>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x167>
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1214 <main+0xb4>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
jne    1214 <main+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    12c7 <main+0x167>
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1250 <main+0xf0>
mov    0x2da7(%rip),%rax
mov    (%rax),%rax
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1250 <main+0xf0>
movl   $0x0,-0x4(%rbp)
jmp    12c7 <main+0x167>
lea    0xdbe(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x167>
cmpl   $0x2,-0x8(%rbp)
jle    129f <main+0x13f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xd52(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x7d,%eax
cmp    $0x2,%edi
jl     1241 <main+0xe1>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
test   %eax,%eax
js     11cd <main+0x6d>
mov    %eax,%r14d
cmp    $0x3,%ebp
jb     11aa <main+0x4a>
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xe47(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    %eax,%eax
jmp    1241 <main+0xe1>
lea    0xe2c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1230 <main+0xd0>
lea    0xebc(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1207 <main+0xa7>
mov    0x2de2(%rip),%rax
mov    (%rax),%rcx
mov    0x2de0(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1241 <main+0xe1>
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1230 <main+0xd0>
mov    0x2db9(%rip),%rax
mov    (%rax),%rcx
mov    0x2d9f(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1241 <main+0xe1>
lea    0xdde(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"PANDORA_TEST_SUCCESS\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/t004_creat.c\00"
@.str.2 = [20 x i8] c"PANDORA_TEST_EEXIST\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.3 = [19 x i8] c"PANDORA_TEST_EPERM\00"
@EPERM = global i64 0
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 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 125, i32* %3
br label %59
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @creat(i8* %13, i32 420)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %10
%17 = call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %59
21: ; preds = %16
%22 = call i64 @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = load i64, i64* @EEXIST
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 0, i32* %3
br label %59
29: ; preds = %24, %21
%30 = call i64 @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i64, i64* @errno
%34 = load i64, i64* @EPERM
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 0, i32* %3
br label %59
37: ; preds = %32, %29
%38 = call i32 @perror(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %59
39: ; preds = %10
%40 = load i32, i32* %4
%41 = icmp sgt i32 %40, 2
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load i32, i32* %6
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @write(i32 %43, i8* %46, i32 %50)
br label %52
52: ; preds = %42, %39
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
%55 = call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%56 = icmp ne i64 %55, 0
%57 = zext i1 %56 to i64
%58 = select i1 %56, i32 0, i32 2
store i32 %58, i32* %3
br label %59
59: ; preds = %52, %37, %36, %28, %19, %9
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [21 x i8] c"PANDORA_TEST_SUCCESS\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/t004_creat.c\00"
@.str.2 = [20 x i8] c"PANDORA_TEST_EEXIST\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.3 = [19 x i8] c"PANDORA_TEST_EPERM\00"
@EPERM = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %42, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @creat(i8* %6, i32 420)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %4
%10 = tail call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0))
br label %42
14: ; preds = %9
%15 = tail call i64 @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @EEXIST
%20 = icmp eq i64 %18, %19
br i1 %20, label %42, label %21
21: ; preds = %17, %14
%22 = tail call i64 @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = load i64, i64* @EPERM
%27 = icmp eq i64 %25, %26
br i1 %27, label %42, label %28
28: ; preds = %24, %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0))
br label %42
30: ; preds = %4
%31 = icmp ugt i32 %0, 2
br i1 %31, label %32, label %37
32: ; preds = %30
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = tail call i32 @strlen(i8* %34)
%36 = tail call i32 @write(i32 %7, i8* %34, i32 %35)
br label %37
37: ; preds = %32, %30
%38 = tail call i32 @close(i32 %7)
%39 = tail call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
%41 = select i1 %40, i32 2, i32 0
br label %42
42: ; preds = %24, %17, %2, %37, %28, %12
%43 = phi i32 [ 1, %12 ], [ 1, %28 ], [ %41, %37 ], [ 125, %2 ], [ 0, %17 ], [ 0, %24 ]
ret i32 %43
}