#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__ EISDIR;
scalar_t__ ENOENT;
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
scalar_t__ chdir(char *);
scalar_t__ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ mkdir(char *, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
char *tmpnam(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char *dir = tmpnam(NULL);
  int failure = 0;
  int fd;
  if (dir == NULL) {
    perror("tmpnam");
    return -1;
  }
  if (mkdir(dir, 0755) != 0) {
    perror("mkdir");
    return -1;
  }
  if (chdir(dir) != 0) {
    perror("chdir");
    remove(dir);
    return -1;
  }
  if (open(dir, O_WRONLY) >= 0) {
    fprintf(stderr, "can open directory `%s' for writing!!!\n", dir);
    failure = 1;
  }
  if (errno != EISDIR) {
    fprintf(stderr, "open (directory): expected `%s', got `%s'\n",
            strerror(EISDIR), strerror(errno));
    failure = 1;
  }
  if (open("nonexist", O_RDONLY) >= 0) {
    fprintf(stderr, "can open non-existing file for reading!!!\n");
    failure = 1;
  }
  if (errno != ENOENT) {
    fprintf(stderr, "open (nonexist): expected `%s', got `%s'\n",
            strerror(ENOENT), strerror(errno));
    failure = 1;
  }
  if (open("nodir/nonexist", O_RDONLY) >= 0) {
    fprintf(stderr, "can open non-existing file for reading!!!\n");
    failure = 1;
  }
  if (errno != ENOENT) {
    fprintf(stderr, "open (nodir/nonexist): expected `%s', got `%s'\n",
            strerror(ENOENT), strerror(errno));
    failure = 1;
  }
  fd = open("exist", O_WRONLY | O_CREAT);
  if (fd < 0) {
    perror("open for writing");
    failure = 1;
    goto lose;
  }
  if (close(fd) != 0) {
    perror("close");
    failure = 1;
    goto lose;
  }
lose:
  (void)remove("exist");
  (void)chdir("/");
  (void)remove(dir);
  return failure;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <tmpnam@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dd <main+0x4d>
lea    0xe34(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c4 <main+0x334>
mov    -0x18(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     120d <main+0x7d>
lea    0xe0b(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c4 <main+0x334>
mov    -0x18(%rbp),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
je     1241 <main+0xb1>
lea    0xde6(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <remove@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c4 <main+0x334>
mov    -0x18(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0x0,%eax
jl     127e <main+0xee>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%rax
mov    0x2d51(%rip),%rcx
cmp    (%rcx),%rax
je     12e5 <main+0x155>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d02(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
lea    0xdcc(%rip),%rdi
call   1080 <open@plt>
cmp    $0x0,%eax
jl     1321 <main+0x191>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    0x2c98(%rip),%rax
mov    (%rax),%rax
mov    0x2c7e(%rip),%rcx
cmp    (%rcx),%rax
je     1388 <main+0x1f8>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2c62(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,-0x38(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    0x2c49(%rip),%rax
mov    (%rax),%esi
lea    0xd23(%rip),%rdi
call   1080 <open@plt>
cmp    $0x0,%eax
jl     13c4 <main+0x234>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
lea    0xcb0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    0x2bf5(%rip),%rax
mov    (%rax),%rax
mov    0x2bdb(%rip),%rcx
cmp    (%rcx),%rax
je     142b <main+0x29b>
mov    0x2be3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2bbf(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,-0x48(%rbp)
mov    0x2bbc(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xcad(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    0x2b76(%rip),%rax
mov    (%rax),%esi
mov    0x2bbd(%rip),%rax
or     (%rax),%esi
lea    0xc80(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    146e <main+0x2de>
lea    0xc9d(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x1c(%rbp)
jmp    149d <main+0x30d>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
je     1498 <main+0x308>
lea    0xc84(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x1c(%rbp)
jmp    149d <main+0x30d>
jmp    149d <main+0x30d>
lea    0xc20(%rip),%rdi
call   1030 <remove@plt>
lea    0xc61(%rip),%rdi
call   1050 <chdir@plt>
mov    -0x18(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   10a0 <tmpnam@plt>
test   %rax,%rax
je     13a2 <main+0x212>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
jne    13ab <main+0x21b>
mov    %r14,%rdi
call   1050 <chdir@plt>
test   %rax,%rax
jne    13be <main+0x22e>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     120b <main+0x7b>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
jmp    120d <main+0x7d>
xor    %ebp,%ebp
mov    0x2dac(%rip),%r12
mov    0x2dc5(%rip),%rax
mov    (%rax),%rdi
cmp    %rdi,(%r12)
je     1259 <main+0xc9>
mov    0x2d9d(%rip),%rax
mov    (%rax),%ebp
call   10b0 <strerror@plt>
mov    %rax,%rbx
mov    (%r12),%rdi
call   10b0 <strerror@plt>
lea    0xdf6(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
mov    0x2d78(%rip),%r13
mov    0x0(%r13),%esi
lea    0xe56(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1290 <main+0x100>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
mov    0x2d19(%rip),%r15
mov    (%r15),%rdi
cmp    %rdi,(%r12)
je     12d5 <main+0x145>
mov    0x2d21(%rip),%rax
mov    (%rax),%ebx
call   10b0 <strerror@plt>
mov    %rax,%rbp
mov    (%r12),%rdi
call   10b0 <strerror@plt>
lea    0xdd0(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
mov    0x0(%r13),%esi
lea    0xddb(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1305 <main+0x175>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
mov    (%r15),%rdi
cmp    %rdi,(%r12)
je     1343 <main+0x1b3>
mov    0x2cb3(%rip),%rax
mov    (%rax),%ebx
call   10b0 <strerror@plt>
mov    %rax,%rbp
mov    (%r12),%rdi
call   10b0 <strerror@plt>
lea    0xd9b(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
mov    0x2c55(%rip),%rax
or     (%rax),%esi
lea    0xd68(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     13d9 <main+0x249>
mov    %eax,%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13e2 <main+0x252>
lea    0xd4c(%rip),%rdi
call   1030 <remove@plt>
lea    0xd8d(%rip),%rdi
call   1050 <chdir@plt>
mov    %r14,%rdi
call   1030 <remove@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc57(%rip),%rdi
jmp    13b2 <main+0x222>
lea    0xc55(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1391 <main+0x201>
lea    0xc48(%rip),%rdi
call   1090 <perror@plt>
mov    %r14,%rdi
call   1030 <remove@plt>
mov    $0xffffffff,%ebp
jmp    1391 <main+0x201>
lea    0xd1a(%rip),%rdi
jmp    13e9 <main+0x259>
lea    0xd22(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebp
jmp    1371 <main+0x1e1>

LLVM IR (-O0):
@.str = [7 x i8] c"tmpnam\00"
@.str.1 = [6 x i8] c"mkdir\00"
@.str.2 = [6 x i8] c"chdir\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.3 = [40 x i8] c"can open directory `%s' for writing!!!\0A\00"
@errno = global i64 0
@EISDIR = global i64 0
@.str.4 = [43 x i8] c"open (directory): expected `%s', got `%s'\0A\00"
@.str.5 = [9 x i8] c"nonexist\00"
@O_RDONLY = global i32 0
@.str.6 = [43 x i8] c"can open non-existing file for reading!!!\0A\00"
@ENOENT = global i64 0
@.str.7 = [42 x i8] c"open (nonexist): expected `%s', got `%s'\0A\00"
@.str.8 = [15 x i8] c"nodir/nonexist\00"
@.str.9 = [48 x i8] c"open (nodir/nonexist): expected `%s', got `%s'\0A\00"
@.str.10 = [6 x i8] c"exist\00"
@O_CREAT = global i32 0
@.str.11 = [17 x i8] c"open for writing\00"
@.str.12 = [6 x i8] c"close\00"
@.str.13 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @tmpnam(i32* null)
store i8* %9, i8** %6
store i32 0, i32* %7
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %106
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i64 @mkdir(i8* %15, i32 493)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %106
20: ; preds = %14
%21 = load i8*, i8** %6
%22 = call i64 @chdir(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %6
%27 = call i32 @remove(i8* %26)
store i32 -1, i32* %3
br label %106
28: ; preds = %20
%29 = load i8*, i8** %6
%30 = load i32, i32* @O_WRONLY
%31 = call i32 @open(i8* %29, i32 %30)
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %6
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %35)
store i32 1, i32* %7
br label %37
37: ; preds = %33, %28
%38 = load i64, i64* @errno
%39 = load i64, i64* @EISDIR
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = load i64, i64* @EISDIR
%44 = call i8* @strerror(i64 %43)
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %44, i8* %46)
store i32 1, i32* %7
br label %48
48: ; preds = %41, %37
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = icmp sge i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %7
br label %55
55: ; preds = %52, %48
%56 = load i64, i64* @errno
%57 = load i64, i64* @ENOENT
%58 = icmp ne i64 %56, %57
br i1 %58, label %59, label %66
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i64, i64* @ENOENT
%62 = call i8* @strerror(i64 %61)
%63 = load i64, i64* @errno
%64 = call i8* @strerror(i64 %63)
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %62, i8* %64)
store i32 1, i32* %7
br label %66
66: ; preds = %59, %55
%67 = load i32, i32* @O_RDONLY
%68 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %67)
%69 = icmp sge i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %7
br label %73
73: ; preds = %70, %66
%74 = load i64, i64* @errno
%75 = load i64, i64* @ENOENT
%76 = icmp ne i64 %74, %75
br i1 %76, label %77, label %84
77: ; preds = %73
%78 = load i32, i32* @stderr
%79 = load i64, i64* @ENOENT
%80 = call i8* @strerror(i64 %79)
%81 = load i64, i64* @errno
%82 = call i8* @strerror(i64 %81)
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0), i8* %80, i8* %82)
store i32 1, i32* %7
br label %84
84: ; preds = %77, %73
%85 = load i32, i32* @O_WRONLY
%86 = load i32, i32* @O_CREAT
%87 = or i32 %85, %86
%88 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 %87)
store i32 %88, i32* %8
%89 = load i32, i32* %8
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %84
%92 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %7
br label %100
93: ; preds = %84
%94 = load i32, i32* %8
%95 = call i64 @close(i32 %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %7
br label %100
99: ; preds = %93
br label %100
100: ; preds = %99, %97, %91
%101 = call i32 @remove(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%102 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%103 = load i8*, i8** %6
%104 = call i32 @remove(i8* %103)
%105 = load i32, i32* %7
store i32 %105, i32* %3
br label %106
106: ; preds = %100, %24, %18, %12
%107 = load i32, i32* %3
ret i32 %107
}

LLVM IR (-O2):
@.str = [7 x i8] c"tmpnam\00"
@.str.1 = [6 x i8] c"mkdir\00"
@.str.2 = [6 x i8] c"chdir\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.3 = [40 x i8] c"can open directory `%s' for writing!!!\0A\00"
@errno = global i64 0
@EISDIR = global i64 0
@.str.4 = [43 x i8] c"open (directory): expected `%s', got `%s'\0A\00"
@.str.5 = [9 x i8] c"nonexist\00"
@O_RDONLY = global i32 0
@.str.6 = [43 x i8] c"can open non-existing file for reading!!!\0A\00"
@ENOENT = global i64 0
@.str.7 = [42 x i8] c"open (nonexist): expected `%s', got `%s'\0A\00"
@.str.8 = [15 x i8] c"nodir/nonexist\00"
@.str.9 = [48 x i8] c"open (nodir/nonexist): expected `%s', got `%s'\0A\00"
@.str.10 = [6 x i8] c"exist\00"
@O_CREAT = global i32 0
@.str.11 = [17 x i8] c"open for writing\00"
@.str.12 = [6 x i8] c"close\00"
@.str.13 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @tmpnam(i32* null)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %92
7: ; preds = %2
%8 = tail call i64 @mkdir(i8* %3, i32 493)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %92
12: ; preds = %7
%13 = tail call i64 @chdir(i8* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @remove(i8* %3)
br label %92
18: ; preds = %12
%19 = load i32, i32* @O_WRONLY
%20 = tail call i32 @open(i8* %3, i32 %19)
%21 = icmp sgt i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %25
25: ; preds = %22, %18
%26 = phi i32 [ 1, %22 ], [ 0, %18 ]
%27 = load i64, i64* @errno
%28 = load i64, i64* @EISDIR
%29 = icmp eq i64 %27, %28
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = tail call i8* @strerror(i64 %28)
%33 = load i64, i64* @errno
%34 = tail call i8* @strerror(i64 %33)
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %32, i8* %34)
br label %36
36: ; preds = %30, %25
%37 = phi i32 [ 1, %30 ], [ %26, %25 ]
%38 = load i32, i32* @O_RDONLY
%39 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = icmp sgt i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %41, %36
%45 = phi i32 [ 1, %41 ], [ %37, %36 ]
%46 = load i64, i64* @errno
%47 = load i64, i64* @ENOENT
%48 = icmp eq i64 %46, %47
br i1 %48, label %55, label %49
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = tail call i8* @strerror(i64 %47)
%52 = load i64, i64* @errno
%53 = tail call i8* @strerror(i64 %52)
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %51, i8* %53)
br label %55
55: ; preds = %49, %44
%56 = phi i32 [ 1, %49 ], [ %45, %44 ]
%57 = load i32, i32* @O_RDONLY
%58 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %57)
%59 = icmp sgt i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %60, %55
%64 = phi i32 [ 1, %60 ], [ %56, %55 ]
%65 = load i64, i64* @errno
%66 = load i64, i64* @ENOENT
%67 = icmp eq i64 %65, %66
br i1 %67, label %74, label %68
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = tail call i8* @strerror(i64 %66)
%71 = load i64, i64* @errno
%72 = tail call i8* @strerror(i64 %71)
%73 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0), i8* %70, i8* %72)
br label %74
74: ; preds = %68, %63
%75 = phi i32 [ 1, %68 ], [ %64, %63 ]
%76 = load i32, i32* @O_WRONLY
%77 = load i32, i32* @O_CREAT
%78 = or i32 %77, %76
%79 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 %78)
%80 = icmp slt i32 %79, 0
br i1 %80, label %84, label %81
81: ; preds = %74
%82 = tail call i64 @close(i32 %79)
%83 = icmp eq i64 %82, 0
br i1 %83, label %87, label %84
84: ; preds = %81, %74
%85 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), %74 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), %81 ]
%86 = tail call i32 @perror(i8* %85)
br label %87
87: ; preds = %84, %81
%88 = phi i32 [ %75, %81 ], [ 1, %84 ]
%89 = tail call i32 @remove(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%90 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%91 = tail call i32 @remove(i8* %3)
br label %92
92: ; preds = %87, %15, %10, %5
%93 = phi i32 [ -1, %5 ], [ -1, %10 ], [ -1, %15 ], [ %88, %87 ]
ret i32 %93
}