#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*/ timerSpec;
struct TYPE_4__ {
  unsigned int tv_sec;
  scalar_t__ tv_nsec;
};
struct TYPE_3__ {
  unsigned int tv_sec;
  scalar_t__ tv_nsec;
};
struct itimerspec {
  TYPE_2__ it_interval;
  TYPE_1__ it_value;
};

/* Variables and functions */
int /*<<< orphan*/ TFD_TIMER_ABSTIME;
int /*<<< orphan*/ memset(struct itimerspec *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ timerfd_settime(int, int /*<<< orphan*/, struct itimerspec *,
                           int /*<<< orphan*/ *);
bool timer_set(int fd, unsigned int sec) {
  struct itimerspec timerSpec;
  memset(&timerSpec, 0, sizeof(timerSpec));
  timerSpec.it_value.tv_sec = sec;
  timerSpec.it_value.tv_nsec = 0;
  timerSpec.it_interval.tv_sec = sec;
  timerSpec.it_interval.tv_nsec = 0;
  if (0 > timerfd_settime(fd, TFD_TIMER_ABSTIME, &timerSpec, NULL)) {
    perror("Error destroying timer");
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<timer_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <timerfd_settime@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11a9 <timer_set+0x79>
lea    0xe68(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <timer_set+0x80>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_set>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    %ebx,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %ebx,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1050 <timerfd_settime@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
js     1192 <timer_set+0x62>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe67(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
jmp    1189 <timer_set+0x59>

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

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