#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 */
struct TYPE_4__ {
  long tv_sec;
  long tv_usec;
};
struct TYPE_3__ {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ exit(int);
double modf(double, double *);
int /*<<< orphan*/ perror(char *);
scalar_t__ setitimer(int /*<<< orphan*/, struct itimerval *,
                     int /*<<< orphan*/ *);
void EnableAlarm(double timeout) {
  if (timeout <= 0)
    return;
  struct itimerval timer = {};
  timer.it_interval.tv_sec = 0;
  timer.it_interval.tv_usec = 0;
  double int_val, fraction_val;
  fraction_val = modf(timeout, &int_val);
  timer.it_value.tv_sec = (long)int_val;
  timer.it_value.tv_usec = (long)(fraction_val * 1e6);
  if (setitimer(ITIMER_REAL, &timer, NULL) != 0) {
    perror("setitimer(ITIMER_REAL, &timer, NULL)");
    exit(1);
  };
}


x86 assembly (clang, -O0):
<EnableAlarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1170 <EnableAlarm+0x20>
jmp    11f9 <EnableAlarm+0xa9>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsd  0xe4b(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <setitimer@plt>
cmp    $0x0,%rax
je     11f9 <EnableAlarm+0xa9>
lea    0xe1e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnableAlarm>:
sub    $0x28,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1197 <EnableAlarm+0x57>
xorpd  %xmm1,%xmm1
movupd %xmm1,0x18(%rsp)
mov    %rsp,%rdi
call   1030 <modf@plt>
cvttsd2si (%rsp),%rax
mulsd  0xe92(%rip),%xmm0
cvttsd2si %xmm0,%rcx
mov    %rax,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <setitimer@plt>
test   %rax,%rax
jne    119c <EnableAlarm+0x5c>
add    $0x28,%rsp
ret
lea    0xe65(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@ITIMER_REAL = global i32 0
@.str = [37 x i8] c"setitimer(ITIMER_REAL, &timer, NULL)\00"
define void @EnableAlarm(double %0) {
%2 = alloca double
%3 = alloca %struct.itimerval
%4 = alloca double
%5 = alloca double
store double %0, double* %2
%6 = load double, double* %2
%7 = fcmp ole double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
br label %32
9: ; preds = %1
%10 = bitcast %struct.itimerval* %3 to i8*
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 1
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
store i64 0, i64* %14
%15 = load double, double* %2
%16 = call double @modf(double %15, double* %4)
store double %16, double* %5
%17 = load double, double* %4
%18 = fptosi double %17 to i64
%19 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i32 0, i32 0
store i64 %18, i64* %20
%21 = load double, double* %5
%22 = fmul double %21, 1.000000e+06
%23 = fptosi double %22 to i64
%24 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 1
store i64 %23, i64* %25
%26 = load i32, i32* @ITIMER_REAL
%27 = call i64 @setitimer(i32 %26, %struct.itimerval* %3, i32* null)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %9
%30 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %8, %9
ret void
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@ITIMER_REAL = global i32 0
@.str = [37 x i8] c"setitimer(ITIMER_REAL, &timer, NULL)\00"
define void @EnableAlarm(double %0) {
%2 = alloca %struct.itimerval
%3 = alloca double
%4 = fcmp ugt double %0, 0.000000e+00
br i1 %4, label %5, label %24
5: ; preds = %1
%6 = bitcast %struct.itimerval* %2 to i8*
%7 = bitcast double* %3 to i8*
%8 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 1
%9 = bitcast %struct.TYPE_3__* %8 to i8*
%10 = call double @modf(double %0, double* %3)
%11 = load double, double* %3
%12 = fptosi double %11 to i64
%13 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 0
store i64 %12, i64* %13
%14 = fmul double %10, 1.000000e+06
%15 = fptosi double %14 to i64
%16 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %2, i64 0, i32 0, i32 1
store i64 %15, i64* %16
%17 = load i32, i32* @ITIMER_REAL
%18 = call i64 @setitimer(i32 %17, %struct.itimerval* %2, i32* null)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %5
%21 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %5
br label %24
24: ; preds = %1, %23
ret void
}