#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*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main() {
  pid_t pid = fork();
  int status;
  if (pid == 0) {
    puts("child process");
    char *argv_list[] = {"ls", "-lart", "/home", NULL};
    execv("/bin/ls", argv_list);
    puts("ls before");
    exit(0);
  } else {
    printf("parent process child pid is %d\n", pid);
    waitpid(pid, &status, 0);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <main+0x80>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c68(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c65(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c62(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c5f(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1070 <execv@plt>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11b6 <main+0x56>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
movaps 0x2c8c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2c70(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe7f(%rip),%rdi
mov    %rsp,%rsi
call   1070 <execv@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %rax,%rbx
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"child process\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [6 x i8] c"-lart\00"
@.str.3 = [6 x i8] c"/home\00"
@__const.main.argv_list = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [8 x i8] c"/bin/ls\00"
@.str.5 = [10 x i8] c"ls before\00"
@.str.6 = [32 x i8] c"parent process child pid is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca [4 x i8*]
store i32 0, i32* %1
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = bitcast [4 x i8*]* %4 to i8*
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%12 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %11)
%13 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %0
%16 = load i64, i64* %2
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i64 %16)
%18 = load i64, i64* %2
%19 = call i32 @waitpid(i64 %18, i32* %3, i32 0)
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"child process\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [6 x i8] c"-lart\00"
@.str.3 = [6 x i8] c"/home\00"
@__const.main.argv_list = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [8 x i8] c"/bin/ls\00"
@.str.5 = [10 x i8] c"ls before\00"
@.str.6 = [32 x i8] c"parent process child pid is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8*]
%3 = tail call i64 (...) @fork()
%4 = bitcast i32* %1 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = bitcast [4 x i8*]* %2 to i8*
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%10 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i64 %3)
%15 = call i32 @waitpid(i64 %3, i32* %1, i32 0)
%16 = call i32 @exit(i32 0)
unreachable
}