#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 /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    printf("Erro ao criar processo\n");
    return 1;
  } else if (pid == 0) {
    printf("Esta é a execução do filho\n");
    printf("Esperando....\n");
    sleep(10);
    printf("Voltou!\n");
    execlp("/bin/ls", "ls", "-l", NULL);
  } else {
    wait(NULL);
    printf("Processo-Filho finalizou\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    118d <main+0x3d>
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120a <main+0xba>
cmpq   $0x0,-0x10(%rbp)
jne    11e9 <main+0x99>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    $0xa,%edi
call   1050 <sleep@plt>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
lea    0xe82(%rip),%rdi
lea    0xe80(%rip),%rsi
lea    0xe7c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <execlp@plt>
jmp    11fe <main+0xae>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
jmp    1203 <main+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1176 <main+0x26>
je     1189 <main+0x39>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <wait@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
jmp    11d5 <main+0x85>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11d5 <main+0x85>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1050 <sleep@plt>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe42(%rip),%rdi
lea    0xe40(%rip),%rsi
lea    0xe3c(%rip),%rdx
xor    %ebx,%ebx
xor    %ecx,%ecx
call   1040 <execlp@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Erro ao criar processo\0A\00"
@.str.1 = [31 x i8] c"Esta \C3\A9 a execu\C3\A7\C3\A3o do filho\0A\00"
@.str.2 = [15 x i8] c"Esperando....\0A\00"
@.str.3 = [9 x i8] c"Voltou!\0A\00"
@.str.4 = [8 x i8] c"/bin/ls\00"
@.str.5 = [3 x i8] c"ls\00"
@.str.6 = [3 x i8] c"-l\00"
@.str.7 = [26 x i8] c"Processo-Filho finalizou\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %22
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @sleep(i32 10)
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* null)
br label %20
17: ; preds = %8
%18 = call i32 @wait(i32* null)
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %20
20: ; preds = %17, %11
br label %21
21: ; preds = %20
store i32 0, i32* %1
br label %22
22: ; preds = %21, %6
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str.4 = [8 x i8] c"/bin/ls\00"
@.str.5 = [3 x i8] c"ls\00"
@.str.6 = [3 x i8] c"-l\00"
@str = [25 x i8] c"Processo-Filho finalizou\00"
@str.8 = [30 x i8] c"Esta \C3\A9 a execu\C3\A7\C3\A3o do filho\00"
@str.9 = [14 x i8] c"Esperando....\00"
@str.10 = [8 x i8] c"Voltou!\00"
@str.11 = [23 x i8] c"Erro ao criar processo\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
br label %16
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %13
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.8, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i32 @sleep(i32 10)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%12 = tail call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* null)
br label %16
13: ; preds = %5
%14 = tail call i32 @wait(i32* null)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %13, %7, %3
%17 = phi i32 [ 1, %3 ], [ 0, %7 ], [ 0, %13 ]
ret i32 %17
}