#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 getpid();
int getppid();
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(PID=%d), cujo pai tem PID=%d\n",
           getpid(), getppid());
    for (;;)
      ;
  } else {
    wait(NULL);
    printf("Processo-Filho finalizou\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    118f <main+0x3f>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <main+0x96>
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <main+0x73>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11be <main+0x6e>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11df <main+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     1181 <main+0x21>
je     1196 <main+0x36>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xebd(%rip),%rdi
jmp    118d <main+0x2d>
mov    $0x1,%ebx
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe53(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
nopl   0x0(%rax,%rax,1)
jmp    11c0 <main+0x60>

LLVM IR (-O0):
@.str = [24 x i8] c"Erro ao criar processo\0A\00"
@.str.1 = [60 x i8] c"Esta \C3\A9 a execu\C3\A7\C3\A3o do filho(PID=%d), cujo pai tem PID=%d\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 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %21
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 (...) @getppid()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
br label %15
15: ; preds = %15, %11
br label %15
16: ; preds = %8
%17 = call i32 @wait(i32* null)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %16
br label %20
20: ; preds = %19
store i32 0, i32* %1
br label %21
21: ; preds = %20, %6
%22 = load i32, i32* %1
ret i32 %22
}

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