#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 */
int /*<<< orphan*/ get_path(char *, char *);
char *getenv(char *);
char *malloc(int);
scalar_t__ mkdir_one(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int mkdir_all(char *path) {
  char *tmp_dir, *tmp_path;
  tmp_dir = malloc(8 * sizeof(char));
  tmp_path = malloc(512 * sizeof(char));
  get_path(tmp_path, path);
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/usr")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/lib")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/lib64")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/bin")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/dev")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/etc")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/proc")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/var")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, "/home")) != 0)
    return 1;
  if (mkdir_one(tmp_path, strcpy(tmp_dir, getenv("HOME"))) != 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<mkdir_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <get_path@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     11c1 <mkdir_all+0x71>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     11fa <mkdir_all+0xaa>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     1233 <mkdir_all+0xe3>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     126c <mkdir_all+0x11c>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     12a5 <mkdir_all+0x155>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     12de <mkdir_all+0x18e>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd2f(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     1317 <mkdir_all+0x1c7>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xcfc(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     1350 <mkdir_all+0x200>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xcc8(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     1389 <mkdir_all+0x239>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xc91(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
cmp    $0x0,%rax
je     13d2 <mkdir_all+0x282>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <mkdir_all+0x289>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdir_all>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1060 <get_path@plt>
lea    0xe7d(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xe5b(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xe3e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xe23(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xe06(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xde9(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xdcc(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xdb4(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xd9b(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
test   %rax,%rax
jne    12d1 <mkdir_all+0x181>
lea    0xd83(%rip),%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <mkdir_one@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/usr\00"
@.str.1 = [5 x i8] c"/lib\00"
@.str.2 = [7 x i8] c"/lib64\00"
@.str.3 = [5 x i8] c"/bin\00"
@.str.4 = [5 x i8] c"/dev\00"
@.str.5 = [5 x i8] c"/etc\00"
@.str.6 = [6 x i8] c"/proc\00"
@.str.7 = [5 x i8] c"/var\00"
@.str.8 = [6 x i8] c"/home\00"
@.str.9 = [5 x i8] c"HOME\00"
define i32 @mkdir_all(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i8* @malloc(i32 8)
store i8* %6, i8** %4
%7 = call i8* @malloc(i32 512)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = load i8*, i8** %3
%10 = call i32 @get_path(i8* %8, i8* %9)
%11 = load i8*, i8** %5
%12 = load i8*, i8** %4
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i64 @mkdir_one(i8* %11, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 1, i32* %2
br label %82
17: ; preds = %1
%18 = load i8*, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i64 @mkdir_one(i8* %18, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %2
br label %82
24: ; preds = %17
%25 = load i8*, i8** %5
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = call i64 @mkdir_one(i8* %25, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 1, i32* %2
br label %82
31: ; preds = %24
%32 = load i8*, i8** %5
%33 = load i8*, i8** %4
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = call i64 @mkdir_one(i8* %32, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 1, i32* %2
br label %82
38: ; preds = %31
%39 = load i8*, i8** %5
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%42 = call i64 @mkdir_one(i8* %39, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %2
br label %82
45: ; preds = %38
%46 = load i8*, i8** %5
%47 = load i8*, i8** %4
%48 = call i32 @strcpy(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%49 = call i64 @mkdir_one(i8* %46, i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 1, i32* %2
br label %82
52: ; preds = %45
%53 = load i8*, i8** %5
%54 = load i8*, i8** %4
%55 = call i32 @strcpy(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%56 = call i64 @mkdir_one(i8* %53, i32 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 1, i32* %2
br label %82
59: ; preds = %52
%60 = load i8*, i8** %5
%61 = load i8*, i8** %4
%62 = call i32 @strcpy(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%63 = call i64 @mkdir_one(i8* %60, i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %59
store i32 1, i32* %2
br label %82
66: ; preds = %59
%67 = load i8*, i8** %5
%68 = load i8*, i8** %4
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%70 = call i64 @mkdir_one(i8* %67, i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %66
store i32 1, i32* %2
br label %82
73: ; preds = %66
%74 = load i8*, i8** %5
%75 = load i8*, i8** %4
%76 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%77 = call i32 @strcpy(i8* %75, i8* %76)
%78 = call i64 @mkdir_one(i8* %74, i32 %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %73
store i32 1, i32* %2
br label %82
81: ; preds = %73
store i32 0, i32* %2
br label %82
82: ; preds = %81, %80, %72, %65, %58, %51, %44, %37, %30, %23, %16
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
@.str = [5 x i8] c"/usr\00"
@.str.1 = [5 x i8] c"/lib\00"
@.str.2 = [7 x i8] c"/lib64\00"
@.str.3 = [5 x i8] c"/bin\00"
@.str.4 = [5 x i8] c"/dev\00"
@.str.5 = [5 x i8] c"/etc\00"
@.str.6 = [6 x i8] c"/proc\00"
@.str.7 = [5 x i8] c"/var\00"
@.str.8 = [6 x i8] c"/home\00"
@.str.9 = [5 x i8] c"HOME\00"
define i32 @mkdir_all(i8* %0) {
%2 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = tail call i32 @get_path(i8* %3, i8* %0)
%5 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @mkdir_one(i8* %3, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %1
%9 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i64 @mkdir_one(i8* %3, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %46
12: ; preds = %8
%13 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i64 @mkdir_one(i8* %3, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %46
16: ; preds = %12
%17 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i64 @mkdir_one(i8* %3, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %16
%21 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i64 @mkdir_one(i8* %3, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %46
24: ; preds = %20
%25 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%26 = tail call i64 @mkdir_one(i8* %3, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%30 = tail call i64 @mkdir_one(i8* %3, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %28
%33 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%34 = tail call i64 @mkdir_one(i8* %3, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%38 = tail call i64 @mkdir_one(i8* %3, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%42 = tail call i32 @strcpy(i8* %2, i8* %41)
%43 = tail call i64 @mkdir_one(i8* %3, i32 %42)
%44 = icmp ne i64 %43, 0
%45 = zext i1 %44 to i32
br label %46
46: ; preds = %40, %36, %32, %28, %24, %20, %16, %12, %8, %1
%47 = phi i32 [ 1, %1 ], [ 1, %8 ], [ 1, %12 ], [ 1, %16 ], [ 1, %20 ], [ 1, %24 ], [ 1, %28 ], [ 1, %32 ], [ 1, %36 ], [ %45, %40 ]
ret i32 %47
}