#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*/ usleep(int);
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/IPC_mutex/main.c",
                66);
      }
    } while (0);
    exit(-1);
  } else if (pid > 0) {
    parent();
    wait(&status);
  } else {
    usleep(200);
    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    11c4 <main+0x54>
jmp    1199 <main+0x29>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
lea    0xe62(%rip),%rdx
mov    $0x42,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    11e4 <main+0x74>
mov    $0x0,%al
call   1040 <parent@plt>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
jmp    11f5 <main+0x85>
mov    $0xc8,%edi
call   1090 <usleep@plt>
mov    $0x0,%al
call   1030 <child@plt>
jmp    11fa <main+0x8a>
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    11a8 <main+0x38>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
lea    0xe7e(%rip),%rdx
mov    $0x42,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jne    11c2 <main+0x52>
mov    $0xc8,%edi
call   1090 <usleep@plt>
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 = [142 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/IPC_mutex/main.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 ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i32 66)
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 %21
18: ; preds = %12
%19 = call i32 @usleep(i32 200)
%20 = call i32 (...) @child()
br label %21
21: ; preds = %18, %15
br label %22
22: ; preds = %21
%23 = 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 = [142 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/IPC_mutex/main.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 ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i32 66)
%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 %17
14: ; preds = %9
%15 = tail call i32 @usleep(i32 200)
%16 = tail call i32 (...) @child()
br label %17
17: ; preds = %11, %14
%18 = call i32 @exit(i32 0)
unreachable
}