#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 /*<<< orphan*/ spawn(char *, char **);
int /*<<< orphan*/ wait(int *);
int main() {
  int child_status;
  char *arg_list[] = {"ls", "-l", "/", NULL};
  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 the main program.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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>
lea    -0x8(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x8(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11d3 <main+0x83>
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e1 <main+0x91>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
movaps 0x2ca5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c89(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe7d(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <spawn@plt>
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe53(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cc <main+0x6c>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
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 = [38 x i8] c"The child process exited abnormally.\0A\00"
@.str.5 = [29 x i8] c"done with the main program.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8*]
store i32 0, i32* %1
%4 = bitcast [4 x i8*]* %3 to i8*
%5 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, 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* %2)
%8 = load i32, i32* %2
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @WEXITSTATUS(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* 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 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
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 = [37 x i8] c"The child process exited abnormally.\00"
@str.6 = [28 x i8] c"done with the main program.\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 ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
ret i32 0
}