#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 keyval {
  int dummy;
};

/* Variables and functions */
char *keyvals_get_val(struct keyval const *, char const *);
scalar_t__ strcmp(char const *, char *);
double strtod(char const *, char **);
double comments_get_double(const struct keyval *comments, const char *key) {
  const char *val;
  char *end;
  double d;
  val = keyvals_get_val(comments, key);
  if (!val || strcmp(val, "") == 0)
    goto error;
  d = strtod(val, &end);
  if (val == end)
    goto error;
  return d;
error:
  return strtod("NAN", NULL);
}


x86 assembly (clang, -O0):
<comments_get_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <keyvals_get_val@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1176 <comments_get_double+0x46>
mov    -0x20(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    117b <comments_get_double+0x4b>
jmp    11af <comments_get_double+0x7f>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11a0 <comments_get_double+0x70>
jmp    11af <comments_get_double+0x7f>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c4 <comments_get_double+0x94>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comments_get_double>:
push   %rbx
sub    $0x10,%rsp
call   1050 <keyvals_get_val@plt>
test   %rax,%rax
je     1170 <comments_get_double+0x40>
mov    %rax,%rbx
lea    0xeba(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1170 <comments_get_double+0x40>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strtod@plt>
cmp    0x8(%rsp),%rbx
je     1170 <comments_get_double+0x40>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe89(%rip),%rdi
xor    %esi,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <strtod@plt>

LLVM IR (-O0):
%struct.keyval = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"NAN\00"
define double @comments_get_double(%struct.keyval* %0, i8* %1) {
%3 = alloca double
%4 = alloca %struct.keyval*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca double
store %struct.keyval* %0, %struct.keyval** %4
store i8* %1, i8** %5
%9 = load %struct.keyval*, %struct.keyval** %4
%10 = load i8*, i8** %5
%11 = call i8* @keyvals_get_val(%struct.keyval* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14, %2
br label %28
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = call double @strtod(i8* %20, i8** %7)
store double %21, double* %8
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = icmp eq i8* %22, %23
br i1 %24, label %25, label %26
25: ; preds = %19
br label %28
26: ; preds = %19
%27 = load double, double* %8
store double %27, double* %3
br label %30
28: ; preds = %25, %18
%29 = call double @strtod(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** null)
store double %29, double* %3
br label %30
30: ; preds = %28, %26
%31 = load double, double* %3
ret double %31
}

LLVM IR (-O2):
%struct.keyval = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"NAN\00"
define double @comments_get_double(%struct.keyval* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @keyvals_get_val(%struct.keyval* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = call double @strtod(i8* %5, i8** %3)
%12 = load i8*, i8** %3
%13 = icmp eq i8* %5, %12
br i1 %13, label %14, label %16
14: ; preds = %10, %2, %7
%15 = tail call double @strtod(i8* nocapture getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** null)
br label %16
16: ; preds = %10, %14
%17 = phi double [ %15, %14 ], [ %11, %10 ]
ret double %17
}