#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(void) {
  pid_t pid;
  if ((pid = fork()) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day05/review.c",
              20, "fork", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (pid == 0) {
    while (1) {
      printf(".");
      fflush(stdout);
    }
  } else {
    while (1) {
      printf("X");
      fflush(stdout);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11d4 <main+0x74>
jmp    1187 <main+0x27>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%r9
lea    0xe52(%rip),%rsi
lea    0xe5b(%rip),%rdx
mov    $0x14,%ecx
lea    0xee4(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1202 <main+0xa2>
jmp    11e3 <main+0x83>
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    11e3 <main+0x83>
jmp    1207 <main+0xa7>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1207 <main+0xa7>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1193 <main+0x33>
cmp    $0xffffffff,%eax
je     11b3 <main+0x53>
mov    0x2e50(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x58,%edi
call   1030 <putchar@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
jmp    1180 <main+0x20>
mov    0x2e2e(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
jmp    11a0 <main+0x40>
mov    0x2e26(%rip),%rax
mov    (%rax),%ebx
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe2f(%rip),%rsi
lea    0xe38(%rip),%rdx
lea    0xec6(%rip),%r8
mov    %ebx,%edi
mov    $0x14,%ecx
mov    %rax,%r9
call   1040 <fprintf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day05/review.c\00"
@.str.2 = [5 x i8] c"fork\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c".\00"
@stdout = global i32 0
@.str.4 = [2 x i8] c"X\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %14
5: ; preds = %0
br label %6
6: ; preds = %5
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; No predecessors!
br label %14
14: ; preds = %13, %0
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
br label %18
18: ; preds = %17, %18
%19 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
br label %18
22: ; preds = %14
br label %23
23: ; preds = %22, %23
%24 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
br label %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day05/review.c\00"
@.str.2 = [5 x i8] c"fork\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %13 [
i32 -1, label %2
i32 0, label %9
]
2: ; preds = %0
%3 = load i32, i32* @stderr
%4 = load i32, i32* @errno
%5 = tail call i8* @strerror(i32 %4)
%6 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0, %9
%10 = tail call i32 @putchar(i32 46)
%11 = load i32, i32* @stdout
%12 = tail call i32 @fflush(i32 %11)
br label %9
13: ; preds = %0, %13
%14 = tail call i32 @putchar(i32 88)
%15 = load i32, i32* @stdout
%16 = tail call i32 @fflush(i32 %15)
br label %13
}