#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
void main(int argc, char *argv[]) {
  pid_t pid = 0;
  pid = fork();
  if (pid < 0) {
    perror("Fork Failed");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    while (1) {
      printf("A, B, C");
    }
  } else {
    pid = fork();
    if (pid < 0) {
      perror("Fork Failed");
      exit(EXIT_FAILURE);
    } else if (pid == 0) {
      while (1) {
        printf("a, b, c");
      }
    }
    while (1) {
      printf("El padre esta ejecutando . . .");
    }
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1187 <main+0x47>
lea    0xe8c(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <main+0x68>
jmp    1197 <main+0x57>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
jmp    1197 <main+0x57>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11d8 <main+0x98>
lea    0xe3b(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11f9 <main+0xb9>
jmp    11e8 <main+0xa8>
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
jmp    11e8 <main+0xa8>
jmp    11fe <main+0xbe>
jmp    1203 <main+0xc3>
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
jmp    1203 <main+0xc3>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     11ba <main+0x7a>
je     117a <main+0x3a>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     11ba <main+0x7a>
je     119a <main+0x5a>
lea    0xeb8(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <printf@plt>
jmp    1170 <main+0x30>
lea    0xe8b(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <printf@plt>
jmp    1190 <main+0x50>
lea    0xe73(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <printf@plt>
jmp    11b0 <main+0x70>
lea    0xe3f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Fork Failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"A, B, C\00"
@.str.2 = [8 x i8] c"a, b, c\00"
@.str.3 = [31 x i8] c"El padre esta ejecutando . . .\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 0, i64* %5
%6 = call i64 (...) @fork()
store i64 %6, i64* %5
%7 = load i64, i64* %5
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i64, i64* %5
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
br label %17
17: ; preds = %16, %17
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %17
19: ; preds = %13
%20 = call i64 (...) @fork()
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i64, i64* %5
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
br label %31
31: ; preds = %30, %31
%32 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %31
33: ; preds = %27
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34, %35
%36 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %35
}

LLVM IR (-O2):
@.str = [12 x i8] c"Fork Failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"A, B, C\00"
@.str.2 = [8 x i8] c"a, b, c\00"
@.str.3 = [31 x i8] c"El padre esta ejecutando . . .\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = icmp eq i64 %3, 0
br i1 %10, label %11, label %13
11: ; preds = %9, %11
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %11
13: ; preds = %9
%14 = tail call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
%21 = icmp eq i64 %14, 0
br i1 %21, label %22, label %24
22: ; preds = %20, %22
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %22
24: ; preds = %20, %24
%25 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %24
}