#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 */
double HUGE_VAL;
scalar_t__ strlen(char *);
double strtod(char *, char **);
int StringToDouble(char *str, double *d) {
  double tempdouble;
  char *endp;
  endp = str;
  tempdouble = strtod(str, &endp);
  if (strlen(endp) || tempdouble >= HUGE_VAL || tempdouble <= -HUGE_VAL) {
    return (1);
  } else {
    *d = tempdouble;
    return (0);
  }
}


x86 assembly (clang, -O0):
<StringToDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11a4 <StringToDouble+0x84>
movsd  -0x20(%rbp),%xmm0
mov    0x2e7f(%rip),%rax
ucomisd (%rax),%xmm0
jae    11a4 <StringToDouble+0x84>
movsd  -0x20(%rbp),%xmm1
mov    0x2e69(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jb     11b0 <StringToDouble+0x90>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <StringToDouble+0xa4>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringToDouble>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x8(%rsp),%rcx
mov    $0x1,%eax
cmpb   $0x0,(%rcx)
jne    115b <StringToDouble+0x4b>
mov    0x2eab(%rip),%rcx
movsd  (%rcx),%xmm1
ucomisd %xmm1,%xmm0
jae    115b <StringToDouble+0x4b>
xorpd  0xeb1(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    115b <StringToDouble+0x4b>
movsd  %xmm0,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@HUGE_VAL = global double 0.000000e+00
define i32 @StringToDouble(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca double
%7 = alloca i8*
store i8* %0, i8** %4
store double* %1, double** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i8*, i8** %4
%10 = call double @strtod(i8* %9, i8** %7)
store double %10, double* %6
%11 = load i8*, i8** %7
%12 = call i64 @strlen(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %2
%15 = load double, double* %6
%16 = load double, double* @HUGE_VAL
%17 = fcmp oge double %15, %16
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = load double, double* %6
%20 = load double, double* @HUGE_VAL
%21 = fneg double %20
%22 = fcmp ole double %19, %21
br i1 %22, label %23, label %24
23: ; preds = %18, %14, %2
store i32 1, i32* %3
br label %27
24: ; preds = %18
%25 = load double, double* %6
%26 = load double*, double** %5
store double %25, double* %26
store i32 0, i32* %3
br label %27
27: ; preds = %24, %23
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@HUGE_VAL = global double 0.000000e+00
define i32 @StringToDouble(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, 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 %9, label %16
9: ; preds = %2
%10 = load double, double* @HUGE_VAL
%11 = fcmp ult double %5, %10
%12 = fneg double %10
%13 = fcmp ugt double %5, %12
%14 = and i1 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %9
store double %5, double* %1
br label %16
16: ; preds = %2, %9, %15
%17 = phi i32 [ 0, %15 ], [ 1, %9 ], [ 1, %2 ]
ret i32 %17
}