#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__ ENOENT;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IRWXG;
int S_IRWXU;
int S_IWGRP;
int S_IWUSR;
int S_IXOTH;
int close(int);
scalar_t__ errno;
scalar_t__ find_file(char *, char *);
int mkdir(char *, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int unlink(char *);
int main(int argc, const char **argv) {
  int rv = 0;
  int fd = 0;
  rv = mkdir("tmp", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  if (rv < 0 && errno != EEXIST) {
    perror("mkdir failed");
    return 1;
  }
  rv = unlink("tmp"
              "/"
              "__testfile__");
  if (rv < 0 && errno != ENOENT) {
    perror("unlink failed");
    return 1;
  }
  if (find_file("tmp", "__testfile__")) {
    perror("file "
           "__testfile__"
           " was unexpectedly found");
    return 1;
  }
  fd = open("tmp"
            "/"
            "__testfile__",
            O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  if (fd < 0) {
    perror("open failed");
    return 1;
  }
  if (!find_file("tmp", "__testfile__")) {
    perror("file "
           "__testfile__"
           " was not found");
    return 1;
  }
  rv = close(fd);
  if (rv < 0) {
    perror("close failed");
    return 1;
  }
  rv = unlink("tmp"
              "/"
              "__testfile__");
  if (rv < 0) {
    perror("unlink failed");
    return 1;
  }
  printf("test completed successfully\n");
  return rv;
}


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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
mov    0x2ddb(%rip),%rax
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
lea    0xe41(%rip),%rdi
call   1040 <mkdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1203 <main+0x93>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
je     1203 <main+0x93>
lea    0xe12(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
lea    0xe07(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    124e <main+0xde>
mov    0x2d75(%rip),%rax
mov    (%rax),%rax
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%rax
je     124e <main+0xde>
lea    0xde5(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
lea    0xdab(%rip),%rdi
lea    0xdb9(%rip),%rsi
call   1070 <find_file@plt>
cmp    $0x0,%rax
je     1283 <main+0x113>
lea    0xdbe(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
mov    0x2d04(%rip),%rax
or     (%rax),%esi
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
mov    0x2d0a(%rip),%rax
or     (%rax),%edx
mov    0x2cd9(%rip),%rax
or     (%rax),%edx
mov    0x2d00(%rip),%rax
or     (%rax),%edx
lea    0xd48(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12f3 <main+0x183>
lea    0xd77(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
lea    0xd06(%rip),%rdi
lea    0xd14(%rip),%rsi
call   1070 <find_file@plt>
cmp    $0x0,%rax
jne    1328 <main+0x1b8>
lea    0xd4e(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1355 <main+0x1e5>
lea    0xd41(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
lea    0xcb5(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1386 <main+0x216>
lea    0xcad(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1398 <main+0x228>
lea    0xd05(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e68(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfe(%rip),%rax
or     (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
lea    0xe64(%rip),%rdi
call   1040 <mkdir@plt>
test   %eax,%eax
jns    11bf <main+0x4f>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    0x2df2(%rip),%rcx
cmp    (%rcx),%rax
jne    12c6 <main+0x156>
lea    0xe4b(%rip),%rdi
call   1030 <unlink@plt>
test   %eax,%eax
jns    11e9 <main+0x79>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%rax
jne    1299 <main+0x129>
lea    0xe10(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1070 <find_file@plt>
test   %rax,%rax
jne    12a2 <main+0x132>
mov    0x2dec(%rip),%rax
mov    0x2dc5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d82(%rip),%rax
or     (%rax),%esi
mov    0x2d59(%rip),%rax
mov    0x2d8a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d57(%rip),%rax
or     (%rax),%edx
mov    0x2d7e(%rip),%rax
or     (%rax),%edx
lea    0xdc6(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     12ab <main+0x13b>
mov    %eax,%ebx
lea    0xda3(%rip),%rdi
lea    0xdb1(%rip),%rsi
call   1070 <find_file@plt>
test   %rax,%rax
je     12b4 <main+0x144>
mov    %ebx,%edi
call   1060 <close@plt>
test   %eax,%eax
js     12bd <main+0x14d>
lea    0xd91(%rip),%rdi
call   1030 <unlink@plt>
test   %eax,%eax
js     1299 <main+0x129>
mov    %eax,%ebx
lea    0xe00(%rip),%rdi
call   1050 <puts@plt>
jmp    12d7 <main+0x167>
lea    0xd82(%rip),%rdi
jmp    12cd <main+0x15d>
lea    0xd87(%rip),%rdi
jmp    12cd <main+0x15d>
lea    0xda7(%rip),%rdi
jmp    12cd <main+0x15d>
lea    0xdaa(%rip),%rdi
jmp    12cd <main+0x15d>
lea    0xdc1(%rip),%rdi
jmp    12cd <main+0x15d>
lea    0xd37(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"tmp\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [13 x i8] c"mkdir failed\00"
@.str.2 = [17 x i8] c"tmp/__testfile__\00"
@ENOENT = global i64 0
@.str.3 = [14 x i8] c"unlink failed\00"
@.str.4 = [13 x i8] c"__testfile__\00"
@.str.5 = [41 x i8] c"file __testfile__ was unexpectedly found\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.6 = [12 x i8] c"open failed\00"
@.str.7 = [32 x i8] c"file __testfile__ was not found\00"
@.str.8 = [13 x i8] c"close failed\00"
@.str.9 = [29 x i8] c"test completed successfully\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* @S_IRWXU
%9 = load i32, i32* @S_IRWXG
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IXOTH
%14 = or i32 %12, %13
%15 = call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i64, i64* @errno
%20 = load i64, i64* @EEXIST
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %78
24: ; preds = %18, %2
%25 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %78
34: ; preds = %28, %24
%35 = call i64 @find_file(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %78
39: ; preds = %34
%40 = load i32, i32* @O_CREAT
%41 = load i32, i32* @O_RDWR
%42 = or i32 %40, %41
%43 = load i32, i32* @O_EXCL
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IRUSR
%46 = load i32, i32* @S_IWUSR
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IRGRP
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IWGRP
%51 = or i32 %49, %50
%52 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %39
%56 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %78
57: ; preds = %39
%58 = call i64 @find_file(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%59 = icmp ne i64 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %78
62: ; preds = %57
%63 = load i32, i32* %7
%64 = call i32 @close(i32 %63)
store i32 %64, i32* %6
%65 = load i32, i32* %6
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %78
69: ; preds = %62
%70 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 %70, i32* %6
%71 = load i32, i32* %6
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %78
75: ; preds = %69
%76 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%77 = load i32, i32* %6
store i32 %77, i32* %3
br label %78
78: ; preds = %75, %73, %67, %60, %55, %37, %32, %22
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [4 x i8] c"tmp\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [13 x i8] c"mkdir failed\00"
@.str.2 = [17 x i8] c"tmp/__testfile__\00"
@ENOENT = global i64 0
@.str.3 = [14 x i8] c"unlink failed\00"
@.str.4 = [13 x i8] c"__testfile__\00"
@.str.5 = [41 x i8] c"file __testfile__ was unexpectedly found\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.6 = [12 x i8] c"open failed\00"
@.str.7 = [32 x i8] c"file __testfile__ was not found\00"
@.str.8 = [13 x i8] c"close failed\00"
@str = [28 x i8] c"test completed successfully\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @S_IRWXU
%4 = load i32, i32* @S_IRWXG
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IROTH
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IXOTH
%9 = or i32 %7, %8
%10 = tail call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i64, i64* @errno
%14 = load i64, i64* @EEXIST
%15 = icmp eq i64 %13, %14
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %66
18: ; preds = %12, %2
%19 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i64, i64* @errno
%23 = load i64, i64* @ENOENT
%24 = icmp eq i64 %22, %23
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %66
27: ; preds = %21, %18
%28 = tail call i64 @find_file(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %66
32: ; preds = %27
%33 = load i32, i32* @O_CREAT
%34 = load i32, i32* @O_RDWR
%35 = or i32 %34, %33
%36 = load i32, i32* @O_EXCL
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IRUSR
%39 = load i32, i32* @S_IWUSR
%40 = or i32 %39, %38
%41 = load i32, i32* @S_IRGRP
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IWGRP
%44 = or i32 %42, %43
%45 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %32
%48 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %66
49: ; preds = %32
%50 = tail call i64 @find_file(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %66
54: ; preds = %49
%55 = tail call i32 @close(i32 %45)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %66
59: ; preds = %54
%60 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %66
64: ; preds = %59
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %66
66: ; preds = %64, %62, %57, %52, %47, %30, %25, %16
%67 = phi i32 [ 1, %16 ], [ 1, %25 ], [ 1, %30 ], [ 1, %47 ], [ 1, %57 ], [ 1, %62 ], [ %60, %64 ], [ 1, %52 ]
ret i32 %67
}