#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 */
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");
  } 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   1050 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    116d <main+0x3d>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11aa <main+0x7a>
cmpq   $0x0,-0x10(%rbp)
jne    1189 <main+0x59>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
jmp    119e <main+0x6e>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <wait@plt>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
jmp    11a3 <main+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
js     1153 <main+0x23>
je     1161 <main+0x31>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <wait@plt>
lea    0xeaf(%rip),%rdi
jmp    1168 <main+0x38>
mov    $0x1,%ebx
lea    0xed8(%rip),%rdi
jmp    1168 <main+0x38>
lea    0xeb1(%rip),%rdi
call   1030 <puts@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 = [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 %18
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %16
13: ; preds = %8
%14 = call i32 @wait(i32* null)
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %13, %11
br label %17
17: ; preds = %16
store i32 0, i32* %1
br label %18
18: ; preds = %17, %6
%19 = load i32, i32* %1
ret i32 %19
}

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