#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*/ puts(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid;
  pid = fork();
  if (pid >= 0) {
    if (pid == 0)
      puts("Sou o filho");
    else {
      printf("Sou o papai\n");
      wait(NULL);
    }
    return 0;
  } else {
    printf("Não pode criar o rpocesso\n");
    return -1;
  }
}


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)
jl     11a2 <main+0x62>
cmpq   $0x0,-0x10(%rbp)
jne    1181 <main+0x41>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
jmp    1196 <main+0x56>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <main+0x75>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
js     1156 <main+0x26>
je     1169 <main+0x39>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <wait@plt>
jmp    1177 <main+0x47>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1177 <main+0x47>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Sou o filho\00"
@.str.1 = [13 x i8] c"Sou o papai\0A\00"
@.str.2 = [28 x i8] c"N\C3\A3o pode criar o rpocesso\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 sge i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %14
11: ; preds = %6
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @wait(i32* null)
br label %14
14: ; preds = %11, %9
store i32 0, i32* %1
br label %17
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %17
17: ; preds = %15, %14
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [12 x i8] c"Sou o filho\00"
@str = [27 x i8] c"N\C3\A3o pode criar o rpocesso\00"
@str.3 = [12 x i8] c"Sou o papai\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp sgt i64 %1, -1
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = icmp eq i64 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.3, i64 0, i64 0))
%9 = tail call i32 @wait(i32* null)
br label %12
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %5, %7, %10
%13 = phi i32 [ -1, %10 ], [ 0, %7 ], [ 0, %5 ]
ret i32 %13
}