#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main() {
  int pid;
  printf("Eu sou o pai %d e eu vou criar um filho \n", getpid());
  pid = fork();
  if (pid == -1) {
    perror("impossivel de criar um filho\n");
  } else if (pid == 0) {
    printf("\tOi, eu sou o processo %d, o filho\n", getpid());
    printf("\tO dia esta otimo hoje, nao acha?\n");
    printf("\tBom, desse jeito vou acabar me instalando para sempre\n");
    printf("\tOu melhor, assim espero!\n");
    for (;;)
      ;
  } else {
    sleep(1);
    printf("As luzes comecaram a se apagar para mim, %d\n", getpid());
    printf("Minha hora chegou : adeus, %d, meu filho\n", pid);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ab <main+0x4b>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
jmp    1232 <main+0xd2>
cmpl   $0x0,-0x8(%rbp)
jne    11fb <main+0x9b>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <main+0x96>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1232 <main+0xd2>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    11d2 <main+0x62>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xea7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
lea    0xf53(%rip),%rdi
call   1030 <puts@plt>
xchg   %ax,%ax
jmp    11d0 <main+0x60>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11ec <main+0x7c>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe68(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Eu sou o pai %d e eu vou criar um filho \0A\00"
@.str.1 = [30 x i8] c"impossivel de criar um filho\0A\00"
@.str.2 = [36 x i8] c"\09Oi, eu sou o processo %d, o filho\0A\00"
@.str.3 = [35 x i8] c"\09O dia esta otimo hoje, nao acha?\0A\00"
@.str.4 = [56 x i8] c"\09Bom, desse jeito vou acabar me instalando para sempre\0A\00"
@.str.5 = [27 x i8] c"\09Ou melhor, assim espero!\0A\00"
@.str.6 = [45 x i8] c"As luzes comecaram a se apagar para mim, %d\0A\00"
@.str.7 = [42 x i8] c"Minha hora chegou : adeus, %d, meu filho\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @getpid()
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %27
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = call i32 (...) @getpid()
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %19
19: ; preds = %19, %13
br label %19
20: ; preds = %10
%21 = call i32 @sleep(i32 1)
%22 = call i32 (...) @getpid()
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %20
br label %27
27: ; preds = %26, %8
%28 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [42 x i8] c"Eu sou o pai %d e eu vou criar um filho \0A\00"
@.str.1 = [30 x i8] c"impossivel de criar um filho\0A\00"
@.str.2 = [36 x i8] c"\09Oi, eu sou o processo %d, o filho\0A\00"
@.str.6 = [45 x i8] c"As luzes comecaram a se apagar para mim, %d\0A\00"
@.str.7 = [42 x i8] c"Minha hora chegou : adeus, %d, meu filho\0A\00"
@str = [34 x i8] c"\09O dia esta otimo hoje, nao acha?\00"
@str.8 = [55 x i8] c"\09Bom, desse jeito vou acabar me instalando para sempre\00"
@str.9 = [26 x i8] c"\09Ou melhor, assim espero!\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @fork()
switch i32 %3, label %13 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %18
6: ; preds = %0
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
br label %12
12: ; preds = %12, %6
br label %12
13: ; preds = %0
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %3)
br label %18
18: ; preds = %13, %4
%19 = tail call i32 @exit(i32 0)
unreachable
}