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

/* Variables and functions */
int sscanf(char const *, char *, double *);
int strtotimeval(struct timeval *tv, const char *time) {
  double secs;
  if (sscanf(time, "%lf", &secs) != 1)
    return -1;
  tv->tv_sec = secs;
  tv->tv_usec = 1000000 * (secs - tv->tv_sec);
  return 0;
}


x86 assembly (clang, -O0):
<strtotimeval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xedd(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1149 <strtotimeval+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1181 <strtotimeval+0x71>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm1
movsd  0xe95(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtotimeval>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xee6(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    115a <strtotimeval+0x4a>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
subsd  %xmm0,%xmm0
mulsd  0xeaf(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x8(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { double, i32 }
@.str = [4 x i8] c"%lf\00"
define i32 @strtotimeval(%struct.timeval* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.timeval*
%5 = alloca i8*
%6 = alloca double
store %struct.timeval* %0, %struct.timeval** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %6)
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %24
11: ; preds = %2
%12 = load double, double* %6
%13 = load %struct.timeval*, %struct.timeval** %4
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store double %12, double* %14
%15 = load double, double* %6
%16 = load %struct.timeval*, %struct.timeval** %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%18 = load double, double* %17
%19 = fsub double %15, %18
%20 = fmul double 1.000000e+06, %19
%21 = fptosi double %20 to i32
%22 = load %struct.timeval*, %struct.timeval** %4
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
store i32 %21, i32* %23
store i32 0, i32* %3
br label %24
24: ; preds = %11, %10
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
@.str = [4 x i8] c"%lf\00"
define i32 @strtotimeval(%struct.timeval* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load double, double* %3
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store double %8, double* %9
%10 = fsub double %8, %8
%11 = fmul double %10, 1.000000e+06
%12 = fptosi double %11 to i32
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %12, i32* %13
br label %14
14: ; preds = %2, %7
%15 = phi i32 [ 0, %7 ], [ -1, %2 ]
ret i32 %15
}