#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*/ getchar();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *);
int main(int argc, char const *argv[]) {
  char name[120];
  pid_t pid_perdido = fork();
  if (pid_perdido == 0) {
    getchar();
    printf("filhoPerdido %d %d\n", getpid(), getppid());
    sprintf(name, "filhoPerdidoFim");
  } else if (pid_perdido > 0) {
    pid_t pid_nao_perdido = fork();
    if (pid_nao_perdido == 0) {
      printf("filhoNaoPerdido %d %d\n", getpid(), getppid());
      sprintf(name, "filhoNaoPerdidoFim");
    } else if (pid_nao_perdido > 0) {
      printf("paiInicio %d %d\n", getpid(), getppid());
      sprintf(name, "paiFim");
    }
  }
  printf("%s\n", name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    11de <main+0x7e>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xa4(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0xa4(%rbp),%esi
mov    %eax,%edx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1060 <sprintf@plt>
jmp    12a4 <main+0x144>
cmpq   $0x0,-0x98(%rbp)
jle    129f <main+0x13f>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    124a <main+0xea>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xa8(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0xa8(%rbp),%esi
mov    %eax,%edx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <sprintf@plt>
jmp    129a <main+0x13a>
cmpq   $0x0,-0xa0(%rbp)
jle    1295 <main+0x135>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xac(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0xac(%rbp),%esi
mov    %eax,%edx
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1060 <sprintf@plt>
jmp    129a <main+0x13a>
jmp    129f <main+0x13f>
jmp    12a4 <main+0x144>
lea    -0x90(%rbp),%rsi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11bf <main+0x5f>
jle    122a <main+0xca>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11f5 <main+0x95>
jle    122a <main+0xca>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xeab(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x46696170,(%rsp)
movl   $0x6d6946,0x3(%rsp)
jmp    122a <main+0xca>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe23(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movups 0xe25(%rip),%xmm0
movaps %xmm0,(%rsp)
jmp    122a <main+0xca>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe18(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movups 0xe1d(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x6d6946,0xf(%rsp)
mov    %rsp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"filhoPerdido %d %d\0A\00"
@.str.1 = [16 x i8] c"filhoPerdidoFim\00"
@.str.2 = [23 x i8] c"filhoNaoPerdido %d %d\0A\00"
@.str.3 = [19 x i8] c"filhoNaoPerdidoFim\00"
@.str.4 = [17 x i8] c"paiInicio %d %d\0A\00"
@.str.5 = [7 x i8] c"paiFim\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [120 x i8]
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 (...) @fork()
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = call i32 (...) @getchar()
%14 = call i32 (...) @getpid()
%15 = call i32 (...) @getppid()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
%17 = getelementptr inbounds [120 x i8], [120 x i8]* %6, i64 0, i64 0
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %44
19: ; preds = %2
%20 = load i64, i64* %7
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = call i64 (...) @fork()
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = call i32 (...) @getpid()
%28 = call i32 (...) @getppid()
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
%30 = getelementptr inbounds [120 x i8], [120 x i8]* %6, i64 0, i64 0
%31 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %42
32: ; preds = %22
%33 = load i64, i64* %8
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = call i32 (...) @getpid()
%37 = call i32 (...) @getppid()
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %37)
%39 = getelementptr inbounds [120 x i8], [120 x i8]* %6, i64 0, i64 0
%40 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %35, %32
br label %42
42: ; preds = %41, %26
br label %43
43: ; preds = %42, %19
br label %44
44: ; preds = %43, %12
%45 = getelementptr inbounds [120 x i8], [120 x i8]* %6, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"filhoPerdido %d %d\0A\00"
@.str.1 = [16 x i8] c"filhoPerdidoFim\00"
@.str.2 = [23 x i8] c"filhoNaoPerdido %d %d\0A\00"
@.str.3 = [19 x i8] c"filhoNaoPerdidoFim\00"
@.str.4 = [17 x i8] c"paiInicio %d %d\0A\00"
@.str.5 = [7 x i8] c"paiFim\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [120 x i8]
%4 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = tail call i32 (...) @getchar()
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (...) @getppid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
br label %27
12: ; preds = %2
%13 = icmp sgt i64 %5, 0
br i1 %13, label %14, label %27
14: ; preds = %12
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = tail call i32 (...) @getpid()
%19 = tail call i32 (...) @getppid()
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19)
br label %27
21: ; preds = %14
%22 = icmp sgt i64 %15, 0
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = tail call i32 (...) @getpid()
%25 = tail call i32 (...) @getppid()
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %25)
br label %27
27: ; preds = %17, %23, %21, %12, %7
%28 = call i32 @puts(i8* %4)
ret i32 0
}