#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__ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ perror(char *);
int wait(int *);
void make_dir(char dname[]) {
  int pid1, pid2, status;
  pid1 = fork();
  if (pid1 < 0)
    perror("mkdir_fork");
  else if (pid1 == 0)
    if (execlp("mkdir", "mkdir", dname, NULL) < 0)
      perror("mkdir_exec");
    else {
      pid2 = wait(&status);
      if (pid2 < 0)
        perror("mkdir_wait");
    }
}


x86 assembly (clang, -O0):
<make_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1171 <make_dir+0x31>
lea    0xe99(%rip),%rdi
call   1030 <perror@plt>
jmp    11de <make_dir+0x9e>
cmpl   $0x0,-0xc(%rbp)
jne    11d9 <make_dir+0x99>
mov    -0x8(%rbp),%rdx
lea    0xe85(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1040 <execlp@plt>
cmp    $0x0,%rax
jge    11ad <make_dir+0x6d>
lea    0xe6e(%rip),%rdi
call   1030 <perror@plt>
jmp    11d4 <make_dir+0x94>
lea    -0x14(%rbp),%rdi
call   1050 <wait@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11cf <make_dir+0x8f>
lea    0xe52(%rip),%rdi
call   1030 <perror@plt>
jmp    11d4 <make_dir+0x94>
jmp    11d9 <make_dir+0x99>
jmp    11de <make_dir+0x9e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
js     1182 <make_dir+0x42>
jne    117c <make_dir+0x3c>
lea    0xeaf(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <execlp@plt>
test   %rax,%rax
js     118b <make_dir+0x4b>
lea    0xc(%rsp),%rdi
call   1050 <wait@plt>
test   %eax,%eax
js     119c <make_dir+0x5c>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe77(%rip),%rdi
jmp    1192 <make_dir+0x52>
lea    0xe7f(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <perror@plt>
lea    0xe79(%rip),%rdi
call   1030 <perror@plt>
jmp    117c <make_dir+0x3c>

LLVM IR (-O0):
@.str = [11 x i8] c"mkdir_fork\00"
@.str.1 = [6 x i8] c"mkdir\00"
@.str.2 = [11 x i8] c"mkdir_exec\00"
@.str.3 = [11 x i8] c"mkdir_wait\00"
define void @make_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 (...) @fork()
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %29
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = call i64 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %27
20: ; preds = %14
%21 = call i32 @wait(i32* %5)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
br label %27
27: ; preds = %26, %18
br label %28
28: ; preds = %27, %11
br label %29
29: ; preds = %28, %9
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"mkdir_fork\00"
@.str.1 = [6 x i8] c"mkdir\00"
@.str.2 = [11 x i8] c"mkdir_exec\00"
@.str.3 = [11 x i8] c"mkdir_wait\00"
define void @make_dir(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %20
10: ; preds = %8
%11 = tail call i64 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %20
15: ; preds = %10
%16 = call i32 @wait(i32* %2)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %8, %15, %18, %13, %6
ret void
}