#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*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getenv(char *);
int getpid();
int main_linux(char *, int);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char path[256];
  if (argv[1] == NULL) {
    if (!getenv("MMM_PATH")) {
      sprintf(path, "/tmp/mmm-%i", getpid());
      setenv("MMM_PATH", path, 1);
      mkdir(path, 0777);
    }
    return main_linux(path, 0);
  }
  if (argv[1][0] == '-' && argv[1][1] == 'p' && argv[2]) {
    return main_linux(argv[2], 1);
  }
  if (!getenv("MMM_PATH")) {
    sprintf(path, "/tmp/mmm-%i", getpid());
    setenv("MMM_PATH", path, 1);
    mkdir(path, 0777);
  }
  if (argv[1])
    switch (fork()) {
    case 0:
      return main_linux(path, 1);
    case -1:
      fprintf(stderr, "fork failed\n");
      return 0;
    }
  execvp(argv[1], argv + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1236 <main+0xa6>
lea    0xe41(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    1220 <main+0x90>
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x118(%rbp),%rdi
mov    %eax,%edx
lea    0xe17(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    -0x110(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
call   1080 <main_linux@plt>
mov    %eax,-0x4(%rbp)
jmp    138a <main+0x1fa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1288 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x70,%eax
jne    1288 <main+0xf8>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1288 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1,%esi
call   1080 <main_linux@plt>
mov    %eax,-0x4(%rbp)
jmp    138a <main+0x1fa>
lea    0xd71(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    12f0 <main+0x160>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x120(%rbp),%rdi
mov    %eax,%edx
lea    0xd47(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0xd2b(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    -0x110(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     136e <main+0x1de>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x124(%rbp)
sub    $0xffffffff,%eax
je     1348 <main+0x1b8>
jmp    131c <main+0x18c>
mov    -0x124(%rbp),%eax
test   %eax,%eax
jne    1369 <main+0x1d9>
jmp    132f <main+0x19f>
lea    -0x110(%rbp),%rdi
mov    $0x1,%esi
call   1080 <main_linux@plt>
mov    %eax,-0x4(%rbp)
jmp    138a <main+0x1fa>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xcbd(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <main+0x1fa>
jmp    136e <main+0x1de>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1090 <execvp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x8(%rsi),%rax
test   %rax,%rax
je     124d <main+0xbd>
mov    %rsi,%rbx
cmpb   $0x2d,(%rax)
jne    11d4 <main+0x44>
cmpb   $0x70,0x1(%rax)
jne    11d4 <main+0x44>
mov    0x10(%rbx),%rdi
test   %rdi,%rdi
je     11d4 <main+0x44>
mov    $0x1,%esi
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <main_linux@plt>
add    $0x8,%rbx
lea    0xe21(%rip),%rdi
call   1030 <getenv@plt>
test   %eax,%eax
jne    1231 <main+0xa1>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe10(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
lea    0xdf3(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbp,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmpq   $0x0,(%rbx)
je     12c1 <main+0x131>
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     12a7 <main+0x117>
test   %eax,%eax
jne    12be <main+0x12e>
mov    %rsp,%rdi
mov    $0x1,%esi
jmp    129e <main+0x10e>
lea    0xdac(%rip),%rdi
call   1030 <getenv@plt>
test   %eax,%eax
jne    1299 <main+0x109>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xd9e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
lea    0xd81(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1080 <main_linux@plt>
mov    %eax,%ebp
jmp    12ce <main+0x13e>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12ce <main+0x13e>
mov    (%rbx),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <execvp@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"MMM_PATH\00"
@.str.1 = [12 x i8] c"/tmp/mmm-%i\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"fork failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = call i32 @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 (...) @getpid()
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %18, i32 1)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i32 @mkdir(i8* %20, i32 511)
br label %22
22: ; preds = %14, %11
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = call i32 @main_linux(i8* %23, i32 0)
store i32 %24, i32* %3
br label %83
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br i1 %32, label %33, label %51
33: ; preds = %25
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 112
br i1 %40, label %41, label %51
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @main_linux(i8* %49, i32 1)
store i32 %50, i32* %3
br label %83
51: ; preds = %41, %33, %25
%52 = call i32 @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%53 = icmp ne i32 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %51
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%56 = call i32 (...) @getpid()
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%59 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %58, i32 1)
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%61 = call i32 @mkdir(i8* %60, i32 511)
br label %62
62: ; preds = %54, %51
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %76
67: ; preds = %62
%68 = call i32 (...) @fork()
switch i32 %68, label %75 [
i32 0, label %69
i32 -1, label %72
]
69: ; preds = %67
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%71 = call i32 @main_linux(i8* %70, i32 1)
store i32 %71, i32* %3
br label %83
72: ; preds = %67
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %83
75: ; preds = %67
br label %76
76: ; preds = %75, %62
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = call i32 @execvp(i8* %79, i8** %81)
store i32 0, i32* %3
br label %83
83: ; preds = %76, %72, %69, %46, %22
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [9 x i8] c"MMM_PATH\00"
@.str.1 = [12 x i8] c"/tmp/mmm-%i\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"fork failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = tail call i32 @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = tail call i32 (...) @getpid()
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %4, i32 1)
%15 = call i32 @mkdir(i8* %4, i32 511)
br label %16
16: ; preds = %11, %8
%17 = call i32 @main_linux(i8* %4, i32 0)
br label %53
18: ; preds = %2
%19 = load i8, i8* %6
%20 = icmp eq i8 %19, 45
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %6, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 112
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = tail call i32 @main_linux(i8* %27, i32 1)
br label %53
31: ; preds = %25, %21, %18
%32 = tail call i32 @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = tail call i32 (...) @getpid()
%36 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %4, i32 1)
%38 = call i32 @mkdir(i8* %4, i32 511)
%39 = load i8*, i8** %5
%40 = icmp eq i8* %39, null
br i1 %40, label %50, label %41
41: ; preds = %31, %34
%42 = call i32 (...) @fork()
switch i32 %42, label %43 [
i32 0, label %45
i32 -1, label %47
]
43: ; preds = %41
%44 = load i8*, i8** %5
br label %50
45: ; preds = %41
%46 = call i32 @main_linux(i8* %4, i32 1)
br label %53
47: ; preds = %41
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %53
50: ; preds = %43, %34
%51 = phi i8* [ %44, %43 ], [ null, %34 ]
%52 = call i32 @execvp(i8* %51, i8** %5)
br label %53
53: ; preds = %50, %47, %45, %29, %16
%54 = phi i32 [ %17, %16 ], [ %30, %29 ], [ 0, %50 ], [ 0, %47 ], [ %46, %45 ]
ret i32 %54
}