#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 WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ printf(char *, ...);
int spawn(char *, char **);
int /*<<< orphan*/ wait(int *);
int main() {
  int child_status;
  char *arg_list[] = {"ls", "-l", "/", NULL};
  int ret = spawn("ls", arg_list);
  wait(&child_status);
  if (WIFEXITED(child_status)) {
    printf("the child process exited normally, with exit code %d\n",
           WEXITSTATUS(child_status));
  } else {
    printf("the child process exited abnormally\n");
  }
  printf("done with main program, ret = %d\n", ret);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c9a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c97(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c94(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c91(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <spawn@plt>
mov    %eax,-0x34(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x8(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11d6 <main+0x86>
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e4 <main+0x94>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0x2ca4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c88(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe7c(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <spawn@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11c3 <main+0x63>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe50(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cf <main+0x6f>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@.str.2 = [2 x i8] c"/\00"
@__const.main.arg_list = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [54 x i8] c"the child process exited normally, with exit code %d\0A\00"
@.str.4 = [37 x i8] c"the child process exited abnormally\0A\00"
@.str.5 = [34 x i8] c"done with main program, ret = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8*]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [4 x i8*]* %3 to i8*
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%7 = call i32 @spawn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6)
store i32 %7, i32* %4
%8 = call i32 @wait(i32* %2)
%9 = load i32, i32* %2
%10 = call i64 @WIFEXITED(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 @WEXITSTATUS(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@.str.2 = [2 x i8] c"/\00"
@__const.main.arg_list = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [54 x i8] c"the child process exited normally, with exit code %d\0A\00"
@.str.5 = [34 x i8] c"done with main program, ret = %d\0A\00"
@str = [36 x i8] c"the child process exited abnormally\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8*]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [4 x i8*]* %2 to i8*
%5 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%6 = call i32 @spawn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5)
%7 = call i32 @wait(i32* %1)
%8 = load i32, i32* %1
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %0
%12 = load i32, i32* %1
%13 = call i32 @WEXITSTATUS(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %17
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %6)
ret i32 0
}