#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();
scalar_t__ getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid, pid1;
  pid = fork();
  if (pid < 0) {
    printf("Erro ao criar processo\n");
    return 1;
  } else if (pid == 0) {
    pid1 = getpid();
    printf("Filho: pid = %d\n", pid);
    printf("Filho: pid1 = %d\n", pid1);
  } else {
    pid1 = getpid();
    printf("Pai: pid = %d\n", pid);
    printf("Pai: pid1 = %d\n", pid1);
    wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    117f <main+0x3f>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <main+0xc2>
cmpq   $0x0,-0x10(%rbp)
jne    11be <main+0x7e>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <main+0xb6>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
jmp    11fb <main+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11a1 <main+0x51>
mov    %rax,%rbx
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11b5 <main+0x65>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <wait@plt>
jmp    11d9 <main+0x89>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
jmp    11d9 <main+0x89>
lea    0xe44(%rip),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe42(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Erro ao criar processo\0A\00"
@.str.1 = [17 x i8] c"Filho: pid = %d\0A\00"
@.str.2 = [18 x i8] c"Filho: pid1 = %d\0A\00"
@.str.3 = [15 x i8] c"Pai: pid = %d\0A\00"
@.str.4 = [16 x i8] c"Pai: pid1 = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = 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 %27
9: ; preds = %0
%10 = load i64, i64* %2
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i64 (...) @getpid()
store i64 %13, i64* %3
%14 = load i64, i64* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = load i64, i64* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %16)
br label %25
18: ; preds = %9
%19 = call i64 (...) @getpid()
store i64 %19, i64* %3
%20 = load i64, i64* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %20)
%22 = load i64, i64* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 %22)
%24 = call i32 @wait(i32* null)
br label %25
25: ; preds = %18, %12
br label %26
26: ; preds = %25
store i32 0, i32* %1
br label %27
27: ; preds = %26, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Filho: pid = %d\0A\00"
@.str.2 = [18 x i8] c"Filho: pid1 = %d\0A\00"
@.str.3 = [15 x i8] c"Pai: pid = %d\0A\00"
@.str.4 = [16 x i8] c"Pai: pid1 = %d\0A\00"
@str = [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, i64 0, i64 0))
br label %15
5: ; preds = %0
%6 = icmp eq i64 %1, 0
%7 = tail call i64 (...) @getpid()
br i1 %6, label %8, label %11
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %7)
br label %15
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %1)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 %7)
%14 = tail call i32 @wait(i32* null)
br label %15
15: ; preds = %11, %8, %3
%16 = phi i32 [ 1, %3 ], [ 0, %8 ], [ 0, %11 ]
ret i32 %16
}