#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ timer_t;
struct timespec {
  int /*<<< orphan*/ tv_nsec;
  scalar_t__ tv_sec;
};
struct sigevent {
  int sigev_signo;
  void *sigev_notify;
};
struct TYPE_4__ {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};
struct TYPE_3__ {
  int /*<<< orphan*/ tv_nsec;
  scalar_t__ tv_sec;
};
struct itimerspec {
  TYPE_2__ it_interval;
  TYPE_1__ it_value;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int SIGABRT;
int SIGALRM;
void *SIGEV_SIGNAL;
int /*<<< orphan*/ SIG_BLOCK;
int TIMER_ABSTIME;
scalar_t__ WEXITSTATUS(int);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sigaddset(int /*<<< orphan*/ *, int);
int sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int sigwait(int /*<<< orphan*/ *, int *);
scalar_t__ timer_create(int /*<<< orphan*/, struct sigevent *,
                        int /*<<< orphan*/ *);
scalar_t__ timer_settime(int /*<<< orphan*/, int, struct itimerspec *,
                         int /*<<< orphan*/ *);
int wait(int *);
int main(int argc, char *argv[]) {
  int pid;
  struct timespec ts;
  if (clock_gettime(CLOCK_REALTIME, &ts) != 0) {
    perror("clock_gettime() did not return success\n");
    return 2;
  }
  if ((pid = fork()) == 0) {
    struct sigevent ev;
    timer_t tid;
    struct itimerspec its;
    sigset_t set;
    int sig;
    int flags = 0;
    if (sigemptyset(&set) == -1) {
      perror("sigemptyset() failed\n");
      return 2;
    }
    if (sigaddset(&set, SIGABRT) == -1) {
      perror("sigaddset() failed\n");
      return 2;
    }
    if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
      perror("sigprocmask() failed\n");
      return 2;
    }
    ev.sigev_notify = SIGEV_SIGNAL;
    ev.sigev_signo = SIGABRT;
    if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
      perror("timer_create() did not return success\n");
      return 2;
    }
    its.it_value.tv_sec = ts.tv_sec + 2;
    its.it_value.tv_nsec = ts.tv_nsec;
    its.it_interval.tv_sec = 0;
    its.it_interval.tv_nsec = 0;
    flags |= TIMER_ABSTIME;
    if (timer_settime(tid, flags, &its, NULL) != 0) {
      perror("timer_settime() did not return success\n");
      return 2;
    }
    if (sigwait(&set, &sig) == -1) {
      perror("sigwait() failed\n");
      return 2;
    }
    if (sig == SIGABRT) {
      printf("Got it! Child\n");
      return 1;
    }
    printf("Got another signal! Child\n");
    return 1;
  } else {
    struct sigevent ev;
    timer_t tid;
    struct itimerspec its;
    sigset_t set;
    int sig;
    int flags = 0;
    int i;
    if (sigemptyset(&set) == -1) {
      perror("sigemptyset() failed\n");
      return 2;
    }
    if (sigaddset(&set, SIGALRM) == -1) {
      perror("sigaddset() failed\n");
      return 2;
    }
    if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
      perror("sigaprocmask() failed\n");
      return 2;
    }
    ev.sigev_notify = SIGEV_SIGNAL;
    ev.sigev_signo = SIGALRM;
    if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
      perror("timer_create() did not return success\n");
      return 2;
    }
    its.it_value.tv_sec = ts.tv_sec + 2;
    its.it_value.tv_nsec = ts.tv_nsec;
    its.it_interval.tv_sec = 0;
    its.it_interval.tv_nsec = 0;
    flags |= TIMER_ABSTIME;
    if (timer_settime(tid, flags, &its, NULL) != 0) {
      perror("timer_settime() did not return success\n");
      return 2;
    }
    if (sigwait(&set, &sig) == -1) {
      perror("sigwait() failed\n");
      return 2;
    }
    if (sig != SIGALRM) {
      printf("Got another signal! Parent\n");
      return 1;
    }
    printf("Got it! Parent\n");
    if (wait(&i) == -1) {
      perror("Error waiting for child to exit\n");
      return 2;
    }
    if (WEXITSTATUS(i)) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("Test FAILED\n");
      return 1;
    }
  }
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1050 <clock_gettime@plt>
cmp    $0x0,%rax
je     120d <main+0x4d>
lea    0xe04(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    13e3 <main+0x223>
movl   $0x0,-0x6c(%rbp)
lea    -0x64(%rbp),%rdi
call   1080 <sigemptyset@plt>
cmp    $0xffffffff,%eax
jne    1251 <main+0x91>
lea    0xde8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
lea    -0x64(%rbp),%rdi
call   10d0 <sigaddset@plt>
cmp    $0xffffffff,%eax
jne    1284 <main+0xc4>
lea    0xdcb(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    -0x64(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    12bb <main+0xfb>
lea    0xda8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    0x2d16(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1060 <timer_create@plt>
cmp    $0x0,%rax
je     130d <main+0x14d>
lea    0xd6c(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
or     -0x6c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x6c(%rbp),%esi
lea    -0x60(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     1373 <main+0x1b3>
lea    0xd2d(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
lea    -0x64(%rbp),%rdi
lea    -0x68(%rbp),%rsi
call   10b0 <sigwait@plt>
cmp    $0xffffffff,%eax
jne    13a1 <main+0x1e1>
lea    0xd27(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    -0x68(%rbp),%eax
mov    0x2c0d(%rip),%rcx
cmp    (%rcx),%eax
jne    13cb <main+0x20b>
lea    0xd0f(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163a <main+0x47a>
lea    0xd06(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163a <main+0x47a>
movl   $0x0,-0xb4(%rbp)
lea    -0xac(%rbp),%rdi
call   1080 <sigemptyset@plt>
cmp    $0xffffffff,%eax
jne    141a <main+0x25a>
lea    0xc1f(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    0x2bc7(%rip),%rax
mov    (%rax),%esi
lea    -0xac(%rbp),%rdi
call   10d0 <sigaddset@plt>
cmp    $0xffffffff,%eax
jne    1450 <main+0x290>
lea    0xbff(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
lea    -0xac(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    148a <main+0x2ca>
lea    0xc7a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    0x2b47(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    0x2b49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
lea    -0x84(%rbp),%rdx
call   1060 <timer_create@plt>
cmp    $0x0,%rax
je     14df <main+0x31f>
lea    0xb9a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x98(%rbp)
movq   $0x0,-0xa0(%rbp)
movq   $0x0,-0xa8(%rbp)
mov    0x2acc(%rip),%rax
mov    (%rax),%eax
or     -0xb4(%rbp),%eax
mov    %eax,-0xb4(%rbp)
mov    -0x84(%rbp),%edi
mov    -0xb4(%rbp),%esi
lea    -0xa8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     1560 <main+0x3a0>
lea    0xb40(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
lea    -0xac(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   10b0 <sigwait@plt>
cmp    $0xffffffff,%eax
jne    1594 <main+0x3d4>
lea    0xb34(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    -0xb0(%rbp),%eax
mov    0x2a47(%rip),%rcx
cmp    (%rcx),%eax
je     15c1 <main+0x401>
lea    0xb5a(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163a <main+0x47a>
lea    0xb5e(%rip),%rdi
call   1070 <printf@plt>
lea    -0xb8(%rbp),%rdi
call   10c0 <wait@plt>
cmp    $0xffffffff,%eax
jne    15fa <main+0x43a>
lea    0xb4d(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    163a <main+0x47a>
mov    -0xb8(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1627 <main+0x467>
lea    0xb41(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    163a <main+0x47a>
lea    0xb36(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2df2(%rip),%rbx
mov    (%rbx),%edi
lea    0x20(%rsp),%rsi
call   1060 <clock_gettime@plt>
test   %rax,%rax
jne    140b <main+0x24b>
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %rsp,%rdi
test   %eax,%eax
je     1311 <main+0x151>
call   1080 <sigemptyset@plt>
cmp    $0xffffffff,%eax
je     1414 <main+0x254>
mov    0x2dde(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rdi
call   10d0 <sigaddset@plt>
cmp    $0xffffffff,%eax
je     141d <main+0x25d>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     1441 <main+0x281>
mov    0x2d97(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <timer_create@plt>
test   %rax,%rax
jne    1426 <main+0x266>
mov    0x28(%rsp),%rax
add    $0x2,%rax
mov    %rax,0x48(%rsp)
mov    0x20(%rsp),%eax
mov    %eax,0x40(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rdx
xor    %ecx,%ecx
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    142f <main+0x26f>
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   10b0 <sigwait@plt>
cmp    $0xffffffff,%eax
je     1438 <main+0x278>
mov    0x4(%rsp),%eax
cmp    (%r14),%eax
jne    13e6 <main+0x226>
lea    0xe2d(%rip),%rdi
call   1050 <puts@plt>
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
cmp    $0xffffffff,%eax
je     1453 <main+0x293>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
test   %rax,%rax
je     13f8 <main+0x238>
lea    0xe17(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
jmp    1464 <main+0x2a4>
call   1080 <sigemptyset@plt>
cmp    $0xffffffff,%eax
je     1414 <main+0x254>
mov    0x2c92(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rdi
call   10d0 <sigaddset@plt>
cmp    $0xffffffff,%eax
je     141d <main+0x25d>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     144a <main+0x28a>
mov    0x2c7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <timer_create@plt>
test   %rax,%rax
jne    1426 <main+0x266>
mov    0x28(%rsp),%rax
add    $0x2,%rax
mov    %rax,0x48(%rsp)
mov    0x20(%rsp),%eax
mov    %eax,0x40(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
mov    0x2c35(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rdx
xor    %ecx,%ecx
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    142f <main+0x26f>
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   10b0 <sigwait@plt>
cmp    $0xffffffff,%eax
je     1438 <main+0x278>
mov    0x4(%rsp),%eax
cmp    (%r14),%eax
jne    13ef <main+0x22f>
lea    0xd79(%rip),%rdi
jmp    13ff <main+0x23f>
lea    0xd3b(%rip),%rdi
jmp    13ff <main+0x23f>
lea    0xd4d(%rip),%rdi
jmp    13ff <main+0x23f>
lea    0xd11(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1464 <main+0x2a4>
lea    0xbee(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc0d(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc1a(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc3b(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc59(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc78(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc81(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc01(%rip),%rdi
jmp    145a <main+0x29a>
lea    0xc86(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
%struct.sigevent = type { i32, i8* }
%struct.itimerspec = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [40 x i8] c"clock_gettime() did not return success\0A\00"
@.str.1 = [22 x i8] c"sigemptyset() failed\0A\00"
@SIGABRT = global i32 0
@.str.2 = [20 x i8] c"sigaddset() failed\0A\00"
@SIG_BLOCK = global i32 0
@.str.3 = [22 x i8] c"sigprocmask() failed\0A\00"
@SIGEV_SIGNAL = global i8* null
@.str.4 = [39 x i8] c"timer_create() did not return success\0A\00"
@TIMER_ABSTIME = global i32 0
@.str.5 = [40 x i8] c"timer_settime() did not return success\0A\00"
@.str.6 = [18 x i8] c"sigwait() failed\0A\00"
@.str.7 = [15 x i8] c"Got it! Child\0A\00"
@.str.8 = [27 x i8] c"Got another signal! Child\0A\00"
@SIGALRM = global i32 0
@.str.9 = [23 x i8] c"sigaprocmask() failed\0A\00"
@.str.10 = [28 x i8] c"Got another signal! Parent\0A\00"
@.str.11 = [16 x i8] c"Got it! Parent\0A\00"
@.str.12 = [33 x i8] c"Error waiting for child to exit\0A\00"
@.str.13 = [13 x i8] c"Test PASSED\0A\00"
@.str.14 = [13 x i8] c"Test FAILED\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timespec
%8 = alloca %struct.sigevent
%9 = alloca i32
%10 = alloca %struct.itimerspec
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.sigevent
%15 = alloca i32
%16 = alloca %struct.itimerspec
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* @CLOCK_REALTIME
%22 = call i64 @clock_gettime(i32 %21, %struct.timespec* %7)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %167
26: ; preds = %2
%27 = call i32 (...) @fork()
store i32 %27, i32* %6
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %92
29: ; preds = %26
store i32 0, i32* %13
%30 = call i32 @sigemptyset(i32* %11)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %167
34: ; preds = %29
%35 = load i32, i32* @SIGABRT
%36 = call i32 @sigaddset(i32* %11, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %167
40: ; preds = %34
%41 = load i32, i32* @SIG_BLOCK
%42 = call i32 @sigprocmask(i32 %41, i32* %11, i32* null)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %167
46: ; preds = %40
%47 = load i8*, i8** @SIGEV_SIGNAL
%48 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %8, i32 0, i32 1
store i8* %47, i8** %48
%49 = load i32, i32* @SIGABRT
%50 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %8, i32 0, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* @CLOCK_REALTIME
%52 = call i64 @timer_create(i32 %51, %struct.sigevent* %8, i32* %9)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %46
%55 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %167
56: ; preds = %46
%57 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%58 = load i64, i64* %57
%59 = add nsw i64 %58, 2
%60 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %10, i32 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %60, i32 0, i32 1
store i64 %59, i64* %61
%62 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %10, i32 0, i32 1
%65 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %64, i32 0, i32 0
store i32 %63, i32* %65
%66 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %10, i32 0, i32 0
%67 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %66, i32 0, i32 1
store i64 0, i64* %67
%68 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %10, i32 0, i32 0
%69 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %68, i32 0, i32 0
store i64 0, i64* %69
%70 = load i32, i32* @TIMER_ABSTIME
%71 = load i32, i32* %13
%72 = or i32 %71, %70
store i32 %72, i32* %13
%73 = load i32, i32* %9
%74 = load i32, i32* %13
%75 = call i64 @timer_settime(i32 %73, i32 %74, %struct.itimerspec* %10, i32* null)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %56
%78 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %167
79: ; preds = %56
%80 = call i32 @sigwait(i32* %11, i32* %12)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %167
84: ; preds = %79
%85 = load i32, i32* %12
%86 = load i32, i32* @SIGABRT
%87 = icmp eq i32 %85, %86
br i1 %87, label %88, label %90
88: ; preds = %84
%89 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %167
90: ; preds = %84
%91 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %167
92: ; preds = %26
store i32 0, i32* %19
%93 = call i32 @sigemptyset(i32* %17)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %167
97: ; preds = %92
%98 = load i32, i32* @SIGALRM
%99 = call i32 @sigaddset(i32* %17, i32 %98)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %167
103: ; preds = %97
%104 = load i32, i32* @SIG_BLOCK
%105 = call i32 @sigprocmask(i32 %104, i32* %17, i32* null)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %109
107: ; preds = %103
%108 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
store i32 2, i32* %3
br label %167
109: ; preds = %103
%110 = load i8*, i8** @SIGEV_SIGNAL
%111 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %14, i32 0, i32 1
store i8* %110, i8** %111
%112 = load i32, i32* @SIGALRM
%113 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %14, i32 0, i32 0
store i32 %112, i32* %113
%114 = load i32, i32* @CLOCK_REALTIME
%115 = call i64 @timer_create(i32 %114, %struct.sigevent* %14, i32* %15)
%116 = icmp ne i64 %115, 0
br i1 %116, label %117, label %119
117: ; preds = %109
%118 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %167
119: ; preds = %109
%120 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%121 = load i64, i64* %120
%122 = add nsw i64 %121, 2
%123 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %16, i32 0, i32 1
%124 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %123, i32 0, i32 1
store i64 %122, i64* %124
%125 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%126 = load i32, i32* %125
%127 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %16, i32 0, i32 1
%128 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %127, i32 0, i32 0
store i32 %126, i32* %128
%129 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %16, i32 0, i32 0
%130 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %129, i32 0, i32 1
store i64 0, i64* %130
%131 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %16, i32 0, i32 0
%132 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %131, i32 0, i32 0
store i64 0, i64* %132
%133 = load i32, i32* @TIMER_ABSTIME
%134 = load i32, i32* %19
%135 = or i32 %134, %133
store i32 %135, i32* %19
%136 = load i32, i32* %15
%137 = load i32, i32* %19
%138 = call i64 @timer_settime(i32 %136, i32 %137, %struct.itimerspec* %16, i32* null)
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %142
140: ; preds = %119
%141 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %167
142: ; preds = %119
%143 = call i32 @sigwait(i32* %17, i32* %18)
%144 = icmp eq i32 %143, -1
br i1 %144, label %145, label %147
145: ; preds = %142
%146 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %167
147: ; preds = %142
%148 = load i32, i32* %18
%149 = load i32, i32* @SIGALRM
%150 = icmp ne i32 %148, %149
br i1 %150, label %151, label %153
151: ; preds = %147
%152 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %167
153: ; preds = %147
%154 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%155 = call i32 @wait(i32* %20)
%156 = icmp eq i32 %155, -1
br i1 %156, label %157, label %159
157: ; preds = %153
%158 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0))
store i32 2, i32* %3
br label %167
159: ; preds = %153
%160 = load i32, i32* %20
%161 = call i64 @WEXITSTATUS(i32 %160)
%162 = icmp ne i64 %161, 0
br i1 %162, label %163, label %165
163: ; preds = %159
%164 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %3
br label %167
165: ; preds = %159
%166 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
store i32 1, i32* %3
br label %167
167: ; preds = %165, %163, %157, %151, %145, %140, %117, %107, %101, %95, %90, %88, %82, %77, %54, %44, %38, %32, %24
%168 = load i32, i32* %3
ret i32 %168
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
%struct.sigevent = type { i32, i8* }
%struct.itimerspec = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [40 x i8] c"clock_gettime() did not return success\0A\00"
@.str.1 = [22 x i8] c"sigemptyset() failed\0A\00"
@SIGABRT = global i32 0
@.str.2 = [20 x i8] c"sigaddset() failed\0A\00"
@SIG_BLOCK = global i32 0
@.str.3 = [22 x i8] c"sigprocmask() failed\0A\00"
@SIGEV_SIGNAL = global i8* null
@.str.4 = [39 x i8] c"timer_create() did not return success\0A\00"
@TIMER_ABSTIME = global i32 0
@.str.5 = [40 x i8] c"timer_settime() did not return success\0A\00"
@.str.6 = [18 x i8] c"sigwait() failed\0A\00"
@SIGALRM = global i32 0
@.str.9 = [23 x i8] c"sigaprocmask() failed\0A\00"
@.str.12 = [33 x i8] c"Error waiting for child to exit\0A\00"
@str = [15 x i8] c"Got it! Parent\00"
@str.15 = [12 x i8] c"Test FAILED\00"
@str.16 = [12 x i8] c"Test PASSED\00"
@str.17 = [27 x i8] c"Got another signal! Parent\00"
@str.18 = [26 x i8] c"Got another signal! Child\00"
@str.19 = [14 x i8] c"Got it! Child\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.sigevent
%5 = alloca i32
%6 = alloca %struct.itimerspec
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sigevent
%10 = alloca i32
%11 = alloca %struct.itimerspec
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = bitcast %struct.timespec* %3 to i8*
%16 = load i32, i32* @CLOCK_REALTIME
%17 = call i64 @clock_gettime(i32 %16, %struct.timespec* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %161
21: ; preds = %2
%22 = call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %86
24: ; preds = %21
%25 = bitcast %struct.sigevent* %4 to i8*
%26 = bitcast i32* %5 to i8*
%27 = bitcast %struct.itimerspec* %6 to i8*
%28 = bitcast i32* %7 to i8*
%29 = bitcast i32* %8 to i8*
%30 = call i32 @sigemptyset(i32* %7)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %84
34: ; preds = %24
%35 = load i32, i32* @SIGABRT
%36 = call i32 @sigaddset(i32* %7, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %84
40: ; preds = %34
%41 = load i32, i32* @SIG_BLOCK
%42 = call i32 @sigprocmask(i32 %41, i32* %7, i32* null)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %84
46: ; preds = %40
%47 = load i8*, i8** @SIGEV_SIGNAL
%48 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %4, i64 0, i32 1
store i8* %47, i8** %48
%49 = load i32, i32* @SIGABRT
%50 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %4, i64 0, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* @CLOCK_REALTIME
%52 = call i64 @timer_create(i32 %51, %struct.sigevent* %4, i32* %5)
%53 = icmp eq i64 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %46
%55 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %84
56: ; preds = %46
%57 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%58 = load i64, i64* %57
%59 = add nsw i64 %58, 2
%60 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %6, i64 0, i32 1, i32 1
store i64 %59, i64* %60
%61 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %6, i64 0, i32 1, i32 0
store i32 %62, i32* %63
%64 = bitcast %struct.itimerspec* %6 to i8*
%65 = load i32, i32* @TIMER_ABSTIME
%66 = load i32, i32* %5
%67 = call i64 @timer_settime(i32 %66, i32 %65, %struct.itimerspec* %6, i32* null)
%68 = icmp eq i64 %67, 0
br i1 %68, label %71, label %69
69: ; preds = %56
%70 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %84
71: ; preds = %56
%72 = call i32 @sigwait(i32* %7, i32* %8)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %71
%75 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %84
76: ; preds = %71
%77 = load i32, i32* %8
%78 = load i32, i32* @SIGABRT
%79 = icmp eq i32 %77, %78
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.19, i64 0, i64 0))
br label %84
82: ; preds = %76
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.18, i64 0, i64 0))
br label %84
84: ; preds = %82, %80, %74, %69, %54, %44, %38, %32
%85 = phi i32 [ 2, %32 ], [ 2, %38 ], [ 2, %44 ], [ 2, %54 ], [ 2, %69 ], [ 2, %74 ], [ 1, %80 ], [ 1, %82 ]
br label %161
86: ; preds = %21
%87 = bitcast %struct.sigevent* %9 to i8*
%88 = bitcast i32* %10 to i8*
%89 = bitcast %struct.itimerspec* %11 to i8*
%90 = bitcast i32* %12 to i8*
%91 = bitcast i32* %13 to i8*
%92 = bitcast i32* %14 to i8*
%93 = call i32 @sigemptyset(i32* %12)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %86
%96 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %159
97: ; preds = %86
%98 = load i32, i32* @SIGALRM
%99 = call i32 @sigaddset(i32* %12, i32 %98)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %159
103: ; preds = %97
%104 = load i32, i32* @SIG_BLOCK
%105 = call i32 @sigprocmask(i32 %104, i32* %12, i32* null)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %109
107: ; preds = %103
%108 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %159
109: ; preds = %103
%110 = load i8*, i8** @SIGEV_SIGNAL
%111 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %9, i64 0, i32 1
store i8* %110, i8** %111
%112 = load i32, i32* @SIGALRM
%113 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %9, i64 0, i32 0
store i32 %112, i32* %113
%114 = load i32, i32* @CLOCK_REALTIME
%115 = call i64 @timer_create(i32 %114, %struct.sigevent* %9, i32* %10)
%116 = icmp eq i64 %115, 0
br i1 %116, label %119, label %117
117: ; preds = %109
%118 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %159
119: ; preds = %109
%120 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%121 = load i64, i64* %120
%122 = add nsw i64 %121, 2
%123 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %11, i64 0, i32 1, i32 1
store i64 %122, i64* %123
%124 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%125 = load i32, i32* %124
%126 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %11, i64 0, i32 1, i32 0
store i32 %125, i32* %126
%127 = bitcast %struct.itimerspec* %11 to i8*
%128 = load i32, i32* @TIMER_ABSTIME
%129 = load i32, i32* %10
%130 = call i64 @timer_settime(i32 %129, i32 %128, %struct.itimerspec* %11, i32* null)
%131 = icmp eq i64 %130, 0
br i1 %131, label %134, label %132
132: ; preds = %119
%133 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %159
134: ; preds = %119
%135 = call i32 @sigwait(i32* %12, i32* %13)
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %139
137: ; preds = %134
%138 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %159
139: ; preds = %134
%140 = load i32, i32* %13
%141 = load i32, i32* @SIGALRM
%142 = icmp eq i32 %140, %141
br i1 %142, label %145, label %143
143: ; preds = %139
%144 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.17, i64 0, i64 0))
br label %159
145: ; preds = %139
%146 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%147 = call i32 @wait(i32* %14)
%148 = icmp eq i32 %147, -1
br i1 %148, label %149, label %151
149: ; preds = %145
%150 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0))
br label %159
151: ; preds = %145
%152 = load i32, i32* %14
%153 = call i64 @WEXITSTATUS(i32 %152)
%154 = icmp eq i64 %153, 0
br i1 %154, label %157, label %155
155: ; preds = %151
%156 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.16, i64 0, i64 0))
br label %159
157: ; preds = %151
%158 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0))
br label %159
159: ; preds = %157, %155, %149, %143, %137, %132, %117, %107, %101, %95
%160 = phi i32 [ 2, %95 ], [ 2, %101 ], [ 2, %107 ], [ 2, %117 ], [ 2, %132 ], [ 2, %137 ], [ 1, %143 ], [ 2, %149 ], [ 0, %155 ], [ 1, %157 ]
br label %161
161: ; preds = %159, %84, %19
%162 = phi i32 [ 2, %19 ], [ %85, %84 ], [ %160, %159 ]
ret i32 %162
}