#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 sigevent {
  int /*<<< orphan*/ sigev_signo;
  int /*<<< orphan*/ sigev_notify;
};
struct TYPE_4__ {
  int tv_sec;
  scalar_t__ tv_nsec;
};
struct TYPE_3__ {
  int tv_sec;
  scalar_t__ tv_nsec;
};
struct itimerspec {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ SIGCONT;
int /*<<< orphan*/ SIGEV_SIGNAL;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
scalar_t__ timer_create(int /*<<< orphan*/, struct sigevent *,
                        int /*<<< orphan*/ *);
int timer_getoverrun(int /*<<< orphan*/);
scalar_t__ timer_settime(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct itimerspec *, int /*<<< orphan*/ *);
int main(void) {
  sigset_t set;
  struct sigevent ev;
  timer_t tid;
  struct itimerspec its;
  int overruns;
  if (sigemptyset(&set) != 0) {
    perror("sigemptyset() did not return success\n");
    return 2;
  }
  if (sigaddset(&set, SIGCONT) != 0) {
    perror("sigaddset() did not return success\n");
    return 2;
  }
  if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) {
    perror("sigprocmask() did not return success\n");
    return 2;
  }
  ev.sigev_notify = SIGEV_SIGNAL;
  ev.sigev_signo = SIGCONT;
  if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
    perror("timer_create() did not return success\n");
    return 2;
  }
  its.it_interval.tv_sec = 4;
  its.it_interval.tv_nsec = 0;
  its.it_value.tv_sec = 3;
  its.it_value.tv_nsec = 0;
  if (timer_settime(tid, 0, &its, NULL) != 0) {
    perror("timer_settime() did not return success\n");
    return 2;
  }
  sleep(3 + 2 * 4 + 1);
  if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) {
    perror("sigprocmask() did not return success\n");
    return 2;
  }
  overruns = timer_getoverrun(tid);
  if (2 == overruns) {
    printf("Test PASSED\n");
    return 0;
  } else {
    printf("FAIL:  %d overruns sent; expected %d\n", overruns, 2);
    return 1;
  }
  printf("UNRESOLVED:  This code should not be executed.\n");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <sigemptyset@plt>
