#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 *);
int /*<<< orphan*/ stderr;
double strtod(char const *, char **);
double trans_double(const char *str, double def) {
  char *endptr = NULL;
  double n = strtod(str, &endptr);
  if (*endptr != '\0') {
    fprintf(stderr, "can't convert to double %s\n", str);
    return def;
  }
  return n;
}


x86 assembly (clang, -O0):
<trans_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1183 <trans_double+0x63>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe91(%rip),%rsi
call   1040 <fprintf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    118d <trans_double+0x6d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trans_double>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rsi
call   1030 <strtod@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1165 <trans_double+0x45>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"can't convert to double %s\0A\00"
define double @trans_double(i8* %0, double %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca double
%6 = alloca i8*
%7 = alloca double
store i8* %0, i8** %4
store double %1, double* %5
store i8* null, i8** %6
%8 = load i8*, i8** %4
%9 = call double @strtod(i8* %8, i8** %6)
store double %9, double* %7
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load double, double* %5
store double %18, double* %3
br label %21
19: ; preds = %2
%20 = load double, double* %7
store double %20, double* %3
br label %21
21: ; preds = %19, %14
%22 = load double, double* %3
ret double %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"can't convert to double %s\0A\00"
define double @trans_double(i8* %0, double %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %2, %9
%13 = phi double [ %1, %9 ], [ %5, %2 ]
ret double %13
}