#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 {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
unsigned long timeval2ulong(struct timeval *tv) {
  unsigned long ret;
  ret = 1e3 * tv->tv_sec;
  ret += 1e-3 * tv->tv_usec;
  return ret;
}


x86 assembly (clang, -O0):
<timeval2ulong>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
movsd  0xee8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xed5(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdl 0x4(%rax),%xmm0
movaps 0xeca(%rip),%xmm3
movq   -0x10(%rbp),%xmm2
punpckldq %xmm3,%xmm2
movapd 0xec9(%rip),%xmm3
subpd  %xmm3,%xmm2
movaps %xmm2,%xmm3
unpckhpd %xmm2,%xmm2
addsd  %xmm3,%xmm2
movsd  0xe92(%rip),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movaps %xmm0,%xmm2
cvttsd2si %xmm2,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval2ulong>:
movslq (%rdi),%rax
imul   $0x3e8,%rax,%rax
cvtsi2sdl 0x4(%rdi),%xmm0
movq   %rax,%xmm1
punpckldq 0xee4(%rip),%xmm1
subpd  0xeec(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
mulsd  0xeec(%rip),%xmm0
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xed8(%rip),%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rcx,%rax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @timeval2ulong(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca i64
store %struct.timeval* %0, %struct.timeval** %2
%4 = load %struct.timeval*, %struct.timeval** %2
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = sitofp i32 %6 to double
%8 = fmul double 1.000000e+03, %7
%9 = fptoui double %8 to i64
store i64 %9, i64* %3
%10 = load %struct.timeval*, %struct.timeval** %2
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = sitofp i32 %12 to double
%14 = load i64, i64* %3
%15 = uitofp i64 %14 to double
%16 = call double @llvm.fmuladd.f64(double 1.000000e-03, double %13, double %15)
%17 = fptoui double %16 to i64
store i64 %17, i64* %3
%18 = load i64, i64* %3
ret i64 %18
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @timeval2ulong(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = sext i32 %3 to i64
%5 = mul nsw i64 %4, 1000
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = sitofp i32 %7 to double
%9 = uitofp i64 %5 to double
%10 = tail call double @llvm.fmuladd.f64(double %8, double 1.000000e-03, double %9)
%11 = fptoui double %10 to i64
ret i64 %11
}