#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 /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int pid;
  pid = fork();
  if (pid < 0) {
    printf("Processo fork falhou");
    system("pause");
    exit(-1);
  } else if (pid == 0) {
    execlp("/bin/ls", "ls", NULL);
  } else {
    wait(NULL);
    printf("filho Completo");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    119e <main+0x3e>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
call   1030 <system@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11c4 <main+0x64>
lea    0xe6c(%rip),%rdi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
jmp    11e0 <main+0x80>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11e5 <main+0x85>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
js     1187 <main+0x27>
jne    11a9 <main+0x49>
lea    0xea6(%rip),%rdi
lea    0xea4(%rip),%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
call   1030 <system@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Processo fork falhou\00"
@.str.1 = [6 x i8] c"pause\00"
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [15 x i8] c"filho Completo\00"
define i32 @main() {
%1 = alloca i32
%2 = call i32 (...) @fork()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %18
14: ; preds = %9
%15 = call i32 @wait(i32* null)
%16 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %12
br label %19
19: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Processo fork falhou\00"
@.str.1 = [6 x i8] c"pause\00"
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [15 x i8] c"filho Completo\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = icmp eq i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* null)
ret i32 0
11: ; preds = %7
%12 = tail call i32 @wait(i32* null)
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
}