#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_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ timer_t;
struct TYPE_2__ {
  void *sival_ptr;
};
struct sigevent {
  void (*sigev_notify_function)(union sigval);
  TYPE_1__ sigev_value;
  int /*<<< orphan*/ sigev_notify;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ SIGEV_THREAD;
int /*<<< orphan*/ memset(struct sigevent *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int timer_create(int /*<<< orphan*/, struct sigevent *, int /*<<< orphan*/ *);
timer_t timeout_add(uint64_t msec, void (*func)(union sigval sv), void *data) {
  timer_t timerid = (timer_t)-1;
  struct sigevent sev;
  memset(&sev, 0, sizeof(struct sigevent));
  sev.sigev_notify = SIGEV_THREAD;
  sev.sigev_notify_function = func;
  sev.sigev_value.sival_ptr = data;
  if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) {
    perror("timer_create");
  }
  return timerid;
}


x86 assembly (clang, -O0):
<timeout_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <timer_create@plt>
cmp    $0xffffffff,%eax
jne    11a1 <timeout_add+0x71>
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeout_add>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0xffffffff,0x4(%rsp)
ff
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rdx
mov    %r15,%rsi
call   1030 <timer_create@plt>
cmp    $0xffffffff,%eax
je     119b <timeout_add+0x6b>
mov    0x4(%rsp),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
jmp    118d <timeout_add+0x5d>

LLVM IR (-O0):
%struct.sigevent = type { {}*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
@SIGEV_THREAD = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [13 x i8] c"timer_create\00"
define i32 @timeout_add(i32 %0, {}* %1, i8* %2) {
%4 = alloca i32
%5 = alloca {}*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sigevent
store i32 %0, i32* %4
store {}* %1, {}** %5
store i8* %2, i8** %6
store i32 -1, i32* %7
%9 = call i32 @memset(%struct.sigevent* %8, i32 0, i32 24)
%10 = load i32, i32* @SIGEV_THREAD
%11 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %8, i32 0, i32 2
store i32 %10, i32* %11
%12 = load {}*, {}** %5
%13 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %8, i32 0, i32 0
store {}* %12, {}** %13
%14 = load i8*, i8** %6
%15 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %8, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i8* %14, i8** %16
%17 = load i32, i32* @CLOCK_REALTIME
%18 = call i32 @timer_create(i32 %17, %struct.sigevent* %8, i32* %7)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
%struct.sigevent = type { {}*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
@SIGEV_THREAD = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [13 x i8] c"timer_create\00"
define i32 @timeout_add(i32 %0, {}* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.sigevent
%6 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%7 = bitcast %struct.sigevent* %5 to i8*
%8 = call i32 @memset(%struct.sigevent* %5, i32 0, i32 24)
%9 = load i32, i32* @SIGEV_THREAD
%10 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %5, i64 0, i32 2
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %5, i64 0, i32 0
store {}* %1, {}** %11
%12 = getelementptr inbounds %struct.sigevent, %struct.sigevent* %5, i64 0, i32 1, i32 0
store i8* %2, i8** %12
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @timer_create(i32 %13, %struct.sigevent* %5, i32* %4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %3
%19 = load i32, i32* %4
ret i32 %19
}