#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 WEXITSTATUS(int);
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t pid;
  int status = -1;
  if ((pid = fork()) != 0) {
    printf("Processo pai esperando filho PID=%d\n", pid);
    wait(&status);
    printf("Filho terminou com o status: %d\n", WEXITSTATUS(status));
    exit(0);
  } else {
    printf("Processo filho executando...\n");
    execl("/bin/ls", "ls", "-la", NULL);
    printf("Filho terminando a execução...\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     11bb <main+0x5b>
mov    -0x4(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
lea    0xe92(%rip),%rsi
lea    0xe8e(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execl@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    11bc <main+0x4c>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
lea    0xead(%rip),%rsi
lea    0xea9(%rip),%rdx
xor    %ecx,%ecx
call   1070 <execl@plt>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xe3f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Processo pai esperando filho PID=%d\0A\00"
@.str.1 = [33 x i8] c"Filho terminou com o status: %d\0A\00"
@.str.2 = [30 x i8] c"Processo filho executando...\0A\00"
@.str.3 = [8 x i8] c"/bin/ls\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [4 x i8] c"-la\00"
@.str.6 = [34 x i8] c"Filho terminando a execu\C3\A7\C3\A3o...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 -1, i32* %2
%3 = call i32 (...) @fork()
store i32 %3, i32* %1
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %0
%6 = load i32, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @wait(i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @WEXITSTATUS(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* null)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %17
17: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Processo pai esperando filho PID=%d\0A\00"
@.str.1 = [33 x i8] c"Filho terminou com o status: %d\0A\00"
@.str.3 = [8 x i8] c"/bin/ls\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [4 x i8] c"-la\00"
@str = [29 x i8] c"Processo filho executando...\00"
@str.7 = [33 x i8] c"Filho terminando a execu\C3\A7\C3\A3o...\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = call i32 @wait(i32* %1)
%8 = load i32, i32* %1
%9 = call i32 @WEXITSTATUS(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* null)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}