#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 /*<<< orphan*/ printf(char *);
int vfork();
int main(int argc, char **argv) {
  char *args[3];
  args[0] = "/bin/echo";
  args[1] = "Child done.";
  args[2] = NULL;
  char *env[1];
  env[0] = NULL;
  printf("About to fork...\n");
  int pid = vfork();
  if (pid == 0) {
    execve(args[0], args, env);
  } else {
    printf("Parent done.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
call   1050 <vfork@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    11a0 <main+0x70>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <execve@plt>
jmp    11ac <main+0x7c>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xec5(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xec3(%rip),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
call   1050 <vfork@plt>
test   %eax,%eax
je     1181 <main+0x51>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
jmp    1197 <main+0x67>
lea    0xe78(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <execve@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/echo\00"
@.str.1 = [12 x i8] c"Child done.\00"
@str = [17 x i8] c"About to fork...\00"
@str.4 = [13 x i8] c"Parent done.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8*]
%4 = alloca [1 x i8*]
%5 = bitcast [3 x i8*]* %3 to i8*
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %8
%9 = bitcast [1 x i8*]* %4 to i8*
%10 = getelementptr inbounds [1 x i8*], [1 x i8*]* %4, i64 0, i64 0
store i8* null, i8** %10
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%12 = call i32 @vfork()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6, i8** %10)
br label %18
16: ; preds = %2
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
ret i32 0
}