#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*/ child();
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ parent();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main(void) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0) {
    do {
      if (1 <= 4) {
        fprintf(stderr,
                "%s %d: "
                "fork error",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/"
                "master/POSIX_sem/process_sem.c",
                59);
      }
    } while (0);
    exit(-1);
  } else if (pid > 0) {
    parent();
    wait(&status);
  } else {
    child();
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    11b4 <main+0x54>
jmp    1189 <main+0x29>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
lea    0xe72(%rip),%rdx
mov    $0x3b,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    11d4 <main+0x74>
mov    $0x0,%al
call   1040 <parent@plt>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
jmp    11db <main+0x7b>
mov    $0x0,%al
call   1030 <child@plt>
jmp    11e0 <main+0x80>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jns    1198 <main+0x38>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
lea    0xe8e(%rip),%rdx
mov    $0x3b,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jne    11a8 <main+0x48>
xor    %eax,%eax
call   1030 <child@plt>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1040 <parent@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"%s %d: fork error\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/POSIX_sem/process_sem.c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
br label %7
7: ; preds = %6
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 59)
br label %10
10: ; preds = %7
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = load i64, i64* %2
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (...) @parent()
%17 = call i32 @wait(i32* %3)
br label %20
18: ; preds = %12
%19 = call i32 (...) @child()
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"%s %d: fork error\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/POSIX_sem/process_sem.c\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 59)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = icmp eq i64 %3, 0
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = tail call i32 (...) @parent()
%13 = call i32 @wait(i32* %1)
br label %16
14: ; preds = %9
%15 = tail call i32 (...) @child()
br label %16
16: ; preds = %11, %14
%17 = call i32 @exit(i32 0)
unreachable
}