#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*/ SIGTERM;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WTERMSIG(int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int);
int /*<<< orphan*/ test_daemon();
int /*<<< orphan*/ test_init(int, char **);
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
scalar_t__ wait(int *);
int main(int argc, char **argv) {
  int ret;
  pid_t pid;
  test_init(argc, argv);
  pid = fork();
  if (pid < 0) {
    test_msg("ERR: %s:%d: "
             "fork failed"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/wait00.c",
             23, errno, strerror(errno));
    exit(1);
  }
  if (pid == 0) {
    test_waitsig();
    _exit(0);
  }
  test_daemon();
  test_waitsig();
  if (kill(pid, SIGTERM)) {
    test_msg("FAIL: %s:%d: "
             "terminating the child failed: %m\n"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/wait00.c",
             36, errno, strerror(errno));
    goto out;
  }
  if (wait(&ret) != pid) {
    test_msg("FAIL: %s:%d: "
             "wait() returned wrong pid: %m\n"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/wait00.c",
             41, errno, strerror(errno));
    goto out;
  }
  if (WIFEXITED(ret)) {
    ret = WEXITSTATUS(ret);
    if (ret) {
      test_msg("FAIL: %s:%d: "
               "child exited with nonzero code %d (%s)\n"
               " (errno = %d (%s))\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/"
               "heads/master/test/zdtm/live/static/wait00.c",
               48, ret, strerror(ret), errno, strerror(errno));
      goto out;
    }
  }
  if (WIFSIGNALED(ret)) {
    test_msg("FAIL: %s:%d: "
             "child exited on unexpected signal %d\n"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/wait00.c",
             53, WTERMSIG(ret), errno, strerror(errno));
    goto out;
  }
  test_msg("PASS\n");
out:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <test_init@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    125c <main+0x7c>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
lea    0xdc1(%rip),%rdi
lea    0xde5(%rip),%rsi
mov    $0x17,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1275 <main+0x95>
mov    $0x0,%al
call   1070 <test_waitsig@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    $0x0,%al
call   1050 <test_daemon@plt>
mov    $0x0,%al
call   1070 <test_waitsig@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
cmp    $0x0,%rax
je     12de <main+0xfe>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x28(%rbp),%ecx
mov    %eax,%r8d
lea    0xe08(%rip),%rdi
lea    0xd5e(%rip),%rsi
mov    $0x24,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1422 <main+0x242>
lea    -0x14(%rbp),%rdi
call   10f0 <wait@plt>
cmp    -0x20(%rbp),%rax
je     1330 <main+0x150>
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xdf8(%rip),%rdi
lea    0xd0c(%rip),%rsi
mov    $0x29,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1422 <main+0x242>
mov    -0x14(%rbp),%edi
call   10c0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     13b4 <main+0x1d4>
mov    -0x14(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     13af <main+0x1cf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   10e0 <strerror@plt>
mov    %eax,-0x34(%rbp)
mov    0x2c69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xdbb(%rip),%rdi
lea    0xc90(%rip),%rsi
mov    $0x30,%edx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1422 <main+0x242>
jmp    13b4 <main+0x1d4>
mov    -0x14(%rbp),%edi
call   1080 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1414 <main+0x234>
mov    -0x14(%rbp),%edi
call   10a0 <WTERMSIG@plt>
mov    %eax,-0x40(%rbp)
mov    0x2c00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    %eax,%r9d
lea    0xd9b(%rip),%rdi
lea    0xc28(%rip),%rsi
mov    $0x35,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1422 <main+0x242>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1060 <test_msg@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
call   1040 <test_init@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     1355 <main+0x175>
je     138e <main+0x1ae>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <test_daemon@plt>
xor    %eax,%eax
call   1070 <test_waitsig@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <kill@plt>
test   %rax,%rax
je     1252 <main+0x72>
mov    0x2da7(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xe8d(%rip),%rdi
lea    0xde3(%rip),%rsi
mov    $0x24,%edx
jmp    12e3 <main+0x103>
lea    0xc(%rsp),%rdi
call   10f0 <wait@plt>
cmp    %rbx,%rax
jne    12c0 <main+0xe0>
mov    0xc(%rsp),%edi
call   10c0 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     12fc <main+0x11c>
call   10b0 <WEXITSTATUS@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
je     12fa <main+0x11a>
mov    %eax,%ebx
mov    %eax,%edi
call   10e0 <strerror@plt>
mov    %eax,%r14d
mov    0x2d41(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10e0 <strerror@plt>
mov    %eax,(%rsp)
lea    0xea5(%rip),%rdi
lea    0xd7a(%rip),%rsi
mov    $0x30,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
mov    %ebp,%r9d
jmp    133c <main+0x15c>
mov    0x2d11(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xe39(%rip),%rdi
lea    0xd4d(%rip),%rsi
mov    $0x29,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <test_msg@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
call   1080 <WIFSIGNALED@plt>
test   %rax,%rax
je     1345 <main+0x165>
mov    0xc(%rsp),%edi
call   10a0 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0x2cc0(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xe6f(%rip),%rdi
lea    0xcfc(%rip),%rsi
mov    $0x35,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <test_msg@plt>
jmp    12ef <main+0x10f>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1060 <test_msg@plt>
jmp    12ef <main+0x10f>
mov    0x2c7c(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xc94(%rip),%rdi
lea    0xcb8(%rip),%rsi
mov    $0x17,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
call   1070 <test_waitsig@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"ERR: %s:%d: fork failed (errno = %d (%s))\0A\00"
@.str.1 = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/wait00.c\00"
@errno = global i32 0
@SIGTERM = global i32 0
@.str.2 = [66 x i8] c"FAIL: %s:%d: terminating the child failed: %m\0A (errno = %d (%s))\0A\00"
@.str.3 = [63 x i8] c"FAIL: %s:%d: wait() returned wrong pid: %m\0A (errno = %d (%s))\0A\00"
@.str.4 = [72 x i8] c"FAIL: %s:%d: child exited with nonzero code %d (%s)\0A (errno = %d (%s))\0A\00"
@.str.5 = [70 x i8] c"FAIL: %s:%d: child exited on unexpected signal %d\0A (errno = %d (%s))\0A\00"
@.str.6 = [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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @test_init(i32 %8, i8** %9)
%11 = call i64 (...) @fork()
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 23, i32 %15, i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i64, i64* %7
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 (...) @test_waitsig()
%25 = call i32 @_exit(i32 0)
unreachable
26: ; preds = %20
%27 = call i32 (...) @test_daemon()
%28 = call i32 (...) @test_waitsig()
%29 = load i64, i64* %7
%30 = load i32, i32* @SIGTERM
%31 = call i64 @kill(i64 %29, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 36, i32 %34, i32 %36)
br label %78
38: ; preds = %26
%39 = call i64 @wait(i32* %6)
%40 = load i64, i64* %7
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = load i32, i32* @errno
%45 = call i32 @strerror(i32 %44)
%46 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 41, i32 %43, i32 %45)
br label %78
47: ; preds = %38
%48 = load i32, i32* %6
%49 = call i64 @WIFEXITED(i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %65
51: ; preds = %47
%52 = load i32, i32* %6
%53 = call i32 @WEXITSTATUS(i32 %52)
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %51
%57 = load i32, i32* %6
%58 = load i32, i32* %6
%59 = call i32 @strerror(i32 %58)
%60 = load i32, i32* @errno
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 48, i32 %57, i32 %59, i32 %60, i32 %62)
br label %78
64: ; preds = %51
br label %65
65: ; preds = %64, %47
%66 = load i32, i32* %6
%67 = call i64 @WIFSIGNALED(i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %65
%70 = load i32, i32* %6
%71 = call i32 @WTERMSIG(i32 %70)
%72 = load i32, i32* @errno
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %71, i32 %72, i32 %74)
br label %78
76: ; preds = %65
%77 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %78
78: ; preds = %76, %69, %56, %42, %33
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"ERR: %s:%d: fork failed (errno = %d (%s))\0A\00"
@.str.1 = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/wait00.c\00"
@errno = global i32 0
@SIGTERM = global i32 0
@.str.2 = [66 x i8] c"FAIL: %s:%d: terminating the child failed: %m\0A (errno = %d (%s))\0A\00"
@.str.3 = [63 x i8] c"FAIL: %s:%d: wait() returned wrong pid: %m\0A (errno = %d (%s))\0A\00"
@.str.4 = [72 x i8] c"FAIL: %s:%d: child exited with nonzero code %d (%s)\0A (errno = %d (%s))\0A\00"
@.str.5 = [70 x i8] c"FAIL: %s:%d: child exited on unexpected signal %d\0A (errno = %d (%s))\0A\00"
@.str.6 = [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 i64 (...) @fork()
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 23, i32 %9, i32 %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = icmp eq i64 %6, 0
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = tail call i32 (...) @test_waitsig()
%17 = tail call i32 @_exit(i32 0)
unreachable
18: ; preds = %13
%19 = tail call i32 (...) @test_daemon()
%20 = tail call i32 (...) @test_waitsig()
%21 = load i32, i32* @SIGTERM
%22 = tail call i64 @kill(i64 %6, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = load i32, i32* @errno
%26 = tail call i32 @strerror(i32 %25)
%27 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 36, i32 %25, i32 %26)
br label %60
28: ; preds = %18
%29 = call i64 @wait(i32* %3)
%30 = icmp eq i64 %29, %6
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 41, i32 %32, i32 %33)
br label %60
35: ; preds = %28
%36 = load i32, i32* %3
%37 = call i64 @WIFEXITED(i32 %36)
%38 = icmp eq i64 %37, 0
%39 = load i32, i32* %3
br i1 %38, label %48, label %40
40: ; preds = %35
%41 = call i32 @WEXITSTATUS(i32 %39)
store i32 %41, i32* %3
%42 = icmp eq i32 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %40
%44 = call i32 @strerror(i32 %41)
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 48, i32 %41, i32 %44, i32 %45, i32 %46)
br label %60
48: ; preds = %35, %40
%49 = phi i32 [ 0, %40 ], [ %39, %35 ]
%50 = call i64 @WIFSIGNALED(i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %58, label %52
52: ; preds = %48
%53 = load i32, i32* %3
%54 = call i32 @WTERMSIG(i32 %53)
%55 = load i32, i32* @errno
%56 = call i32 @strerror(i32 %55)
%57 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %54, i32 %55, i32 %56)
br label %60
58: ; preds = %48
%59 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %60
60: ; preds = %58, %52, %43, %31, %24
ret i32 0
}