#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 /*<<< orphan*/ EINTR;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ test_daemon();
scalar_t__ test_go();
int /*<<< orphan*/ test_init(int, char **);
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
int wait(int *);
int main(int argc, char **argv) {
  int pid, wpid, status;
  test_init(argc, argv);
  test_daemon();
  while (test_go()) {
    pid = fork();
    if (pid < 0) {
      test_msg("FAIL: %s:%d: "
               "Can't fork"
               " (errno = %d)\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/"
               "master/test/zdtm/live/transition/fork.c",
               28, errno);
      goto out;
    }
    if (pid == 0)
      exit(0);
    while ((wpid = wait(&status)) == -1 && errno == EINTR)
      ;
    if (wpid != pid) {
      test_msg("FAIL: %s:%d: "
               "Pids do not match: expected %d "
               "instead of %d (errno=%d status=%x)"
               " (errno = %d)\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/"
               "master/test/zdtm/live/transition/fork.c",
               38, pid, wpid, errno, status, errno);
      goto out;
    }
    if (!WIFEXITED(status)) {
      test_msg("FAIL: %s:%d: "
               "Task didn't exit"
               " (errno = %d)\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/"
               "master/test/zdtm/live/transition/fork.c",
               45, errno);
      goto out;
    }
    if (WEXITSTATUS(status) != 0) {
      test_msg("FAIL: %s:%d: "
               "Task exited with wrong code"
               " (errno = %d)\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/"
               "master/test/zdtm/live/transition/fork.c",
               50, errno);
      goto out;
    }
  }
  test_waitsig();
  test_msg("PASS\n");
out:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <test_init@plt>
mov    $0x0,%al
call   1040 <test_daemon@plt>
mov    $0x0,%al
call   1080 <test_go@plt>
cmp    $0x0,%rax
je     133e <main+0x19e>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1216 <main+0x76>
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
lea    0xe02(%rip),%rdi
lea    0xe21(%rip),%rsi
mov    $0x1c,%edx
mov    $0x0,%al
call   1050 <test_msg@plt>
jmp    1353 <main+0x1b3>
cmpl   $0x0,-0x14(%rbp)
jne    1227 <main+0x87>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    122c <main+0x8c>
lea    -0x1c(%rbp),%rdi
call   10b0 <wait@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x1d(%rbp)
jne    1260 <main+0xc0>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    0x2d80(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1270 <main+0xd0>
jmp    1275 <main+0xd5>
jmp    122c <main+0x8c>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     12c6 <main+0x126>
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    0x2d51(%rip),%rax
mov    (%rax),%r9d
mov    -0x1c(%rbp),%r10d
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
lea    0xe19(%rip),%rdi
lea    0xd79(%rip),%rsi
mov    $0x26,%edx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1050 <test_msg@plt>
jmp    1353 <main+0x1b3>
mov    -0x1c(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    12ff <main+0x15f>
mov    0x2d02(%rip),%rax
mov    (%rax),%ecx
lea    0xe35(%rip),%rdi
lea    0xd38(%rip),%rsi
mov    $0x2d,%edx
mov    $0x0,%al
call   1050 <test_msg@plt>
jmp    1353 <main+0x1b3>
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1339 <main+0x199>
mov    0x2cc8(%rip),%rax
mov    (%rax),%ecx
lea    0xe27(%rip),%rdi
lea    0xcfe(%rip),%rsi
mov    $0x32,%edx
mov    $0x0,%al
call   1050 <test_msg@plt>
jmp    1353 <main+0x1b3>
jmp    11c9 <main+0x29>
mov    $0x0,%al
call   1060 <test_waitsig@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <test_msg@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1030 <test_init@plt>
xor    %eax,%eax
call   1040 <test_daemon@plt>
lea    0x4(%rsp),%rbx
mov    0x2e21(%rip),%r15
mov    0x2e12(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <test_go@plt>
test   %rax,%rax
je     1242 <main+0xa2>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
js     1259 <main+0xb9>
mov    %eax,%r14d
je     12c5 <main+0x125>
mov    %rbx,%rdi
call   10b0 <wait@plt>
mov    (%r15),%r9d
cmp    $0xffffffff,%eax
jne    1206 <main+0x66>
cmp    0x0(%rbp),%r9d
je     11f0 <main+0x50>
mov    0x4(%rsp),%r10d
cmp    %r14d,%eax
jne    1271 <main+0xd1>
mov    %r10d,%edi
call   1090 <WIFEXITED@plt>
test   %eax,%eax
je     129b <main+0xfb>
mov    0x4(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
test   %rax,%rax
je     11d0 <main+0x30>
mov    (%r15),%ecx
lea    0xf14(%rip),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x32,%edx
jmp    12b1 <main+0x111>
xor    %eax,%eax
call   1060 <test_waitsig@plt>
lea    0xf2f(%rip),%rdi
xor    %eax,%eax
call   1050 <test_msg@plt>
jmp    12b8 <main+0x118>
mov    (%r15),%ecx
lea    0xd9d(%rip),%rdi
lea    0xdbc(%rip),%rsi
mov    $0x1c,%edx
jmp    12b1 <main+0x111>
lea    0xe47(%rip),%rdi
lea    0xda7(%rip),%rsi
mov    $0x26,%edx
mov    %r14d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
push   %r9
push   %r10
call   1050 <test_msg@plt>
add    $0x10,%rsp
jmp    12b8 <main+0x118>
mov    (%r15),%ecx
lea    0xe77(%rip),%rdi
lea    0xd7a(%rip),%rsi
mov    $0x2d,%edx
xor    %eax,%eax
call   1050 <test_msg@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"FAIL: %s:%d: Can't fork (errno = %d)\0A\00"
@.str.1 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/master/test/zdtm/live/transition/fork.c\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.2 = [93 x i8] c"FAIL: %s:%d: Pids do not match: expected %d instead of %d (errno=%d status=%x) (errno = %d)\0A\00"
@.str.3 = [44 x i8] c"FAIL: %s:%d: Task didn't exit (errno = %d)\0A\00"
@.str.4 = [55 x i8] c"FAIL: %s:%d: Task exited with wrong code (errno = %d)\0A\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @test_init(i32 %9, i8** %10)
%12 = call i32 (...) @test_daemon()
br label %13
13: ; preds = %64, %2
%14 = call i64 (...) @test_go()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %65
16: ; preds = %13
%17 = call i32 (...) @fork()
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 28, i32 %21)
br label %68
23: ; preds = %16
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %23
br label %29
29: ; preds = %38, %28
%30 = call i32 @wait(i32* %8)
store i32 %30, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = load i32, i32* @EINTR
%35 = icmp eq i32 %33, %34
br label %36
36: ; preds = %32, %29
%37 = phi i1 [ false, %29 ], [ %35, %32 ]
br i1 %37, label %38, label %39
38: ; preds = %36
br label %29
39: ; preds = %36
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = load i32, i32* @errno
%47 = load i32, i32* %8
%48 = load i32, i32* @errno
%49 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 38, i32 %44, i32 %45, i32 %46, i32 %47, i32 %48)
br label %68
50: ; preds = %39
%51 = load i32, i32* %8
%52 = call i32 @WIFEXITED(i32 %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %50
%55 = load i32, i32* @errno
%56 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 45, i32 %55)
br label %68
57: ; preds = %50
%58 = load i32, i32* %8
%59 = call i64 @WEXITSTATUS(i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i32, i32* @errno
%63 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 50, i32 %62)
br label %68
64: ; preds = %57
br label %13
65: ; preds = %13
%66 = call i32 (...) @test_waitsig()
%67 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %65, %61, %54, %43, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"FAIL: %s:%d: Can't fork (errno = %d)\0A\00"
@.str.1 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/master/test/zdtm/live/transition/fork.c\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.2 = [93 x i8] c"FAIL: %s:%d: Pids do not match: expected %d instead of %d (errno=%d status=%x) (errno = %d)\0A\00"
@.str.3 = [44 x i8] c"FAIL: %s:%d: Task didn't exit (errno = %d)\0A\00"
@.str.4 = [55 x i8] c"FAIL: %s:%d: Task exited with wrong code (errno = %d)\0A\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @test_init(i32 %0, i8** %1)
%6 = tail call i32 (...) @test_daemon()
br label %7
7: ; preds = %38, %2
%8 = call i64 (...) @test_go()
%9 = icmp eq i64 %8, 0
br i1 %9, label %45, label %10
10: ; preds = %7
%11 = call i32 (...) @fork()
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 28, i32 %14)
br label %48
16: ; preds = %10
%17 = icmp eq i32 %11, 0
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %16, %20
%21 = call i32 @wait(i32* %3)
%22 = icmp eq i32 %21, -1
%23 = load i32, i32* @errno
%24 = load i32, i32* @EINTR
%25 = icmp eq i32 %23, %24
%26 = select i1 %22, i1 %25, i1 false
br i1 %26, label %20, label %27
27: ; preds = %20
%28 = icmp eq i32 %21, %11
%29 = load i32, i32* %3
br i1 %28, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 38, i32 %11, i32 %21, i32 %23, i32 %29, i32 %23)
br label %48
32: ; preds = %27
%33 = call i32 @WIFEXITED(i32 %29)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @errno
%37 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 45, i32 %36)
br label %48
38: ; preds = %32
%39 = load i32, i32* %3
%40 = call i64 @WEXITSTATUS(i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %7, label %42
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 50, i32 %43)
br label %48
45: ; preds = %7
%46 = call i32 (...) @test_waitsig()
%47 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %45, %42, %35, %30, %13
ret i32 0
}