#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 timespec {
  double tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
struct timespec *flu_parse_ts(char const *);
int /*<<< orphan*/ free(struct timespec *);
double flu_parse_d(const char *s) {
  errno = 0;
  struct timespec *ts = flu_parse_ts(s);
  if (ts == NULL) {
    errno = EINVAL;
    return 0.0;
  }
  double r = ts->tv_sec + (double)ts->tv_nsec / 1000000000;
  free(ts);
  return r;
}


x86 assembly (clang, -O0):
<flu_parse_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <flu_parse_ts@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1173 <flu_parse_d+0x53>
mov    0x2e7f(%rip),%rax
mov    (%rax),%rcx
mov    0x2e7d(%rip),%rax
mov    %rcx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ad <flu_parse_d+0x8d>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
movsd  0xe73(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flu_parse_d>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eb4(%rip),%rbx
movq   $0x0,(%rbx)
call   1040 <flu_parse_ts@plt>
test   %rax,%rax
je     1165 <flu_parse_d+0x45>
cvtsi2sdq 0x8(%rax),%xmm0
divsd  0xeb5(%rip),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rax,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
jmp    1175 <flu_parse_d+0x55>
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rbx)
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
@errno = global i64 0
@EINVAL = global i64 0
define double @flu_parse_d(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca %struct.timespec*
%5 = alloca double
store i8* %0, i8** %3
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = call %struct.timespec* @flu_parse_ts(i8* %6)
store %struct.timespec* %7, %struct.timespec** %4
%8 = load %struct.timespec*, %struct.timespec** %4
%9 = icmp eq %struct.timespec* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i64, i64* @EINVAL
store i64 %11, i64* @errno
store double 0.000000e+00, double* %2
br label %25
12: ; preds = %1
%13 = load %struct.timespec*, %struct.timespec** %4
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%15 = load double, double* %14
%16 = load %struct.timespec*, %struct.timespec** %4
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = fdiv double %19, 1.000000e+09
%21 = fadd double %15, %20
store double %21, double* %5
%22 = load %struct.timespec*, %struct.timespec** %4
%23 = call i32 @free(%struct.timespec* %22)
%24 = load double, double* %5
store double %24, double* %2
br label %25
25: ; preds = %12, %10
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@errno = global i64 0
@EINVAL = global i64 0
define double @flu_parse_d(i8* %0) {
store i64 0, i64* @errno
%2 = tail call %struct.timespec* @flu_parse_ts(i8* %0)
%3 = icmp eq %struct.timespec* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i64, i64* @EINVAL
store i64 %5, i64* @errno
br label %15
6: ; preds = %1
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%8 = load double, double* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = fdiv double %11, 1.000000e+09
%13 = fadd double %8, %12
%14 = tail call i32 @free(%struct.timespec* %2)
br label %15
15: ; preds = %6, %4
%16 = phi double [ 0.000000e+00, %4 ], [ %13, %6 ]
ret double %16
}