#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 WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ nice(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
int main(void) {
  pid_t child_pid;
  int child_status;
  char *arg_list[] = {"ls", "-l", NULL};
  printf("\n*** Main process started ***\n\n");
  child_pid = fork();
  if (child_pid > 0) {
    printf("Process ID (main process): %d\n", getpid());
    printf("Parent Process ID (main process): %d\n", getppid());
    wait(&child_status);
    if (WIFEXITED(child_status)) {
      printf("The child process exited normally, with exit code: %d",
             WEXITSTATUS(child_status));
    } else {
      printf("The child process exit abnormally");
    }
  } else {
    nice(1);
    printf("Process ID (child process): %d\n", getpid());
    printf("Parent Process ID (child process): %d\n", getppid());
    execvp("ls", arg_list);
  }
  printf("\n\n*** Main process finished ***\n\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c4a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c47(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c44(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    126d <main+0xcd>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
call   10b0 <wait@plt>
mov    -0x14(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     125a <main+0xba>
mov    -0x14(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1268 <main+0xc8>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b5 <main+0x115>
mov    $0x1,%edi
call   1050 <nice@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xd50(%rip),%rdi
call   1070 <execvp@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0x2c55(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c39(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
jle    123a <main+0x8a>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <getppid@plt>
lea    0xdfd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
mov    0xc(%rsp),%edi
call   1090 <WIFEXITED@plt>
test   %rax,%rax
jne    1285 <main+0xd5>
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    129e <main+0xee>
mov    $0x1,%edi
call   1060 <nice@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe39(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <getppid@plt>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd87(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <execvp@plt>
jmp    129e <main+0xee>
mov    0xc(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
lea    0xd97(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@__const.main.arg_list = [3 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* null]
@.str.2 = [32 x i8] c"\0A*** Main process started ***\0A\0A\00"
@.str.3 = [31 x i8] c"Process ID (main process): %d\0A\00"
@.str.4 = [38 x i8] c"Parent Process ID (main process): %d\0A\00"
@.str.5 = [54 x i8] c"The child process exited normally, with exit code: %d\00"
@.str.6 = [34 x i8] c"The child process exit abnormally\00"
@.str.7 = [32 x i8] c"Process ID (child process): %d\0A\00"
@.str.8 = [39 x i8] c"Parent Process ID (child process): %d\0A\00"
@.str.9 = [34 x i8] c"\0A\0A*** Main process finished ***\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca [3 x i8*]
store i32 0, i32* %1
%5 = bitcast [3 x i8*]* %4 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%7 = call i64 (...) @fork()
store i64 %7, i64* %2
%8 = load i64, i64* %2
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %0
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i32 (...) @getppid()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = call i32 @wait(i32* %3)
%16 = load i32, i32* %3
%17 = call i64 @WIFEXITED(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* %3
%21 = call i32 @WEXITSTATUS(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %10
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
br label %34
26: ; preds = %0
%27 = call i32 @nice(i32 1)
%28 = call i32 (...) @getpid()
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %28)
%30 = call i32 (...) @getppid()
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%33 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %32)
br label %34
34: ; preds = %26, %25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@__const.main.arg_list = [3 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* null]
@.str.3 = [31 x i8] c"Process ID (main process): %d\0A\00"
@.str.4 = [38 x i8] c"Parent Process ID (main process): %d\0A\00"
@.str.5 = [54 x i8] c"The child process exited normally, with exit code: %d\00"
@.str.6 = [34 x i8] c"The child process exit abnormally\00"
@.str.7 = [32 x i8] c"Process ID (child process): %d\0A\00"
@.str.8 = [39 x i8] c"Parent Process ID (child process): %d\0A\00"
@str = [31 x i8] c"\0A*** Main process started ***\0A\00"
@str.10 = [33 x i8] c"\0A\0A*** Main process finished ***\0A\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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = tail call i64 (...) @fork()
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %0
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = tail call i32 (...) @getppid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = call i32 @wait(i32* %1)
%14 = load i32, i32* %1
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %8
%18 = load i32, i32* %1
%19 = call i32 @WEXITSTATUS(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %31
21: ; preds = %8
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %31
23: ; preds = %0
%24 = tail call i32 @nice(i32 1)
%25 = tail call i32 (...) @getpid()
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %25)
%27 = tail call i32 (...) @getppid()
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%30 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %29)
br label %31
31: ; preds = %17, %21, %23
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
}