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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct timeval add2currenttime(double seconds) {
  struct timeval newtime;
  gettimeofday(&newtime, NULL);
  newtime.tv_sec += (int)seconds;
  newtime.tv_usec += (int)((seconds - (int)seconds) * 1000000.0 + 0.5);
  if (newtime.tv_usec >= 1000000L) {
    newtime.tv_sec++;
    newtime.tv_usec -= 1000000L;
  }
  return newtime;
}


x86 assembly (clang, -O0):
<add2currenttime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cvttsd2si -0x18(%rbp),%eax
cltq
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
cvttsd2si -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xead(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea9(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0xf4240,%rax
jl     1196 <add2currenttime+0x86>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movslq -0x10(%rbp),%rax
sub    $0xf4240,%rax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add2currenttime>:
sub    $0x28,%rsp
movaps %xmm0,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movapd 0x10(%rsp),%xmm1
cvttsd2si %xmm1,%eax
movslq %eax,%rdx
add    0x8(%rsp),%rdx
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm1
mulsd  0xeb7(%rip),%xmm1
addsd  0xeb7(%rip),%xmm1
cvttsd2si %xmm1,%eax
add    (%rsp),%eax
cmp    $0xf4240,%eax
jl     1170 <add2currenttime+0x60>
add    $0x1,%rdx
mov    %rdx,0x8(%rsp)
add    $0xfff0bdc0,%eax
mov    %eax,(%rsp)
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define { i32, i64 } @add2currenttime(double %0) {
%2 = alloca %struct.timeval
%3 = alloca double
store double %0, double* %3
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = load double, double* %3
%6 = fptosi double %5 to i32
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %7
store i64 %10, i64* %8
%11 = load double, double* %3
%12 = load double, double* %3
%13 = fptosi double %12 to i32
%14 = sitofp i32 %13 to double
%15 = fsub double %11, %14
%16 = call double @llvm.fmuladd.f64(double %15, double 1.000000e+06, double 5.000000e-01)
%17 = fptosi double %16 to i32
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%19 = load i32, i32* %18
%20 = add nsw i32 %19, %17
store i32 %20, i32* %18
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = icmp sge i64 %23, 1000000
br i1 %24, label %25, label %34
25: ; preds = %1
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%27 = load i64, i64* %26
%28 = add nsw i64 %27, 1
store i64 %28, i64* %26
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = sub nsw i64 %31, 1000000
%33 = trunc i64 %32 to i32
store i32 %33, i32* %29
br label %34
34: ; preds = %25, %1
%35 = bitcast %struct.timeval* %2 to { i32, i64 }*
%36 = load { i32, i64 }, { i32, i64 }* %35
ret { i32, i64 } %36
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define { i32, i64 } @add2currenttime(double %0) {
%2 = alloca %struct.timeval
%3 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%4 = fptosi double %0 to i32
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%7 = load i64, i64* %6
%8 = add nsw i64 %7, %5
%9 = sitofp i32 %4 to double
%10 = fsub double %0, %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double 1.000000e+06, double 5.000000e-01)
%12 = fptosi double %11 to i32
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, %12
%16 = icmp sgt i32 %15, 999999
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = add nsw i64 %8, 1
store i64 %18, i64* %6
%19 = add nsw i32 %15, -1000000
store i32 %19, i32* %13
br label %20
20: ; preds = %17, %1
%21 = phi i64 [ %18, %17 ], [ %8, %1 ]
%22 = phi i32 [ %19, %17 ], [ %15, %1 ]
%23 = insertvalue { i32, i64 } poison, i32 %22, 0
%24 = insertvalue { i32, i64 } %23, i64 %21, 1
ret { i32, i64 } %24
}