#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;
scalar_t__ EINVAL;
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ SIGEV_SIGNAL;
scalar_t__ errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ timer_create(int /*<<< orphan*/, struct sigevent *,
                        int /*<<< orphan*/ *);
scalar_t__ timer_delete(int /*<<< orphan*/);
int timer_settime(int /*<<< orphan*/, int /*<<< orphan*/, struct itimerspec *,
                  int /*<<< orphan*/ *);
int main(void) {
  struct sigevent ev;
  timer_t tid;
  struct itimerspec its;
  ev.sigev_notify = SIGEV_SIGNAL;
  ev.sigev_signo = SIGALRM;
  if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
    perror("timer_create() did not return success\n");
    return 2;
  }
  if (timer_delete(tid) != 0) {
    perror("timer_delete() did not return success\n");
    return 2;
  }
  its.it_interval.tv_sec = 0;
  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) == -1) {
    if (errno == EINVAL) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("errno!=EINVAL after a timer_delete()\n");
      return 1;
    }
  } else {
    printf("timer_settime() did not fail after timer_delete()\n");
    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)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <timer_create@plt>
cmp    $0x0,%rax
je     11af <main+0x5f>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1270 <main+0x120>
mov    -0x14(%rbp),%edi
call   1060 <timer_delete@plt>
cmp    $0x0,%rax
je     11d9 <main+0x89>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1270 <main+0x120>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%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    $0xffffffff,%eax
jne    125d <main+0x10d>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%rax
jne    1245 <main+0xf5>
lea    0xe1a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <main+0x120>
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1270 <main+0x120>
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <timer_create@plt>
test   %rax,%rax
jne    1219 <main+0xc9>
mov    0xc(%rsp),%edi
call   1060 <timer_delete@plt>
test   %rax,%rax
jne    1222 <main+0xd2>
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movl   $0x3,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    0xc(%rsp),%edi
lea    0x18(%rsp),%rdx
xor    %esi,%esi
xor    %ecx,%ecx
call   1030 <timer_settime@plt>
cmp    $0xffffffff,%eax
je     11da <main+0x8a>
lea    0xe76(%rip),%rdi
jmp    120a <main+0xba>
mov    0x2def(%rip),%rax
mov    (%rax),%rax
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%rax
jne    1203 <main+0xb3>
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x38,%rsp
ret
lea    0xde0(%rip),%rdi
jmp    1229 <main+0xd9>
lea    0xdfe(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%eax
add    $0x38,%rsp
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 { i64, i64 }
@SIGEV_SIGNAL = global i32 0
@SIGALRM = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [39 x i8] c"timer_create() did not return success\0A\00"
@.str.1 = [39 x i8] c"timer_delete() did not return success\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [13 x i8] c"Test PASSED\0A\00"
@.str.3 = [38 x i8] c"errno!=EINVAL after a timer_delete()\0A\00"
@.str.4 = [51 x i8] c"timer_settime() did not fail after timer_delete()\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigevent
%3 = alloca i32
%4 = alloca %struct.itimerspec
store i32 0, i32* %1
%5 = load i32, i32* @SIGEV_SIGNAL
%6 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 1
store i32 %5, i32* %6
%7 = load i32, i32* @SIGALRM
%8 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i32 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @CLOCK_REALTIME
%10 = call i64 @timer_create(i32 %9, %struct.sigevent* %2, i32* %3)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %42
14: ; preds = %0
%15 = load i32, i32* %3
%16 = call i64 @timer_delete(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %42
20: ; preds = %14
%21 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 1
store i64 0, i64* %22
%23 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 0
store i64 0, i64* %24
%25 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 0
store i32 3, i32* %26
%27 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %4, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 1
store i64 0, i64* %28
%29 = load i32, i32* %3
%30 = call i32 @timer_settime(i32 %29, i32 0, %struct.itimerspec* %4, i32* null)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %40
32: ; preds = %20
%33 = load i64, i64* @errno
%34 = load i64, i64* @EINVAL
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %42
38: ; preds = %32
%39 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %42
40: ; preds = %20
%41 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %42
42: ; preds = %40, %38, %36, %18, %12
%43 = load i32, i32* %1
ret i32 %43
}

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
@SIGALRM = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [39 x i8] c"timer_create() did not return success\0A\00"
@.str.1 = [39 x i8] c"timer_delete() did not return success\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@str = [50 x i8] c"timer_settime() did not fail after timer_delete()\00"
@str.5 = [37 x i8] c"errno!=EINVAL after a timer_delete()\00"
@str.6 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca %struct.sigevent
%2 = alloca i32
%3 = alloca %struct.itimerspec
%4 = bitcast %struct.sigevent* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.itimerspec* %3 to i8*
%7 = load i32, i32* @SIGEV_SIGNAL
%8 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %1, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @SIGALRM
%10 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %1, i64 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i64 @timer_create(i32 %11, %struct.sigevent* %1, i32* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %40
16: ; preds = %0
%17 = load i32, i32* %2
%18 = call i64 @timer_delete(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %40
22: ; preds = %16
%23 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %3, i64 0, i32 1, i32 0
%24 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %3, i64 0, i32 0, i32 0
%25 = bitcast i64* %23 to i8*
store i32 3, i32* %24
%26 = getelementptr inbounds %struct.itimerspec, %struct.itimerspec* %3, i64 0, i32 0, i32 1
store i64 0, i64* %26
%27 = load i32, i32* %2
%28 = call i32 @timer_settime(i32 %27, i32 0, %struct.itimerspec* %3, i32* null)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %38
30: ; preds = %22
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINVAL
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %40
36: ; preds = %30
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.5, i64 0, i64 0))
br label %40
38: ; preds = %22
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %36, %34, %20, %14
%41 = phi i32 [ 2, %14 ], [ 2, %20 ], [ 0, %34 ], [ 1, %36 ], [ 1, %38 ]
ret i32 %41
}