#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;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double tock(struct timeval *t) {
  struct timeval now;
  gettimeofday(&now, NULL);
  return (double)(now.tv_sec - t->tv_sec) +
         ((double)(now.tv_usec - t->tv_usec) / 1000000.);
}


x86 assembly (clang, -O0):
<tock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    0x8(%rcx),%rax
cvtsi2sd %rax,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2sd %rax,%xmm1
movsd  0xeae(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tock>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%rax
mov    0x8(%rsp),%rcx
sub    0x8(%rbx),%rcx
cvtsi2sd %rcx,%xmm1
sub    (%rbx),%rax
cvtsi2sd %rax,%xmm0
divsd  0xebc(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @tock(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%4 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%6 = load i64, i64* %5
%7 = load %struct.timeval*, %struct.timeval** %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%9 = load i64, i64* %8
%10 = sub nsw i64 %6, %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load %struct.timeval*, %struct.timeval** %2
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = sub nsw i64 %13, %16
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %11, %19
ret double %20
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @tock(%struct.timeval* nocapture %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%8 = load i64, i64* %7
%9 = sub nsw i64 %6, %8
%10 = sitofp i64 %9 to double
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%14 = load i64, i64* %13
%15 = sub nsw i64 %12, %14
%16 = sitofp i64 %15 to double
%17 = fdiv double %16, 1.000000e+06
%18 = fadd double %17, %10
ret double %18
}