#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__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct TYPE_3__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ ITIMER_REAL;
scalar_t__ setitimer(int /*<<< orphan*/, struct itimerval *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ tge_get_fractional_microseconds(double const);
int /*<<< orphan*/ tge_get_whole_seconds(double const);
int /*<<< orphan*/ x_perror(char *);
void tge_timer_start(const double start, const double interval) {
  struct itimerval itv = {
      .it_interval.tv_sec = tge_get_whole_seconds(interval),
      .it_interval.tv_usec = tge_get_fractional_microseconds(interval),
      .it_value.tv_sec = tge_get_whole_seconds(start),
      .it_value.tv_usec = tge_get_fractional_microseconds(start),
  };
  if (setitimer(ITIMER_REAL, &itv, NULL) != 0) {
    x_perror("failed to set itimer");
  }
}


x86 assembly (clang, -O0):
<tge_timer_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <tge_get_fractional_microseconds@plt>
mov    %eax,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <tge_get_whole_seconds@plt>
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <tge_get_fractional_microseconds@plt>
mov    %eax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <tge_get_whole_seconds@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <setitimer@plt>
cmp    $0x0,%rax
je     11b2 <tge_timer_start+0x72>
lea    0xe53(%rip),%rdi
call   1040 <x_perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tge_timer_start>:
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1060 <tge_get_fractional_microseconds@plt>
mov    %eax,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1030 <tge_get_whole_seconds@plt>
mov    %eax,0x14(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <tge_get_fractional_microseconds@plt>
mov    %eax,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <tge_get_whole_seconds@plt>
mov    %eax,0x1c(%rsp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <setitimer@plt>
test   %rax,%rax
je     11b0 <tge_timer_start+0x70>
lea    0xe59(%rip),%rdi
add    $0x28,%rsp
jmp    1040 <x_perror@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
@.str = [21 x i8] c"failed to set itimer\00"
define void @tge_timer_start(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca %struct.itimerval
store double %0, double* %3
store double %1, double* %4
%6 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 0
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%8 = load double, double* %3
%9 = call i32 @tge_get_fractional_microseconds(double %8)
store i32 %9, i32* %7
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
%11 = load double, double* %3
%12 = call i32 @tge_get_whole_seconds(double %11)
store i32 %12, i32* %10
%13 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%15 = load double, double* %4
%16 = call i32 @tge_get_fractional_microseconds(double %15)
store i32 %16, i32* %14
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 1
%18 = load double, double* %4
%19 = call i32 @tge_get_whole_seconds(double %18)
store i32 %19, i32* %17
%20 = load i32, i32* @ITIMER_REAL
%21 = call i64 @setitimer(i32 %20, %struct.itimerval* %5, i32* null)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @x_perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %2
ret void
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
@.str = [21 x i8] c"failed to set itimer\00"
define void @tge_timer_start(double %0, double %1) {
%3 = alloca %struct.itimerval
%4 = bitcast %struct.itimerval* %3 to i8*
%5 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%6 = tail call i32 @tge_get_fractional_microseconds(double %0)
store i32 %6, i32* %5
%7 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
%8 = tail call i32 @tge_get_whole_seconds(double %0)
store i32 %8, i32* %7
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 0
%10 = tail call i32 @tge_get_fractional_microseconds(double %1)
store i32 %10, i32* %9
%11 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 1
%12 = tail call i32 @tge_get_whole_seconds(double %1)
store i32 %12, i32* %11
%13 = load i32, i32* @ITIMER_REAL
%14 = call i64 @setitimer(i32 %13, %struct.itimerval* %3, i32* null)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = tail call i32 @x_perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
ret void
}