#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 int pid_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ clearenv();
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ printf(char *);
int vfork();
int wait(int *);
int main(void) {
  pid_t pid;
  int status, wpid;
  char *argv[] = {
      "/bin/ls",
      "-laF",
      NULL,
  };
  clearenv();
  if ((pid = vfork()) == 0) {
    printf("Hi.  I'm the child process...\n");
    execvp(argv[0], argv);
    _exit(0);
  }
  printf("Hello.  I'm the parent process.\n");
  while (1) {
    wpid = wait(&status);
    if (wpid > 0 && wpid != pid) {
      continue;
    }
    if (wpid == pid)
      break;
  }
  printf("Child process exited.\nGoodbye.\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c8a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c87(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c84(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <clearenv@plt>
call   1060 <vfork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    11c8 <main+0x68>
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <execvp@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1080 <wait@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11fb <main+0x9b>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11fb <main+0x9b>
jmp    11d4 <main+0x74>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    120c <main+0xac>
jmp    1211 <main+0xb1>
jmp    11d4 <main+0x74>
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2ca2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c86(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1050 <clearenv@plt>
call   1060 <vfork@plt>
test   %eax,%eax
je     11ea <main+0x8a>
mov    %eax,%ebx
lea    0xe75(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <wait@plt>
test   %eax,%eax
setle  %cl
cmp    %ebx,%eax
sete   %dl
or     %cl,%dl
cmp    $0x1,%dl
jne    11b0 <main+0x50>
cmp    %ebx,%eax
jne    11b0 <main+0x50>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe03(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <execvp@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/ls\00"
@.str.1 = [5 x i8] c"-laF\00"
@__const.main.argv = [3 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [31 x i8] c"Hi. I'm the child process...\0A\00"
@.str.3 = [33 x i8] c"Hello. I'm the parent process.\0A\00"
@.str.4 = [32 x i8] c"Child process exited.\0AGoodbye.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i8*]
store i32 0, i32* %1
%6 = bitcast [3 x i8*]* %5 to i8*
%7 = call i32 (...) @clearenv()
%8 = call i32 @vfork()
store i32 %8, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%13 = load i8*, i8** %12
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%15 = call i32 @execvp(i8* %13, i8** %14)
%16 = call i32 @_exit(i32 0)
unreachable
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %27, %33
%20 = call i32 @wait(i32* %3)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %19
28: ; preds = %23, %19
%29 = load i32, i32* %4
%30 = load i32, i32* %2
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28
br label %34
33: ; preds = %28
br label %19
34: ; preds = %32
%35 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/ls\00"
@.str.1 = [5 x i8] c"-laF\00"
@__const.main.argv = [3 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* null]
@EXIT_SUCCESS = global i32 0
@str = [32 x i8] c"Hello. I'm the parent process.\00"
@str.5 = [31 x i8] c"Child process exited.\0AGoodbye.\00"
@str.6 = [30 x i8] c"Hi. I'm the child process...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8*]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [3 x i8*]* %2 to i8*
%5 = call i32 (...) @clearenv()
%6 = call i32 @vfork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%11 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %10)
%12 = call i32 @_exit(i32 0)
unreachable
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %15, %13
%16 = call i32 @wait(i32* %1)
%17 = icmp slt i32 %16, 1
%18 = icmp eq i32 %16, %6
%19 = select i1 %17, i1 true, i1 %18
%20 = select i1 %19, i1 %18, i1 false
br i1 %20, label %21, label %15
21: ; preds = %15
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}