cmp    $0x0,%rax
je     11ca <main+0x3a>
lea    0xe47(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10b0 <sigaddset@plt>
cmp    $0x0,%rax
je     11fe <main+0x6e>
lea    0xe39(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0x0,%rax
je     1236 <main+0xa6>
lea    0xe25(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <timer_create@plt>
cmp    $0x0,%rax
je     1286 <main+0xf6>
lea    0xdfb(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
movl   $0x4,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x3,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
lea    -0x38(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     12d8 <main+0x148>
lea    0xdd0(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    $0xc,%edi
call   10a0 <sleep@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0x0,%rax
je     131a <main+0x18a>
lea    0xd41(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    -0x14(%rbp),%edi
call   1080 <timer_getoverrun@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x2,%eax
cmp    -0x3c(%rbp),%eax
jne    134d <main+0x1bd>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    -0x3c(%rbp),%esi
lea    0xd75(%rip),%rdi
mov    $0x2,%edx
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    %rsp,%rdi
call   1080 <sigemptyset@plt>
test   %rax,%rax
jne    12c2 <main+0x122>
mov    0x2e23(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rdi
call   10c0 <sigaddset@plt>
test   %rax,%rax
jne    12cb <main+0x12b>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
test   %rax,%rax
jne    12b9 <main+0x119>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1060 <timer_create@plt>
test   %rax,%rax
jne    12d4 <main+0x134>
movl   $0x4,0x20(%rsp)
movq   $0x0,0x28(%rsp)
movl   $0x3,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rdx
xor    %esi,%esi
xor    %ecx,%ecx
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    12dd <main+0x13d>
mov    $0xc,%edi
call   10b0 <sleep@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
test   %rax,%rax
jne    12b9 <main+0x119>
mov    0x4(%rsp),%edi
call   1090 <timer_getoverrun@plt>
cmp    $0x2,%eax
jne    129d <main+0xfd>
lea    0xe51(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
jmp    12ee <main+0x14e>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    12ee <main+0x14e>
lea    0xd8a(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xd37(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xd54(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xd95(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xdb3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sigevent = type { i32, i32 }
%struct.itimerspec = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i64 }
%struct.TYPE_3__ = type { i32, i64 }
@.str = [38 x i8] c"sigemptyset() did not return success\0A\00"
@SIGCONT = global i32 0
@.str.1 = [36 x i8] c"sigaddset() did not return success\0A\00"
@SIG_SETMASK = global i32 0
@.str.2 = [38 x i8] c"sigprocmask() did not return success\0A\00"
@SIGEV_SIGNAL = global i32 0
@CLOCK_REALTIME = global i32 0
@.str.3 = [39 x i8] c"timer_create() did not return success\0A\00"
@.str.4 = [40 x i8] c"timer_settime() did not return success\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.5 = [13 x i8] c"Test PASSED\0A\00"
@.str.6 = [38 x i8] c"FAIL: %d overruns sent; expected %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sigevent
%4 = alloca i32
%5 = alloca %struct.itimerspec
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @sigemptyset(i32* %2)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %64
11: ; preds = %0
%12 = load i32, i32* @SIGCONT
%13 = call i64 @sigaddset(i32* %2, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %64
17: ; preds = %11
%18 = load i32, i32* @SIG_SETMASK
%19 = call i64 @sigprocmask(i32 %18, i32* %2, i32* null)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %64
23: ; preds = %17
%24 = load i32, i32* @SIGEV_SIGNAL
%25 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %3, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @SIGCONT
%27 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %3, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @CLOCK_REALTIME
%29 = call i64 @timer_create(i32 %28, %struct.sigevent* %3, i32* %4)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %64
33: ; preds = %23
%34 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
store i32 4, i32* %35
%36 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %36, i32 0, i32 1
store i64 0, i64* %37
%38 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %38, i32 0, i32 0
store i32 3, i32* %39
%40 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %40, i32 0, i32 1
store i64 0, i64* %41
%42 = load i32, i32* %4
%43 = call i64 @timer_settime(i32 %42, i32 0, %struct.itimerspec* %5, i32* null)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %33
%46 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %1
br label %64
47: ; preds = %33
%48 = call i32 @sleep(i32 12)
%49 = load i32, i32* @SIG_UNBLOCK
%50 = call i64 @sigprocmask(i32 %49, i32* %2, i32* null)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %64
54: ; preds = %47
%55 = load i32, i32* %4
%56 = call i32 @timer_getoverrun(i32 %55)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp eq i32 2, %57
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %64
61: ; preds = %54
%62 = load i32, i32* %6
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %62, i32 2)
store i32 1, i32* %1
br label %64
64: ; preds = %61, %59, %52, %45, %31, %21, %15, %9
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
%struct.sigevent = type { i32, i32 }
%struct.itimerspec = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i64 }
%struct.TYPE_3__ = type { i32, i64 }
@.str = [38 x i8] c"sigemptyset() did not return success\0A\00"
@SIGCONT = global i32 0
@.str.1 = [36 x i8] c"sigaddset() did not return success\0A\00"
@SIG_SETMASK = global i32 0
@.str.2 = [38 x i8] c"sigprocmask() did not return success\0A\00"
@SIGEV_SIGNAL = global i32 0
@CLOCK_REALTIME = global i32 0
@.str.3 = [39 x i8] c"timer_create() did not return success\0A\00"
@.str.4 = [40 x i8] c"timer_settime() did not return success\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.6 = [38 x i8] c"FAIL: %d overruns sent; expected %d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigevent
%3 = alloca i32
%4 = alloca %struct.itimerspec
%5 = bitcast i32* %1 to i8*
%6 = bitcast %struct.sigevent* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.itimerspec* %4 to i8*
%9 = call i64 @sigemptyset(i32* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %60
13: ; preds = %0
%14 = load i32, i32* @SIGCONT
%15 = call i64 @sigaddset(i32* %1, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %60
19: ; preds = %13
%20 = load i32, i32* @SIG_SETMASK
%21 = call i64 @sigprocmask(i32 %20, i32* %1, i32* null)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %60
25: ; preds = %19
%26 = load i32, i32* @SIGEV_SIGNAL
%27 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @SIGCONT
%29 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i64 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* @CLOCK_REALTIME
%31 = call i64 @timer_create(i32 %30, %struct.sigevent* %2, i32* %3)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %25
%34 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %60
35: ; preds = %25
%36 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 1, i32 0
store i32 4, i32* %36
%37 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 1, i32 1
store i64 0, i64* %37
%38 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 0, i32 0
store i32 3, i32* %38
%39 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 0, i32 1
store i64 0, i64* %39
%40 = load i32, i32* %3
%41 = call i64 @timer_settime(i32 %40, i32 0, %struct.itimerspec* %4, i32* null)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %35
%44 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %60
45: ; preds = %35
%46 = call i32 @sleep(i32 12)
%47 = load i32, i32* @SIG_UNBLOCK
%48 = call i64 @sigprocmask(i32 %47, i32* %1, i32* null)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %60
52: ; preds = %45
%53 = load i32, i32* %3
%54 = call i32 @timer_getoverrun(i32 %53)
%55 = icmp eq i32 %54, 2
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %60
58: ; preds = %52
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %54, i32 2)
br label %60
60: ; preds = %58, %56, %50, %43, %33, %23, %17, %11
%61 = phi i32 [ 2, %11 ], [ 2, %17 ], [ 2, %23 ], [ 2, %33 ], [ 2, %43 ], [ 2, %50 ], [ 0, %56 ], [ 1, %58 ]
ret i32 %61
}