#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 */

/* Type definitions */
typedef int /*<<< orphan*/ timer_t;
struct sigevent {
  scalar_t__ sigev_signo;
  int /*<<< orphan*/ sigev_notify;
};
typedef int /*<<< orphan*/ sigev;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ SIGEV_SIGNAL;
scalar_t__ SIGRTMIN;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(struct sigevent *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int timer_create(int /*<<< orphan*/, struct sigevent *, int /*<<< orphan*/ *);
int setup_timer(timer_t *timer) {
  int status;
  struct sigevent sigev;
  memset(&sigev, 0, sizeof(sigev));
  sigev.sigev_notify = SIGEV_SIGNAL;
  sigev.sigev_signo = (SIGRTMIN + 1);
  status = timer_create(CLOCK_MONOTONIC, &sigev, timer);
  if (status) {
    fprintf(stderr, "error from timer_create: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <timer_create@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d5 <setup_timer+0x95>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <setup_timer+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_timer>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e54(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <timer_create@plt>
test   %eax,%eax
je     11c4 <setup_timer+0x84>
mov    0x2e32(%rip),%rax
mov    (%rax),%ebx
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe4b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigevent = type { i64, i32 }
@SIGEV_SIGNAL = global i32 0
@SIGRTMIN = global i64 0
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"error from timer_create: %s\0A\00"
@errno = global i32 0
define i32 @setup_timer(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.sigevent
store i32* %0, i32** %3
%6 = call i32 @memset(%struct.sigevent* %5, i32 0, i32 16)
%7 = load i32, i32* @SIGEV_SIGNAL
%8 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %5, i32 0, i32 1
store i32 %7, i32* %8
%9 = load i64, i64* @SIGRTMIN
%10 = add nsw i64 %9, 1
%11 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %5, i32 0, i32 0
store i64 %10, i64* %11
%12 = load i32, i32* @CLOCK_MONOTONIC
%13 = load i32*, i32** %3
%14 = call i32 @timer_create(i32 %12, %struct.sigevent* %5, i32* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %2
br label %23
22: ; preds = %1
store i32 0, i32* %2
br label %23
23: ; preds = %22, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.sigevent = type { i64, i32 }
@SIGEV_SIGNAL = global i32 0
@SIGRTMIN = global i64 0
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"error from timer_create: %s\0A\00"
@errno = global i32 0
define i32 @setup_timer(i32* %0) {
%2 = alloca %struct.sigevent
%3 = bitcast %struct.sigevent* %2 to i8*
%4 = call i32 @memset(%struct.sigevent* %2, i32 0, i32 16)
%5 = load i32, i32* @SIGEV_SIGNAL
%6 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = load i64, i64* @SIGRTMIN
%8 = add nsw i64 %7, 1
%9 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %2, i64 0, i32 0
store i64 %8, i64* %9
%10 = load i32, i32* @CLOCK_MONOTONIC
%11 = call i32 @timer_create(i32 %10, %struct.sigevent* %2, i32* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %1, %13
%19 = phi i32 [ -1, %13 ], [ 0, %1 ]
ret i32 %19
}