#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*/ assert(int);
double dt_to_s(struct timeval *dt) {
  double ret = (double)dt->tv_sec + ((double)dt->tv_usec / 1000000.);
  assert(ret >= 0);
  return ret > 0 ? ret : 1;
}


x86 assembly (clang, -O0):
<dt_to_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xec9(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    117e <dt_to_s+0x6e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1190 <dt_to_s+0x80>
movsd  0xe82(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1190 <dt_to_s+0x80>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dt_to_s>:
sub    $0x18,%rsp
cvtsi2sdq 0x8(%rdi),%xmm0
cvtsi2sdq (%rdi),%xmm1
divsd  0xed9(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
xorpd  %xmm0,%xmm0
xor    %edi,%edi
ucomisd %xmm0,%xmm1
setae  %dil
call   1030 <assert@plt>
xorpd  %xmm1,%xmm1
movapd (%rsp),%xmm0
cmpltsd %xmm0,%xmm1
andpd  %xmm1,%xmm0
movapd %xmm0,%xmm2
movsd  0xea7(%rip),%xmm0
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @dt_to_s(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca double
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 1
%6 = load i64, i64* %5
%7 = sitofp i64 %6 to double
%8 = load %struct.timeval*, %struct.timeval** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = fdiv double %11, 1.000000e+06
%13 = fadd double %7, %12
store double %13, double* %3
%14 = load double, double* %3
%15 = fcmp oge double %14, 0.000000e+00
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load double, double* %3
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = load double, double* %3
br label %23
22: ; preds = %1
br label %23
23: ; preds = %22, %20
%24 = phi double [ %21, %20 ], [ 1.000000e+00, %22 ]
ret double %24
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @dt_to_s(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%3 = load i64, i64* %2
%4 = sitofp i64 %3 to double
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = sitofp i64 %6 to double
%8 = fdiv double %7, 1.000000e+06
%9 = fadd double %8, %4
%10 = fcmp oge double %9, 0.000000e+00
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = fcmp ogt double %9, 0.000000e+00
%14 = select i1 %13, double %9, double 1.000000e+00
ret double %14
}