#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*/ printf(char *, char *, int);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
bool simple_fork() {
  pid_t child_pid = fork();
  if (child_pid < 0)
    printf("%s:%u: fork failed",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/BartekLew/dirclean/refs/heads/master/"
           "prompt.c",
           51);
  else if (child_pid != 0)
    waitpid(child_pid, NULL, 0);
  else
    return true;
  return false;
}


x86 assembly (clang, -O0):
<simple_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    116b <simple_fork+0x3b>
lea    0xeab(%rip),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x33,%edx
call   1030 <printf@plt>
jmp    119b <simple_fork+0x6b>
cmpq   $0x0,-0x10(%rbp)
je     118a <simple_fork+0x5a>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
jmp    1196 <simple_fork+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <simple_fork+0x72>
jmp    119b <simple_fork+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_fork>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
js     1151 <simple_fork+0x21>
je     116b <simple_fork+0x3b>
xor    %ebx,%ebx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
jmp    1170 <simple_fork+0x40>
lea    0xea8(%rip),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x33,%edx
call   1030 <printf@plt>
jmp    1170 <simple_fork+0x40>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%s:%u: fork failed\00"
@.str.1 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BartekLew/dirclean/refs/heads/master/prompt.c\00"
define i32 @simple_fork() {
%1 = alloca i32
%2 = alloca i64
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 51)
br label %16
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i64, i64* %2
%13 = call i32 @waitpid(i64 %12, i32* null, i32 0)
br label %15
14: ; preds = %8
store i32 1, i32* %1
br label %17
15: ; preds = %11
br label %16
16: ; preds = %15, %6
store i32 0, i32* %1
br label %17
17: ; preds = %16, %14
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [19 x i8] c"%s:%u: fork failed\00"
@.str.1 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BartekLew/dirclean/refs/heads/master/prompt.c\00"
define i32 @simple_fork() {
%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 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 51)
br label %9
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @waitpid(i64 %1, i32* null, i32 0)
br label %9
9: ; preds = %3, %7, %5
%10 = phi i32 [ 1, %5 ], [ 0, %7 ], [ 0, %3 ]
ret i32 %10
}