#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
double strtod(char const *, char **);
double cast_to_double(const char *key, const char *val, double *out) {
  char *end;
  *out = strtod(val, &end);
  if (end == val || *end != '\0') {
    fprintf(stderr,
            "Error: key \"%s\" (\"%s\") did not cast "
            "properly to double\n",
            key, val);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cast_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1167 <cast_to_double+0x47>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <cast_to_double+0x76>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
movsd  0xe74(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119e <cast_to_double+0x7e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cast_to_double>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strtod@plt>
movsd  %xmm0,(%r15)
mov    0x8(%rsp),%rax
cmp    %rbx,%rax
je     1153 <cast_to_double+0x33>
cmpb   $0x0,(%rax)
je     1178 <cast_to_double+0x58>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
movsd  0xe8a(%rip),%xmm0
jmp    117b <cast_to_double+0x5b>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"Error: key \22%s\22 (\22%s\22) did not cast properly to double\0A\00"
define double @cast_to_double(i8* %0, i8* %1, double* %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store double* %2, double** %7
%9 = load i8*, i8** %6
%10 = call double @strtod(i8* %9, i8** %8)
%11 = load double*, double** %7
store double %10, double* %11
%12 = load i8*, i8** %8
%13 = load i8*, i8** %6
%14 = icmp eq i8* %12, %13
br i1 %14, label %20, label %15
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15, %3
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
store double -1.000000e+00, double* %4
br label %26
25: ; preds = %15
store double 0.000000e+00, double* %4
br label %26
26: ; preds = %25, %20
%27 = load double, double* %4
ret double %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"Error: key \22%s\22 (\22%s\22) did not cast properly to double\0A\00"
define double @cast_to_double(i8* %0, i8* %1, double* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call double @strtod(i8* %1, i8** %4)
store double %6, double* %2
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, %1
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9, %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %15
15: ; preds = %9, %12
%16 = phi double [ -1.000000e+00, %12 ], [ 0.000000e+00, %9 ]
ret double %16
}