#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*/ execve(char *, char **, char **);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  printf("In init\n");
  char *arg_v[] = {"bin/hello1", NULL};
  char *env_p[] = {"PATH=/rootfs/bin", "CWD=/rootfs", NULL};
  int pid = fork();
  if (pid == 0) {
    execve("bin/hello1", arg_v, env_p);
  } else {
    waitpid(pid, 0, 0);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2c83(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c7d(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c7a(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c77(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    11ca <main+0x8a>
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    0xe49(%rip),%rdi
call   1040 <execve@plt>
jmp    11d6 <main+0x96>
mov    -0x54(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <waitpid@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
movaps 0x2c99(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2cad(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2c91(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     118b <main+0x4b>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
jmp    119f <main+0x5f>
lea    0xe6e(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <execve@plt>
mov    $0x1,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"In init\0A\00"
@.str.1 = [11 x i8] c"bin/hello1\00"
@__const.main.arg_v = [2 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [17 x i8] c"PATH=/rootfs/bin\00"
@.str.3 = [12 x i8] c"CWD=/rootfs\00"
@__const.main.env_p = [3 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i8* null]
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [2 x i8*]
%9 = alloca [3 x i8*]
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = bitcast [2 x i8*]* %8 to i8*
%13 = bitcast [3 x i8*]* %9 to i8*
%14 = call i32 (...) @fork()
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
%20 = call i32 @execve(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %18, i8** %19)
br label %24
21: ; preds = %3
%22 = load i32, i32* %10
%23 = call i32 @waitpid(i32 %22, i32 0, i32 0)
br label %24
24: ; preds = %21, %17
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"bin/hello1\00"
@__const.main.arg_v = [2 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [17 x i8] c"PATH=/rootfs/bin\00"
@.str.3 = [12 x i8] c"CWD=/rootfs\00"
@__const.main.env_p = [3 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i8* null]
@str = [8 x i8] c"In init\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [2 x i8*]
%5 = alloca [3 x i8*]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%7 = bitcast [2 x i8*]* %4 to i8*
%8 = bitcast [3 x i8*]* %5 to i8*
%9 = tail call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%14 = call i32 @execve(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %12, i8** %13)
br label %17
15: ; preds = %3
%16 = tail call i32 @waitpid(i32 %9, i32 0, i32 0)
br label %17
17: ; preds = %15, %11
ret i32 1
}