#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__ {
  scalar_t__ tv_sec;
  scalar_t__ tv_nsec;
};
struct TYPE_3__ {
  int tv_sec;
  scalar_t__ tv_nsec;
};
struct itimerspec {
  TYPE_2__ it_interval;
  TYPE_1__ it_value;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ SIGCONT;
int /*<<< orphan*/ SIGEV_SIGNAL;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ timer_create(int /*<<< orphan*/, struct sigevent *,
                        int /*<<< orphan*/ *);
scalar_t__ timer_settime(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct itimerspec *, struct itimerspec *);
int main(void) {
  struct sigevent ev;
  timer_t tid;
  struct itimerspec its, oits;
  ev.sigev_notify = SIGEV_SIGNAL;
  ev.sigev_signo = SIGCONT;
  its.it_interval.tv_sec = 0;
  its.it_interval.tv_nsec = 0;
  its.it_value.tv_sec = 1;
  its.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, &its, &oits) != 0) {
    perror("timer_settime() did not return success\n");
    return 2;
  }
  if ((0 == oits.it_value.tv_sec) && (0 == oits.it_value.tv_nsec) &&
      (0 == oits.it_interval.tv_sec) && (0 == oits.it_interval.tv_nsec)) {
    printf("Test PASSED\n");
    return 0;
  } else {
    printf("Test FAILED:  value: tv_sec %d tv_nsec %d\n",
           (int)oits.it_value.tv_sec, (int)oits.it_value.tv_nsec);
    printf("Test FAILED:  interval: tv_sec %d tv_nsec %d\n",
           (int)oits.it_interval.tv_sec, (int)oits.it_interval.tv_nsec);
    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    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <timer_create@plt>
cmp    $0x0,%rax
je     11be <main+0x7e>
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1273 <main+0x133>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
lea    -0x38(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     11f2 <main+0xb2>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1273 <main+0x133>
xor    %eax,%eax
cmp    -0x48(%rbp),%eax
jne    123b <main+0xfb>
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    123b <main+0xfb>
xor    %eax,%eax
cmp    -0x58(%rbp),%rax
jne    123b <main+0xfb>
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
jne    123b <main+0xfb>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1273 <main+0x133>
mov    -0x48(%rbp),%esi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    -0x50(%rbp),%rax
mov    %eax,%edx
lea    0xe22(%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>:
sub    $0x58,%rsp
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x1,0x40(%rsp)
movq   $0x0,0x48(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1050 <timer_create@plt>
test   %rax,%rax
jne    1221 <main+0xd1>
mov    0x4(%rsp),%edi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %esi,%esi
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    122a <main+0xda>
mov    0x20(%rsp),%esi
mov    0x28(%rsp),%rdx
test   %esi,%esi
jne    11f3 <main+0xa3>
test   %rdx,%rdx
jne    11f3 <main+0xa3>
cmpq   $0x0,0x10(%rsp)
jne    11f3 <main+0xa3>
cmpq   $0x0,0x18(%rsp)
jne    11f3 <main+0xa3>
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
ret
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x18(%rsp),%edx
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x58,%rsp
ret
lea    0xdd8(%rip),%rdi
jmp    1231 <main+0xe1>
lea    0xdf6(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%eax
add    $0x58,%rsp
ret

LLVM IR (-O0):
%struct.sigevent = type { i32, i32 }
%struct.itimerspec = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32, 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 = [13 x i8] c"Test PASSED\0A\00"
@.str.3 = [43 x i8] c"Test FAILED: value: tv_sec %d tv_nsec %d\0A\00"
@.str.4 = [46 x i8] c"Test FAILED: interval: tv_sec %d tv_nsec %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigevent
%3 = alloca i32
%4 = alloca %struct.itimerspec
%5 = alloca %struct.itimerspec
store i32 0, i32* %1
%6 = load i32, i32* @SIGEV_SIGNAL
%7 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @SIGCONT
%9 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 0
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
store i32 1, i32* %15
%16 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
store i64 0, i64* %17
%18 = load i32, i32* @CLOCK_REALTIME
%19 = call i64 @timer_create(i32 %18, %struct.sigevent* %2, i32* %3)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %69
23: ; preds = %0
%24 = load i32, i32* %3
%25 = call i64 @timer_settime(i32 %24, i32 0, %struct.itimerspec* %4, %struct.itimerspec* %5)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = 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 %69
29: ; preds = %23
%30 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = icmp eq i32 0, %32
br i1 %33, label %34, label %51
34: ; preds = %29
%35 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 1
%37 = load i64, i64* %36
%38 = icmp eq i64 0, %37
br i1 %38, label %39, label %51
39: ; preds = %34
%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 0
%42 = load i64, i64* %41
%43 = icmp eq i64 0, %42
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %45, i32 0, i32 1
%47 = load i64, i64* %46
%48 = icmp eq i64 0, %47
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %69
51: ; preds = %44, %39, %34, %29
%52 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%53 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%56 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i32 0, i32 1
%57 = load i64, i64* %56
%58 = trunc i64 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %54, i32 %58)
%60 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%61 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %60, i32 0, i32 0
%62 = load i64, i64* %61
%63 = trunc i64 %62 to i32
%64 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%65 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %64, i32 0, i32 1
%66 = load i64, i64* %65
%67 = trunc i64 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %63, i32 %67)
store i32 1, i32* %1
br label %69
69: ; preds = %51, %49, %27, %21
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
%struct.sigevent = type { i32, i32 }
%struct.itimerspec = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32, 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.3 = [43 x i8] c"Test FAILED: value: tv_sec %d tv_nsec %d\0A\00"
@.str.4 = [46 x i8] c"Test FAILED: interval: tv_sec %d tv_nsec %d\0A\00"
@str = [12 x i8] c"Test PASSED\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 = bitcast %struct.itimerspec* %3 to i8*
store i32 1, i32* %13
%15 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %3, i64 0, i32 1, i32 1
store i64 0, i64* %15
%16 = load i32, i32* @CLOCK_REALTIME
%17 = call i64 @timer_create(i32 %16, %struct.sigevent* %1, i32* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %53
21: ; preds = %0
%22 = load i32, i32* %2
%23 = call i64 @timer_settime(i32 %22, i32 0, %struct.itimerspec* %3, %struct.itimerspec* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %53
27: ; preds = %21
%28 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 1, i32 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
%31 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 1, i32 1
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, 0
%34 = select i1 %30, i1 %33, i1 false
%35 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 0, i32 0
%36 = load i64, i64* %35
%37 = icmp eq i64 %36, 0
%38 = select i1 %34, i1 %37, i1 false
%39 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i64 0, i32 0, i32 1
%40 = load i64, i64* %39
%41 = icmp eq i64 %40, 0
%42 = select i1 %38, i1 %41, i1 false
br i1 %42, label %43, label %45
43: ; preds = %27
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %53
45: ; preds = %27
%46 = trunc i64 %32 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %46)
%48 = load i64, i64* %35
%49 = trunc i64 %48 to i32
%50 = load i64, i64* %39
%51 = trunc i64 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %49, i32 %51)
br label %53
53: ; preds = %45, %43, %25, %19
%54 = phi i32 [ 2, %19 ], [ 2, %25 ], [ 0, %43 ], [ 1, %45 ]
ret i32 %54
}