#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;
  int tv_nsec;
};
struct TYPE_3__ {
  int tv_sec;
  int 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 *, ...);
int /*<<< orphan*/ sleep(int);
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;
  }
  sleep(1 + 1);
  oits.it_value.tv_sec = 1000;
  oits.it_value.tv_nsec = 1000;
  oits.it_interval.tv_sec = 1000;
  oits.it_interval.tv_nsec = 1000;
  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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <timer_create@plt>
cmp    $0x0,%rax
je     11cb <main+0x7b>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ce <main+0x17e>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
lea    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     11ff <main+0xaf>
lea    0xe39(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ce <main+0x17e>
mov    $0x2,%edi
call   1070 <sleep@plt>
movl   $0x3e8,-0x30(%rbp)
movl   $0x3e8,-0x2c(%rbp)
movl   $0x3e8,-0x38(%rbp)
movl   $0x3e8,-0x34(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
lea    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <timer_settime@plt>
cmp    $0x0,%rax
je     1259 <main+0x109>
lea    0xddf(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ce <main+0x17e>
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
jne    129f <main+0x14f>
xor    %eax,%eax
cmp    -0x2c(%rbp),%eax
jne    129f <main+0x14f>
xor    %eax,%eax
cmp    -0x38(%rbp),%eax
jne    129f <main+0x14f>
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
jne    129f <main+0x14f>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ce <main+0x17e>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movdqa 0xe79(%rip),%xmm0
movdqa %xmm0,0x30(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0x28(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <timer_create@plt>
test   %rax,%rax
jne    1266 <main+0x106>
mov    0xc(%rsp),%edi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %esi,%esi
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    126f <main+0x10f>
mov    $0x2,%ebx
mov    $0x2,%edi
call   1080 <sleep@plt>
movdqa 0xe2d(%rip),%xmm0
movdqa %xmm0,0x10(%rsp)
mov    0xc(%rsp),%edi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %esi,%esi
call   1030 <timer_settime@plt>
test   %rax,%rax
jne    1282 <main+0x122>
movdqa 0x10(%rsp),%xmm0
pxor   %xmm1,%xmm1
pcmpeqd %xmm0,%xmm1
movmskps %xmm1,%eax
cmp    $0xf,%eax
je     1256 <main+0xf6>
pshufd $0xee,%xmm0,%xmm1
movd   %xmm1,%esi
pshufd $0xff,%xmm0,%xmm0
movd   %xmm0,%edx
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
jmp    128e <main+0x12e>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    128e <main+0x12e>
lea    0xdb3(%rip),%rdi
jmp    1276 <main+0x116>
lea    0xdd1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%ebx
jmp    128e <main+0x12e>
lea    0xdbe(%rip),%rdi
call   1070 <perror@plt>
mov    %ebx,%eax
add    $0x40,%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 { 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"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 i32 0, i32* %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 i32 0, i32* %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 i32 0, i32* %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 %81
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 %81
29: ; preds = %23
%30 = call i32 @sleep(i32 2)
%31 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 0
store i32 1000, i32* %32
%33 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 1
store i32 1000, i32* %34
%35 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %35, i32 0, i32 0
store i32 1000, i32* %36
%37 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %37, i32 0, i32 1
store i32 1000, i32* %38
%39 = load i32, i32* %3
%40 = call i64 @timer_settime(i32 %39, i32 0, %struct.itimerspec* %4, %struct.itimerspec* %5)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %29
%43 = 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 %81
44: ; preds = %29
%45 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = icmp eq i32 0, %47
br i1 %48, label %49, label %66
49: ; preds = %44
%50 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = icmp eq i32 0, %52
br i1 %53, label %54, label %66
54: ; preds = %49
%55 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = icmp eq i32 0, %57
br i1 %58, label %59, label %66
59: ; preds = %54
%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 1
%62 = load i32, i32* %61
%63 = icmp eq i32 0, %62
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = 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 %81
66: ; preds = %59, %54, %49, %44
%67 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 1
%71 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %69, i32 %72)
%74 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%75 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %5, i32 0, i32 0
%78 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %76, i32 %79)
store i32 1, i32* %1
br label %81
81: ; preds = %66, %64, %42, %27, %21
%82 = load i32, i32* %1
ret i32 %82
}

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 { 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"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 <4 x i32>
%4 = bitcast <4 x i32>* %3 to %struct.itimerspec*
%5 = alloca <4 x i32>
%6 = bitcast <4 x i32>* %5 to %struct.itimerspec*
%7 = bitcast %struct.sigevent* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast <4 x i32>* %3 to i8*
%10 = bitcast <4 x i32>* %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
store <4 x i32> <i32 0, i32 0, i32 1, i32 0>, <4 x i32>* %3
%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 %50
20: ; preds = %0
%21 = load i32, i32* %2
%22 = call i64 @timer_settime(i32 %21, i32 0, %struct.itimerspec* %4, %struct.itimerspec* %6)
%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 %50
26: ; preds = %20
%27 = call i32 @sleep(i32 2)
%28 = getelementptr inbounds <4 x i32>, <4 x i32>* %5, i64 0, i64 0
%29 = getelementptr inbounds <4 x i32>, <4 x i32>* %5, i64 0, i64 1
store <4 x i32> <i32 1000, i32 1000, i32 1000, i32 1000>, <4 x i32>* %5
%30 = load i32, i32* %2
%31 = call i64 @timer_settime(i32 %30, i32 0, %struct.itimerspec* %4, %struct.itimerspec* %6)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %50
35: ; preds = %26
%36 = load <4 x i32>, <4 x i32>* %5
%37 = freeze <4 x i32> %36
%38 = icmp ne <4 x i32> %37, zeroinitializer
%39 = bitcast <4 x i1> %38 to i4
%40 = icmp eq i4 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %50
43: ; preds = %35
%44 = extractelement <4 x i32> %37, i64 2
%45 = extractelement <4 x i32> %37, i64 3
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %45)
%47 = load i32, i32* %28
%48 = load i32, i32* %29
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %48)
br label %50
50: ; preds = %43, %41, %33, %24, %18
%51 = phi i32 [ 2, %18 ], [ 2, %24 ], [ 2, %33 ], [ 0, %41 ], [ 1, %43 ]
ret i32 %51
}