#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 timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double timer_resolution() {
  struct timeval tv1, tv2;
  gettimeofday(&tv1, NULL);
  do {
    gettimeofday(&tv2, NULL);
  } while (tv1.tv_usec == tv2.tv_usec);
  return (double)(tv2.tv_usec - tv1.tv_usec) * 1.0e-6;
}


x86 assembly (clang, -O0):
<timer_resolution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1125 <timer_resolution+0x15>
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xeab(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_resolution>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
nopl   (%rax)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rax
sub    %rbx,%rax
je     1130 <timer_resolution+0x20>
cvtsi2sd %rax,%xmm0
mulsd  0xeaf(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
define double @timer_resolution() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
br label %4
4: ; preds = %6, %0
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %4
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp eq i64 %8, %10
br i1 %11, label %4, label %12
12: ; preds = %6
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%14 = load i64, i64* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i64, i64* %15
%17 = sub nsw i64 %14, %16
%18 = sitofp i64 %17 to double
%19 = fmul double %18, 0x3EB0C6F7A0B5ED8D
ret double %19
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
define double @timer_resolution() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
br label %9
9: ; preds = %9, %0
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%11 = load i64, i64* %8
%12 = icmp eq i64 %11, %7
br i1 %12, label %9, label %13
13: ; preds = %9
%14 = sub nsw i64 %11, %7
%15 = sitofp i64 %14 to double
%16 = fmul double %15, 0x3EB0C6F7A0B5ED8D
ret double %16
}