#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 */
struct timespec {
  long long tv_sec;
  scalar_t__ tv_nsec;
};
typedef scalar_t__ int64_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ tlmu_hosttimer_start(scalar_t__);
scalar_t__ tlmu_timers_run(scalar_t__);
void tlmu_hosttimer_handler(int host_signum) {
  struct timespec tp;
  int64_t current_ns;
  int64_t next_ns;
  clock_gettime(CLOCK_REALTIME, &tp);
  current_ns = tp.tv_sec * 1000000000LL + tp.tv_nsec;
  next_ns = tlmu_timers_run(current_ns);
  tlmu_hosttimer_start(next_ns - current_ns);
}


x86 assembly (clang, -O0):
<tlmu_hosttimer_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
imul   $0x3b9aca00,-0x18(%rbp),%rax
3b
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <tlmu_timers_run@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
sub    -0x20(%rbp),%rdi
call   1050 <tlmu_hosttimer_start@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tlmu_hosttimer_handler>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
imul   $0x3b9aca00,(%rsp),%rbx
3b
add    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <tlmu_timers_run@plt>
sub    %rbx,%rax
mov    %rax,%rdi
call   1050 <tlmu_hosttimer_start@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
define void @tlmu_hosttimer_handler(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %3)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%9 = load i64, i64* %8
%10 = mul nsw i64 %9, 1000000000
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%12 = load i64, i64* %11
%13 = add nsw i64 %10, %12
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = call i64 @tlmu_timers_run(i64 %14)
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = load i64, i64* %4
%18 = sub nsw i64 %16, %17
%19 = call i32 @tlmu_hosttimer_start(i64 %18)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
define void @tlmu_hosttimer_handler(i32 %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = mul nsw i64 %7, 1000000000
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%10 = load i64, i64* %9
%11 = add nsw i64 %8, %10
%12 = call i64 @tlmu_timers_run(i64 %11)
%13 = sub nsw i64 %12, %11
%14 = call i32 @tlmu_hosttimer_start(i64 %13)
ret void
}