#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 execve(char *, char **, char **);
int fork();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[], char *envp[]) {
  int pid;
  int ret;
  pid = fork();
  if (pid) {
  } else {
    char *a = "bin/shell";
    char *const nullchar = NULL;
    char *ar[2] = {a, nullchar};
    char *const e1 = "HOME=/Users/kavana";
    char *const e2 = "LIB=/lib";
    char *const e3 = "PATH=/bin";
    char *er[] = {e1, e2, e3, nullchar};
    ret = execve(a, ar, er);
    printf("%d\n", ret);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1166 <main+0x36>
jmp    11f9 <main+0xc9>
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c4f(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0x2c4c(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0x2c49(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c46(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1040 <execve@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jne    1186 <main+0x56>
lea    0xeba(%rip),%rdi
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
movaps 0x2cb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c9a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
call   1040 <execve@plt>
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"bin/shell\00"
@.str.1 = [19 x i8] c"HOME=/Users/kavana\00"
@.str.2 = [9 x i8] c"LIB=/lib\00"
@.str.3 = [10 x i8] c"PATH=/bin\00"
@__const.main.er = [4 x i8*] [i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca [2 x i8*]
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca [4 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%17 = call i32 (...) @fork()
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %3
br label %32
21: ; preds = %3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %10
store i8* null, i8** %11
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 0
%23 = load i8*, i8** %10
store i8* %23, i8** %22
%24 = getelementptr inbounds i8*, i8** %22, i64 1
store i8* null, i8** %24
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %15
%25 = bitcast [4 x i8*]* %16 to i8*
%26 = load i8*, i8** %10
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 0
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %16, i64 0, i64 0
%29 = call i32 @execve(i8* %26, i8** %27, i8** %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %21, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"bin/shell\00"
@.str.1 = [19 x i8] c"HOME=/Users/kavana\00"
@.str.2 = [9 x i8] c"LIB=/lib\00"
@.str.3 = [10 x i8] c"PATH=/bin\00"
@__const.main.er = [4 x i8*] [i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [2 x i8*]
%5 = alloca [4 x i8*]
%6 = tail call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = bitcast [2 x i8*]* %4 to i8*
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 1
store i8* null, i8** %11
%12 = bitcast [4 x i8*]* %5 to i8*
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
%14 = call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %10, i8** %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %3, %8
ret i32 0
}