#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ S_IRWXG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
scalar_t__ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  if (mkdir("/tmp", S_IRWXG) != 0 && errno != EEXIST) {
    printf("Unable to create dir '/tmp'\n");
    return -1;
  }
  if (mkdir("/tmp/1", S_IRWXG) != 0 && errno != EEXIST) {
    printf("Unable to create dir '/tmp/1'\n");
    return -1;
  }
  if (mkdir("/tmp/1/", S_IRWXG) != 0 && errno != EEXIST) {
    printf("Unable to create dir '/tmp/1/'\n");
    return -1;
  }
  DIR *dir = opendir("/tmp");
  if (!dir) {
    printf("Unable to open dir '/tmp'\n");
    return -2;
  }
  struct dirent *dirent;
  while ((dirent = readdir(dir)) != 0) {
    printf("Found '%s'\n", dirent->d_name);
    if (strlen(dirent->d_name) == 0) {
      printf("Found empty path!\n");
      return -3;
    }
  }
  closedir(dir);
  printf("success\n");
  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)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     11c9 <main+0x69>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
je     11c9 <main+0x69>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1328 <main+0x1c8>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     121c <main+0xbc>
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     121c <main+0xbc>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1328 <main+0x1c8>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     126f <main+0x10f>
mov    0x2d8e(%rip),%rax
mov    (%rax),%rax
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
je     126f <main+0x10f>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1328 <main+0x1c8>
lea    0xd8a(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12a4 <main+0x144>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1328 <main+0x1c8>
jmp    12a9 <main+0x149>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     130a <main+0x1aa>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    1305 <main+0x1a5>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1328 <main+0x1c8>
jmp    12a9 <main+0x149>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7a(%rip),%rbx
mov    (%rbx),%esi
lea    0xe89(%rip),%rdi
call   1030 <mkdir@plt>
test   %rax,%rax
je     119b <main+0x3b>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
jne    124c <main+0xec>
mov    (%rbx),%esi
lea    0xe61(%rip),%rdi
call   1030 <mkdir@plt>
test   %rax,%rax
je     11c8 <main+0x68>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
jne    125a <main+0xfa>
mov    (%rbx),%esi
lea    0xe3b(%rip),%rdi
call   1030 <mkdir@plt>
test   %rax,%rax
je     11f1 <main+0x91>
mov    0x2dee(%rip),%rax
mov    (%rax),%rax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%rax
jne    1268 <main+0x108>
lea    0xe08(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1276 <main+0x116>
mov    %rax,%rbp
lea    0xe08(%rip),%r15
lea    0xe2f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1284 <main+0x124>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%rax
cmpb   $0x0,(%rax)
jne    1220 <main+0xc0>
mov    $0xfffffffd,%ebp
jmp    1295 <main+0x135>
mov    $0xffffffff,%ebp
lea    0xe39(%rip),%r14
jmp    1295 <main+0x135>
mov    $0xffffffff,%ebp
lea    0xe0d(%rip),%r14
jmp    1295 <main+0x135>
mov    $0xffffffff,%ebp
lea    0xde0(%rip),%r14
jmp    1295 <main+0x135>
mov    $0xfffffffe,%ebp
lea    0xd9e(%rip),%r14
jmp    1295 <main+0x135>
mov    %rbp,%rdi
call   1070 <closedir@plt>
xor    %ebp,%ebp
lea    0xda5(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"/tmp\00"
@S_IRWXG = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [29 x i8] c"Unable to create dir '/tmp'\0A\00"
@.str.2 = [7 x i8] c"/tmp/1\00"
@.str.3 = [31 x i8] c"Unable to create dir '/tmp/1'\0A\00"
@.str.4 = [8 x i8] c"/tmp/1/\00"
@.str.5 = [32 x i8] c"Unable to create dir '/tmp/1/'\0A\00"
@.str.6 = [27 x i8] c"Unable to open dir '/tmp'\0A\00"
@.str.7 = [12 x i8] c"Found '%s'\0A\00"
@.str.8 = [19 x i8] c"Found empty path!\0A\00"
@.str.9 = [9 x i8] c"success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @S_IRWXG
%9 = call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
17: ; preds = %11, %2
%18 = load i32, i32* @S_IRWXG
%19 = call i64 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = load i64, i64* @EEXIST
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
27: ; preds = %21, %17
%28 = load i32, i32* @S_IRWXG
%29 = call i64 @mkdir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = load i64, i64* @EEXIST
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
37: ; preds = %31, %27
%38 = call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32* %38, i32** %6
%39 = load i32*, i32** %6
%40 = icmp ne i32* %39, null
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
store i32 -2, i32* %3
br label %65
43: ; preds = %37
br label %44
44: ; preds = %60, %43
%45 = load i32*, i32** %6
%46 = call %struct.dirent* @readdir(i32* %45)
store %struct.dirent* %46, %struct.dirent** %7
%47 = icmp ne %struct.dirent* %46, null
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = load %struct.dirent*, %struct.dirent** %7
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %51)
%53 = load %struct.dirent*, %struct.dirent** %7
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i64 @strlen(i8* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %48
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
store i32 -3, i32* %3
br label %65
60: ; preds = %48
br label %44
61: ; preds = %44
%62 = load i32*, i32** %6
%63 = call i32 @closedir(i32* %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %65
65: ; preds = %61, %58, %41, %35, %25, %15
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"/tmp\00"
@S_IRWXG = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [7 x i8] c"/tmp/1\00"
@.str.4 = [8 x i8] c"/tmp/1/\00"
@.str.7 = [12 x i8] c"Found '%s'\0A\00"
@str = [26 x i8] c"Unable to open dir '/tmp'\00"
@str.10 = [8 x i8] c"success\00"
@str.11 = [18 x i8] c"Found empty path!\00"
@str.12 = [31 x i8] c"Unable to create dir '/tmp/1/'\00"
@str.13 = [30 x i8] c"Unable to create dir '/tmp/1'\00"
@str.14 = [28 x i8] c"Unable to create dir '/tmp'\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @S_IRWXG
%4 = tail call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %41
10: ; preds = %6, %2
%11 = load i32, i32* @S_IRWXG
%12 = tail call i64 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @EEXIST
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %41
18: ; preds = %14, %10
%19 = load i32, i32* @S_IRWXG
%20 = tail call i64 @mkdir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @EEXIST
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22, %18
%27 = tail call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %41, label %29
29: ; preds = %26, %32
%30 = tail call %struct.dirent* @readdir(i32* %27)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i64 0, i32 0
%34 = load i8*, i8** %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %33
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %41, label %29
39: ; preds = %29
%40 = tail call i32 @closedir(i32* %27)
br label %41
41: ; preds = %32, %26, %22, %14, %6, %39
%42 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0), %39 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.14, i64 0, i64 0), %6 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @str.13, i64 0, i64 0), %14 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str.12, i64 0, i64 0), %22 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0), %26 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0), %32 ]
%43 = phi i32 [ 0, %39 ], [ -1, %6 ], [ -1, %14 ], [ -1, %22 ], [ -2, %26 ], [ -3, %32 ]
%44 = tail call i32 @puts(i8* dereferenceable(1) %42)
ret i32 %43
}