#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 */

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int __chk_error(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ error1(char *, int, char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
void test_fork(void) {
  int pid, status;
  pid = __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/Cisco-Talos/pyrebox/"
                    "refs/heads/master/qemu/tests/tcg/multiarch/linux-test.c",
                    213, (fork()));
  if (pid == 0) {
    sleep(2);
    exit(2);
  }
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/Cisco-Talos/pyrebox/refs/heads/master/"
              "qemu/tests/tcg/multiarch/linux-test.c",
              219, (waitpid(pid, &status, 0)));
  if (!WIFEXITED(status) || WEXITSTATUS(status) != 2)
    error1("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/Cisco-Talos/pyrebox/refs/heads/master/"
           "qemu/tests/tcg/multiarch/linux-test.c",
           221, "waitpid status=0x%x", status);
}


x86 assembly (clang, -O0):
<test_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,%edx
lea    0xe68(%rip),%rdi
mov    $0xd5,%esi
call   1030 <__chk_error@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11c3 <test_fork+0x43>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,%edx
lea    0xe26(%rip),%rdi
mov    $0xdb,%esi
call   1030 <__chk_error@plt>
mov    -0x8(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1206 <test_fork+0x86>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x2,%eax
je     1221 <test_fork+0xa1>
mov    -0x8(%rbp),%ecx
lea    0xdf0(%rip),%rdi
mov    $0xdd,%esi
lea    0xe8a(%rip),%rdx
call   1080 <error1@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fork>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
lea    0xe71(%rip),%rdi
mov    $0xd5,%esi
mov    %eax,%edx
call   1030 <__chk_error@plt>
test   %eax,%eax
je     11f9 <test_fork+0x79>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xe4c(%rip),%rdi
mov    $0xdb,%esi
mov    %eax,%edx
call   1030 <__chk_error@plt>
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %eax,%eax
je     11db <test_fork+0x5b>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x2,%eax
je     11f7 <test_fork+0x77>
mov    0x4(%rsp),%ecx
lea    0xe1a(%rip),%rdi
lea    0xeb9(%rip),%rdx
mov    $0xdd,%esi
call   1080 <error1@plt>
pop    %rax
ret
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [166 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Cisco-Talos/pyrebox/refs/heads/master/qemu/tests/tcg/multiarch/linux-test.c\00"
@.str.1 = [20 x i8] c"waitpid status=0x%x\00"
define void @test_fork() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @fork()
%4 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 213, i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @sleep(i32 2)
%9 = call i32 @exit(i32 2)
unreachable
10: ; preds = %0
%11 = load i32, i32* %1
%12 = call i32 @waitpid(i32 %11, i32* %2, i32 0)
%13 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 219, i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @WIFEXITED(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* %2
%19 = call i32 @WEXITSTATUS(i32 %18)
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %17, %10
%22 = load i32, i32* %2
%23 = call i32 @error1(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 221, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %17
ret void
}

LLVM IR (-O2):
@.str = [166 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Cisco-Talos/pyrebox/refs/heads/master/qemu/tests/tcg/multiarch/linux-test.c\00"
@.str.1 = [20 x i8] c"waitpid status=0x%x\00"
define void @test_fork() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = tail call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 213, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @sleep(i32 2)
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %0
%10 = call i32 @waitpid(i32 %4, i32* %1, i32 0)
%11 = call i32 @__chk_error(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 219, i32 %10)
%12 = load i32, i32* %1
%13 = call i32 @WIFEXITED(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %9
%16 = load i32, i32* %1
%17 = call i32 @WEXITSTATUS(i32 %16)
%18 = icmp eq i32 %17, 2
br i1 %18, label %22, label %19
19: ; preds = %15, %9
%20 = load i32, i32* %1
%21 = call i32 @error1(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str, i64 0, i64 0), i32 221, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %15
ret void
}