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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double gettimeofday_sec(void) {
  struct timeval tv;
  unsigned long msec;
  gettimeofday(&tv, NULL);
  msec = (tv.tv_sec * 1000.0) + (unsigned long)(tv.tv_usec / 1000.0);
  return (double)msec / 1000.0;
}


x86 assembly (clang, -O0):
<gettimeofday_sec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdi
call   1030 <gettimeofday@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xec9(%rip),%xmm5
divsd  %xmm5,%xmm1
movaps %xmm1,%xmm2
cvttsd2si %xmm2,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xeb6(%rip),%xmm3
subsd  %xmm3,%xmm1
cvttsd2si %xmm1,%rcx
and    %rdx,%rcx
or     %rcx,%rax
movq   %rax,%xmm4
movaps 0xea3(%rip),%xmm2
punpckldq %xmm2,%xmm4
movapd 0xea7(%rip),%xmm1
subpd  %xmm1,%xmm4
movaps %xmm4,%xmm6
unpckhpd %xmm4,%xmm4
addsd  %xmm6,%xmm4
mulsd  %xmm5,%xmm0
addsd  %xmm4,%xmm0
movaps %xmm0,%xmm4
cvttsd2si %xmm4,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
subsd  %xmm3,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
movq   -0x18(%rbp),%xmm0
punpckldq %xmm2,%xmm0
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe2e(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettimeofday_sec>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0x10(%rsp),%xmm0
movsd  0xed2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
movsd  0xec2(%rip),%xmm2
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rdx
and    %rcx,%rdx
or     %rax,%rdx
movq   %rdx,%xmm0
movdqa 0xeae(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xeb2(%rip),%xmm4
subpd  %xmm4,%xmm0
movapd %xmm0,%xmm5
unpckhpd %xmm0,%xmm5
addsd  %xmm0,%xmm5
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm5,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rdx
and    %rcx,%rdx
or     %rax,%rdx
movq   %rdx,%xmm2
punpckldq %xmm3,%xmm2
subpd  %xmm4,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timeval = type { double, double }
define double @gettimeofday_sec() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load double, double* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load double, double* %6
%8 = fdiv double %7, 1.000000e+03
%9 = fptoui double %8 to i64
%10 = uitofp i64 %9 to double
%11 = tail call double @llvm.fmuladd.f64(double %5, double 1.000000e+03, double %10)
%12 = fptoui double %11 to i64
%13 = uitofp i64 %12 to double
%14 = fdiv double %13, 1.000000e+03
ret double %14
}