#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 member_1;
  int tv_sec;
  int tv_usec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ errno;
double floor(double);
scalar_t__ rint(double);
double strtod(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ tkh_string_is_time_report(char const *);
struct timeval tkh_decode_time(const char *s) {
  struct timeval tv = {0, -1};
  if (!tkh_string_is_time_report(s))
    return tv;
  errno = 0;
  double t = strtod(s, NULL);
  tv.tv_sec = (int)floor(t);
  tv.tv_usec = (int)rint((t - floor(t)) * 10000000);
  return tv;
}


x86 assembly (clang, -O0):
<tkh_decode_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x18(%rbp)
mov    0xeb5(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <tkh_string_is_time_report@plt>
cmp    $0x0,%eax
jne    1179 <tkh_decode_time+0x39>
jmp    11de <tkh_decode_time+0x9e>
mov    0x2e60(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <rint@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tkh_decode_time>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <tkh_string_is_time_report@plt>
test   %eax,%eax
je     119b <tkh_decode_time+0x5b>
mov    0x2e88(%rip),%rax
movq   $0x0,(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
call   1060 <floor@plt>
cvttsd2si %xmm0,%ebx
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe76(%rip),%xmm1
movapd %xmm1,%xmm0
call   1050 <rint@plt>
mov    %eax,%edx
shl    $0x20,%rbx
jmp    11a7 <tkh_decode_time+0x67>
movabs $0xffffffff00000000,%rbx
ff ff ff
xor    %edx,%edx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32, i32, i32 }
@__const.tkh_decode_time.tv = %struct.timeval { i32 0, i32 -1, i32 0, i32 0 }
@errno = global i64 0
define { i64, i64 } @tkh_decode_time(i8* %0) {
%2 = alloca %struct.timeval
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %3
%5 = bitcast %struct.timeval* %2 to i8*
%6 = load i8*, i8** %3
%7 = call i32 @tkh_string_is_time_report(i8* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
br label %25
10: ; preds = %1
store i64 0, i64* @errno
%11 = load i8*, i8** %3
%12 = call double @strtod(i8* %11, i32* null)
store double %12, double* %4
%13 = load double, double* %4
%14 = call double @llvm.floor.f64(double %13)
%15 = fptosi double %14 to i32
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
store i32 %15, i32* %16
%17 = load double, double* %4
%18 = load double, double* %4
%19 = call double @llvm.floor.f64(double %18)
%20 = fsub double %17, %19
%21 = fmul double %20, 1.000000e+07
%22 = call i64 @rint(double %21)
%23 = trunc i64 %22 to i32
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 2
store i32 %23, i32* %24
br label %25
25: ; preds = %10, %9
%26 = bitcast %struct.timeval* %2 to { i64, i64 }*
%27 = load { i64, i64 }, { i64, i64 }* %26
ret { i64, i64 } %27
}

LLVM IR (-O2):
@errno = global i64 0
define { i64, i64 } @tkh_decode_time(i8* %0) {
%2 = tail call i32 @tkh_string_is_time_report(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
store i64 0, i64* @errno
%5 = tail call double @strtod(i8* nocapture %0, i32* null)
%6 = tail call double @llvm.floor.f64(double %5)
%7 = fptosi double %6 to i32
%8 = fsub double %5, %6
%9 = fmul double %8, 1.000000e+07
%10 = tail call i64 @rint(double %9)
%11 = and i64 %10, 4294967295
%12 = zext i32 %7 to i64
%13 = shl nuw i64 %12, 32
br label %14
14: ; preds = %1, %4
%15 = phi i64 [ %11, %4 ], [ 0, %1 ]
%16 = phi i64 [ %13, %4 ], [ -4294967296, %1 ]
%17 = insertvalue { i64, i64 } poison, i64 %16, 0
%18 = insertvalue { i64, i64 } %17, i64 %15, 1
ret { i64, i64 } %18
}