#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*/ timerSpec;
struct itimerspec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ memset(struct itimerspec *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ timer_set(int, unsigned int);
int timerfd_create(int /*<<< orphan*/, int /*<<< orphan*/);
bool timer_init(unsigned int sec, int *fd_out) {
  struct itimerspec timerSpec;
  int fd;
  memset(&timerSpec, 0, sizeof(timerSpec));
  if (0 > (fd = timerfd_create(CLOCK_REALTIME, 0))) {
    perror("Error creating timer");
    return false;
  }
  if (!timer_set(fd, sec)) {
    return false;
  }
  *fd_out = fd;
  return true;
}


x86 assembly (clang, -O0):
<timer_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <timerfd_create@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    1196 <timer_init+0x56>
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <timer_init+0x86>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <timer_set@plt>
cmp    $0x0,%eax
jne    11b6 <timer_init+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <timer_init+0x86>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <timerfd_create@plt>
test   %eax,%eax
js     1198 <timer_init+0x58>
mov    %eax,%ebx
mov    %eax,%edi
mov    %ebp,%esi
call   1060 <timer_set@plt>
test   %eax,%eax
je     118a <timer_init+0x4a>
mov    %ebx,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe61(%rip),%rdi
call   1050 <perror@plt>
jmp    118a <timer_init+0x4a>

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

LLVM IR (-O2):
%struct.itimerspec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [21 x i8] c"Error creating timer\00"
define i32 @timer_init(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.itimerspec
%4 = bitcast %struct.itimerspec* %3 to i8*
%5 = call i32 @memset(%struct.itimerspec* %3, i32 0, i32 4)
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @timerfd_create(i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %2
%12 = call i32 @timer_set(i32 %7, i32 %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %11
store i32 %7, i32* %1
br label %15
15: ; preds = %11, %14, %9
%16 = phi i32 [ 0, %9 ], [ 1, %14 ], [ 0, %11 ]
ret i32 %16
}