#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*/ 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");
    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   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    117d <main+0x3d>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <main+0x98>
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <main+0x77>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    0xe9a(%rip),%rsi
lea    0xe96(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <execlp@plt>
jmp    11cc <main+0x8c>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
jmp    11d1 <main+0x91>
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   1060 <fork@plt>
test   %rax,%rax
js     1166 <main+0x26>
je     1179 <main+0x39>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <wait@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
jmp    11a3 <main+0x63>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11a3 <main+0x63>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe74(%rip),%rdi
lea    0xe72(%rip),%rsi
lea    0xe6e(%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 = [8 x i8] c"/bin/ls\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [3 x i8] c"-l\00"
@.str.5 = [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 %19
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
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 @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), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* null)
br label %17
14: ; preds = %8
%15 = call i32 @wait(i32* null)
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %17
store i32 0, i32* %1
br label %19
19: ; preds = %18, %6
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [3 x i8] c"-l\00"
@str = [25 x i8] c"Processo-Filho finalizou\00"
@str.6 = [30 x i8] c"Esta \C3\A9 a execu\C3\A7\C3\A3o do filho\00"
@str.7 = [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.7, i64 0, i64 0))
br label %13
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%9 = 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), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* null)
br label %13
10: ; preds = %5
%11 = tail call i32 @wait(i32* null)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %10, %7, %3
%14 = phi i32 [ 1, %3 ], [ 0, %7 ], [ 0, %10 ]
ret i32 %14
}