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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ SIGCONT;
int /*<<< orphan*/ SIGEV_SIGNAL;
int TIMER_ABSTIME;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ timer_create(int /*<<< orphan*/, struct sigevent *,
                        int /*<<< orphan*/ *);
scalar_t__ timer_gettime(int /*<<< orphan*/, struct itimerspec *);
scalar_t__ timer_settime(int /*<<< orphan*/, int, struct itimerspec *,
                         int /*<<< orphan*/ *);
int main(void) {
  struct sigevent ev;
  timer_t tid;
  struct itimerspec itsset, itsget;
  struct timespec ts;
  int flags = 0;
  int delta;
  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;
  }
  if (clock_gettime(CLOCK_REALTIME, &ts) != 0) {
    perror("clock_gettime() did not return success\n");
    return 2;
  }
  itsset.it_interval.tv_sec = 0;
  itsset.it_interval.tv_nsec = 0;
  itsset.it_value.tv_sec = ts.tv_sec + 2;
  itsset.it_value.tv_nsec = ts.tv_nsec;
  flags |= TIMER_ABSTIME;
  if (timer_settime(tid, flags, &itsset, NULL) != 0) {
    perror("timer_settime() did not return success\n");
    return 2;
  }
  if (timer_gettime(tid, &itsget) != 0) {
    perror("timer_gettime() did not return success\n");
    return 2;
  }
  delta = 2 - itsget.it_value.tv_sec;
  if (delta < 0) {
    printf("FAIL:  timer_gettime() value > timer_settime()\n");
    printf("%d > %d\n", (int)itsget.it_value.tv_sec,
           (int)itsset.it_value.tv_sec);
    return 1;
  }
  if (delta <= 1) {
    printf("Test PASSED\n");
    return 0;
  }
  printf("FAIL:  timer_gettime() value !~= timer_settime()\n");
  printf("%d !~= %d\n", (int)itsget.it_value.tv_sec,
         (int)itsset.it_value.tv_sec);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x54(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <timer_create@plt>
cmp    $0x0,%rax
je     11c6 <main+0x66>
lea    0xe4b(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    131b <main+0x1bb>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
je     11fa <main+0x9a>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    131b <main+0x1bb>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x50(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
or     -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x54(%rbp),%esi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     125d <main+0xfd>
lea    0xe03(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    131b <main+0x1bb>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1070 <timer_gettime@plt>
cmp    $0x0,%rax
je     128b <main+0x12b>
lea    0xdfd(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    131b <main+0x1bb>
mov    $0x2,%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    12ce <main+0x16e>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131b <main+0x1bb>
cmpl   $0x1,-0x58(%rbp)
jg     12f2 <main+0x192>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    131b <main+0x1bb>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e32(%rip),%rbx
mov    (%rbx),%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1060 <timer_create@plt>
test   %rax,%rax
jne    1278 <main+0x108>
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1050 <clock_gettime@plt>
test   %rax,%rax
jne    1281 <main+0x111>
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%ecx
add    $0x2,%eax
mov    %eax,0x20(%rsp)
mov    %ecx,0x24(%rsp)
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rdx
xor    %ecx,%ecx
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    128a <main+0x11a>
mov    0xc(%rsp),%edi
lea    0x38(%rsp),%rsi
call   1080 <timer_gettime@plt>
test   %rax,%rax
jne    1293 <main+0x123>
mov    0x38(%rsp),%eax
cmp    $0x3,%eax
jl     123b <main+0xcb>
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
mov    0x38(%rsp),%esi
mov    0x20(%rsp),%edx
lea    0xe66(%rip),%rdi
jmp    126a <main+0xfa>
test   %eax,%eax
jle    124f <main+0xdf>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    12a4 <main+0x134>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
mov    0x38(%rsp),%esi
mov    0x20(%rsp),%edx
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    12a4 <main+0x134>
lea    0xd81(%rip),%rdi
jmp    129a <main+0x12a>
lea    0xd9f(%rip),%rdi
jmp    129a <main+0x12a>
lea    0xdbe(%rip),%rdi
jmp    129a <main+0x12a>
lea    0xddd(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%eax
add    $0x50,%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, i32 }
%struct.TYPE_3__ = type { i64, i64 }
%struct.timespec = type { i32, i32 }
@SIGEV_SIGNAL = global i32 0
@SIGCONT = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [39 x i8] c"timer_create() did not return success\0A\00"
@.str.1 = [40 x i8] c"clock_gettime() did not return success\0A\00"
@TIMER_ABSTIME = global i32 0
@.str.2 = [40 x i8] c"timer_settime() did not return success\0A\00"
@.str.3 = [40 x i8] c"timer_gettime() did not return success\0A\00"
@.str.4 = [48 x i8] c"FAIL: timer_gettime() value > timer_settime()\0A\00"
@.str.5 = [9 x i8] c"%d > %d\0A\00"
@.str.6 = [13 x i8] c"Test PASSED\0A\00"
@.str.7 = [50 x i8] c"FAIL: timer_gettime() value !~= timer_settime()\0A\00"
@.str.8 = [11 x i8] c"%d !~= %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigevent
%3 = alloca i32
%4 = alloca %struct.itimerspec
%5 = alloca %struct.itimerspec
%6 = alloca %struct.timespec
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
%9 = load i32, i32* @SIGEV_SIGNAL
%10 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @SIGCONT
%12 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i64 @timer_create(i32 %13, %struct.sigevent* %2, i32* %3)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %83
18: ; preds = %0
%19 = load i32, i32* @CLOCK_REALTIME
%20 = call i64 @clock_gettime(i32 %19, %struct.timespec* %6)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %83
24: ; preds = %18
%25 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
store i64 0, i64* %26
%27 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 0
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 2
%32 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 1
store i32 %35, i32* %37
%38 = load i32, i32* @TIMER_ABSTIME
%39 = load i32, i32* %7
%40 = or i32 %39, %38
store i32 %40, i32* %7
%41 = load i32, i32* %3
%42 = load i32, i32* %7
%43 = call i64 @timer_settime(i32 %41, i32 %42, %struct.itimerspec* %4, i32* null)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %24
%46 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %83
47: ; preds = %24
%48 = load i32, i32* %3
%49 = call i64 @timer_gettime(i32 %48, %struct.itimerspec* %5)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %83
53: ; preds = %47
%54 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = sub nsw i32 2, %56
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %53
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%62 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%63 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%66 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %64, i32 %67)
store i32 1, i32* %1
br label %83
69: ; preds = %53
%70 = load i32, i32* %8
%71 = icmp sle i32 %70, 1
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %83
74: ; preds = %69
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
%76 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%77 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%80 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %78, i32 %81)
store i32 1, i32* %1
br label %83
83: ; preds = %74, %72, %60, %51, %45, %22, %16
%84 = load i32, i32* %1
ret i32 %84
}

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