#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__ {
  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 /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sleep(int);
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 /*<<< orphan*/,
                         struct itimerspec *, int /*<<< orphan*/ *);
int main(void) {
  struct sigevent ev;
  timer_t tid;
  struct itimerspec itsset, itsget;
  int delta;
  ev.sigev_notify = SIGEV_SIGNAL;
  ev.sigev_signo = SIGCONT;
  itsset.it_interval.tv_sec = 0;
  itsset.it_interval.tv_nsec = 0;
  itsset.it_value.tv_sec = 8;
  itsset.it_value.tv_nsec = 0;
  if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
    perror("timer_create() did not return success\n");
    return 2;
  }
  if (timer_settime(tid, 0, &itsset, NULL) != 0) {
    perror("timer_settime() did not return success\n");
    return 2;
  }
  if (sleep(2) != 0) {
    perror("sleep() did not return 0\n");
    return 2;
  }
  if (timer_gettime(tid, &itsget) != 0) {
    perror("timer_gettime() did not return success\n");
    return 2;
  }
  delta = (itsset.it_value.tv_sec - 2) - itsget.it_value.tv_sec;
  if (delta < 0) {
    printf("FAIL:  timer_gettime() value > time expected left\n");
    printf("%d > %d\n", (int)itsget.it_value.tv_sec,
           (int)itsset.it_value.tv_sec - 2);
    return 1;
  }
  if (delta <= 1) {
    printf("Test PASSED\n");
    return 0;
  } else {
    printf("FAIL:  timer_gettime() value !~= time expected left\n");
    printf("%d !~= %d\n", (int)itsget.it_value.tv_sec,
           (int)itsset.it_value.tv_sec - 2);
    return 1;
  }
  printf("This code should not be executed\n");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x8,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <timer_create@plt>
cmp    $0x0,%rax
je     11de <main+0x7e>
lea    0xe33(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1303 <main+0x1a3>
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     1212 <main+0xb2>
lea    0xe26(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1303 <main+0x1a3>
mov    $0x2,%edi
call   1080 <sleep@plt>
cmp    $0x0,%rax
je     123e <main+0xde>
lea    0xe22(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1303 <main+0x1a3>
mov    -0x14(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   1060 <timer_gettime@plt>
cmp    $0x0,%rax
je     126c <main+0x10c>
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1303 <main+0x1a3>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
sub    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    12b3 <main+0x153>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%esi
mov    -0x38(%rbp),%edx
sub    $0x2,%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1303 <main+0x1a3>
cmpl   $0x1,-0x5c(%rbp)
jg     12d7 <main+0x177>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1303 <main+0x1a3>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%esi
mov    -0x38(%rbp),%edx
sub    $0x2,%edx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <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    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
movl   $0x8,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1050 <timer_create@plt>
test   %rax,%rax
jne    1287 <main+0x117>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rdx
xor    %esi,%esi
xor    %ecx,%ecx
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    1290 <main+0x120>
mov    $0x2,%ebx
mov    $0x2,%edi
call   1090 <sleep@plt>
test   %rax,%rax
jne    12a3 <main+0x133>
mov    0x4(%rsp),%edi
lea    0x30(%rsp),%rsi
call   1070 <timer_gettime@plt>
test   %rax,%rax
jne    12b1 <main+0x141>
mov    0x10(%rsp),%eax
sub    0x30(%rsp),%eax
add    $0xfffffffe,%eax
js     1235 <main+0xc5>
cmp    $0x1,%eax
ja     1255 <main+0xe5>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    127f <main+0x10f>
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
mov    0x30(%rsp),%esi
mov    0x10(%rsp),%edx
add    $0xfffffffe,%edx
lea    0xe3e(%rip),%rdi
jmp    1273 <main+0x103>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
mov    0x30(%rsp),%esi
mov    0x10(%rsp),%edx
add    $0xfffffffe,%edx
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
ret
lea    0xd72(%rip),%rdi
jmp    1297 <main+0x127>
lea    0xd90(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%ebx
jmp    127f <main+0x10f>
lea    0xda5(%rip),%rdi
call   1080 <perror@plt>
jmp    127f <main+0x10f>
lea    0xdb1(%rip),%rdi
call   1080 <perror@plt>
jmp    127f <main+0x10f>

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 { i64, i64 }
@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"timer_settime() did not return success\0A\00"
@.str.2 = [26 x i8] c"sleep() did not return 0\0A\00"
@.str.3 = [40 x i8] c"timer_gettime() did not return success\0A\00"
@.str.4 = [51 x i8] c"FAIL: timer_gettime() value > time expected left\0A\00"
@.str.5 = [9 x i8] c"%d > %d\0A\00"
@.str.6 = [13 x i8] c"Test PASSED\0A\00"
@.str.7 = [53 x i8] c"FAIL: timer_gettime() value !~= time expected left\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 i32
store i32 0, i32* %1
%7 = load i32, i32* @SIGEV_SIGNAL
%8 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @SIGCONT
%10 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 0
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 1
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
store i32 8, i32* %16
%17 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 1
store i64 0, i64* %18
%19 = load i32, i32* @CLOCK_REALTIME
%20 = call i64 @timer_create(i32 %19, %struct.sigevent* %2, i32* %3)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %77
24: ; preds = %0
%25 = load i32, i32* %3
%26 = call i64 @timer_settime(i32 %25, i32 0, %struct.itimerspec* %4, i32* null)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = 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 %77
30: ; preds = %24
%31 = call i64 @sleep(i32 2)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %77
35: ; preds = %30
%36 = load i32, i32* %3
%37 = call i64 @timer_gettime(i32 %36, %struct.itimerspec* %5)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = 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 %77
41: ; preds = %35
%42 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = sub nsw i32 %44, 2
%46 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = sub nsw i32 %45, %48
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %62
52: ; preds = %41
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%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 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = sub nsw i32 %59, 2
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %56, i32 %60)
store i32 1, i32* %1
br label %77
62: ; preds = %41
%63 = load i32, i32* %6
%64 = icmp sle i32 %63, 1
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = 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 %77
67: ; preds = %62
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0))
%69 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%73 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = sub nsw i32 %74, 2
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %71, i32 %75)
store i32 1, i32* %1
br label %77
77: ; preds = %67, %65, %52, %39, %33, %28, %22
%78 = load i32, i32* %1
ret i32 %78
}

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