#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ vfork();
scalar_t__ wait(int *);
int main() {
  pid_t pid;
  int sta;
  char *arrArg[] = {"test", "A", "B", "C", NULL};
  char *arrEnv[] = {"env1=150", "env2=tom", NULL};
  pid = vfork();
  if (pid < 0) {
    printf("create process fail\n");
    exit(1);
  }
  if (pid == 0) {
    execve("./env", arrArg, arrEnv);
  } else {
    if (pid != wait(&sta)) {
      printf("wait child error\n");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xe7a(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe74(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe6b(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe62(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c4e(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c4b(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c48(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1060 <vfork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11f8 <main+0x98>
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    121c <main+0xbc>
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    0xe20(%rip),%rdi
call   1050 <execve@plt>
jmp    1258 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x14(%rbp),%rdi
call   1080 <wait@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
cmp    %rcx,%rax
je     1253 <main+0xf3>
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1258 <main+0xf8>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movq   $0x0,0x30(%rsp)
lea    0xe9b(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe94(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe8a(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe80(%rip),%rax
mov    %rax,0x28(%rsp)
mov    0x2c7b(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0x2c5f(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
js     11ed <main+0x9d>
je     11cf <main+0x7f>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rax,%rbx
je     11e5 <main+0x95>
lea    0xe56(%rip),%rdi
jmp    11f4 <main+0xa4>
lea    0xe47(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x40(%rsp),%rdx
call   1040 <execve@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"B\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [9 x i8] c"env1=150\00"
@.str.5 = [9 x i8] c"env2=tom\00"
@__const.main.arrEnv = [3 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str.6 = [21 x i8] c"create process fail\0A\00"
@.str.7 = [6 x i8] c"./env\00"
@.str.8 = [18 x i8] c"wait child error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca [5 x i8*]
%5 = alloca [3 x i8*]
store i32 0, i32* %1
%6 = bitcast [5 x i8*]* %4 to i8*
%7 = bitcast i8* %6 to [5 x i8*]*
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8** %11
%12 = bitcast [3 x i8*]* %5 to i8*
%13 = call i64 (...) @vfork()
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = load i64, i64* %2
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%25 = call i32 @execve(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %23, i8** %24)
br label %34
26: ; preds = %19
%27 = load i64, i64* %2
%28 = call i64 @wait(i32* %3)
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
br label %34
34: ; preds = %33, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"B\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [9 x i8] c"env1=150\00"
@.str.5 = [9 x i8] c"env2=tom\00"
@__const.main.arrEnv = [3 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str.7 = [6 x i8] c"./env\00"
@str = [17 x i8] c"wait child error\00"
@str.9 = [20 x i8] c"create process fail\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8*]
%3 = alloca [3 x i8*]
%4 = bitcast i32* %1 to i8*
%5 = bitcast [5 x i8*]* %2 to i8*
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 4
%7 = bitcast i8** %6 to i64*
store i64 0, i64* %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %11
%12 = bitcast [3 x i8*]* %3 to i8*
%13 = tail call i64 (...) @vfork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.9, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = icmp eq i64 %13, 0
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%22 = call i32 @execve(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %8, i8** %21)
br label %29
23: ; preds = %18
%24 = call i64 @wait(i32* %1)
%25 = icmp eq i64 %13, %24
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23, %20
ret i32 0
}