#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 {
  scalar_t__ tv_sec;
  scalar_t__ tv_nsec;
};
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int SIGVTALRM;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, long long, int, float);
void sighandler(int signo, siginfo_t *si, void *ucontext) {
  static struct timespec t0;
  if (signo == SIGVTALRM) {
    struct timespec t1;
    clock_gettime(CLOCK_MONOTONIC, &t1);
    long long delta = ((((long long)(t1).tv_sec - (long long)(t0).tv_sec) *
                        1000 * 1000 * 1000) +
                       ((long long)(t1).tv_nsec - (long long)(t0).tv_nsec));
    if (t0.tv_sec)
      printf("%llins %ins -> %.3fms\n", delta, (42 * 1000 * 1000),
             ((float)delta / 1000000.0 - (float)(42)));
    t0 = t1;
  }
  return;
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
jne    11e8 <sighandler+0xc8>
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%rax
sub    0x2ed6(%rip),%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
mov    -0x20(%rbp),%rcx
sub    0x2ebe(%rip),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,0x2ea7(%rip)
je     11d2 <sighandler+0xb2>
mov    -0x30(%rbp),%rsi
cvtsi2ssq -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe5b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe47(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe48(%rip),%rdi
mov    $0x280de80,%edx
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,0x2e5b(%rip)
mov    -0x20(%rbp),%rax
mov    %rax,0x2e58(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
sub    $0x18,%rsp
mov    0x2ead(%rip),%rax
cmp    %edi,(%rax)
jne    11a6 <sighandler+0x86>
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0x2eef(%rip),%rax
test   %rax,%rax
je     119a <sighandler+0x7a>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rsi
sub    %rax,%rcx
imul   $0x3b9aca00,%rcx,%rax
sub    0x2ed7(%rip),%rsi
add    %rax,%rsi
cvtsi2ss %rsi,%xmm0
cvtss2sd %xmm0,%xmm0
divsd  0xe83(%rip),%xmm0
addsd  0xe83(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe80(%rip),%rdi
mov    $0x280de80,%edx
call   1040 <printf@plt>
movups 0x8(%rsp),%xmm0
movups %xmm0,0x2e92(%rip)
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@sighandler.t0 = internal global %struct.timespec zeroinitializer
@SIGVTALRM = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str = [23 x i8] c"%llins %ins -> %.3fms\0A\00"
define void @sighandler(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct.timespec
%8 = alloca i64
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
%10 = load i32, i32* @SIGVTALRM
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %40
12: ; preds = %3
%13 = load i32, i32* @CLOCK_MONOTONIC
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %7)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @sighandler.t0, i32 0, i32 0)
%18 = sub nsw i64 %16, %17
%19 = mul nsw i64 %18, 1000
%20 = mul nsw i64 %19, 1000
%21 = mul nsw i64 %20, 1000
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%23 = load i64, i64* %22
%24 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @sighandler.t0, i32 0, i32 1)
%25 = sub nsw i64 %23, %24
%26 = add nsw i64 %21, %25
store i64 %26, i64* %8
%27 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @sighandler.t0, i32 0, i32 0)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %12
%30 = load i64, i64* %8
%31 = load i64, i64* %8
%32 = sitofp i64 %31 to float
%33 = fpext float %32 to double
%34 = fdiv double %33, 1.000000e+06
%35 = fsub double %34, 4.200000e+01
%36 = fptrunc double %35 to float
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %30, i32 42000000, float %36)
br label %38
38: ; preds = %29, %12
%39 = bitcast %struct.timespec* %7 to i8*
br label %40
40: ; preds = %38, %3
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@sighandler.t0 = internal unnamed_addr global %struct.timespec zeroinitializer
@SIGVTALRM = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str = [23 x i8] c"%llins %ins -> %.3fms\0A\00"
define void @sighandler(i32 %0, i32* nocapture readnone %1, i8* nocapture readnone %2) {
%4 = alloca %struct.timespec
%5 = load i32, i32* @SIGVTALRM
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %30
7: ; preds = %3
%8 = bitcast %struct.timespec* %4 to i8*
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %4)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @sighandler.t0, i64 0, i32 0)
%14 = sub nsw i64 %12, %13
%15 = mul i64 %14, 1000000000
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%17 = load i64, i64* %16
%18 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @sighandler.t0, i64 0, i32 1)
%19 = sub nsw i64 %17, %18
%20 = add nsw i64 %19, %15
%21 = icmp eq i64 %13, 0
br i1 %21, label %29, label %22
22: ; preds = %7
%23 = sitofp i64 %20 to float
%24 = fpext float %23 to double
%25 = fdiv double %24, 1.000000e+06
%26 = fadd double %25, -4.200000e+01
%27 = fptrunc double %26 to float
%28 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %20, i32 42000000, float %27)
br label %29
29: ; preds = %22, %7
br label %30
30: ; preds = %29, %3
ret void
}