#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 */
scalar_t__ ERANGE;
double HUGE_VAL;
scalar_t__ errno;
int /*<<< orphan*/ fatal_error(char *, char *, int, char *, char *);
double strtod(char *, char **);
double real_from_cstr(char *str) {
  char *end_ptr;
  double ret;
  ret = strtod(str, &end_ptr);
  if (ret == HUGE_VAL || ret == -HUGE_VAL) {
    fatal_error("cubestr.c", "real_from_cstr", 175,
                "Cannot parse double from string '%s', overflow", str);
  } else if (ret == 0 && errno == ERANGE) {
    fatal_error("cubestr.c", "real_from_cstr", 177,
                "Cannot parse double from string '%s', underflow", str);
  } else if (end_ptr == str) {
    fatal_error("cubestr.c", "real_from_cstr", 179,
                "Cannot parse double from string '%s'", str);
  }
  return ret;
}


x86 assembly (clang, -O0):
<real_from_cstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e9e(%rip),%rax
ucomisd (%rax),%xmm0
jne    115f <real_from_cstr+0x3f>
jp     115f <real_from_cstr+0x3f>
jmp    1196 <real_from_cstr+0x76>
movsd  -0x18(%rbp),%xmm0
mov    0x2e7d(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    11be <real_from_cstr+0x9e>
jp     11be <real_from_cstr+0x9e>
mov    -0x8(%rbp),%r8
lea    0xe5f(%rip),%rdi
lea    0xe62(%rip),%rsi
mov    $0xaf,%edx
lea    0xe65(%rip),%rcx
call   1040 <fatal_error@plt>
jmp    1253 <real_from_cstr+0x133>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1218 <real_from_cstr+0xf8>
jp     1218 <real_from_cstr+0xf8>
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
jne    1218 <real_from_cstr+0xf8>
mov    -0x8(%rbp),%r8
lea    0xe05(%rip),%rdi
lea    0xe08(%rip),%rsi
mov    $0xb1,%edx
lea    0xe3a(%rip),%rcx
call   1040 <fatal_error@plt>
jmp    124e <real_from_cstr+0x12e>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1249 <real_from_cstr+0x129>
mov    -0x8(%rbp),%r8
lea    0xdcf(%rip),%rdi
lea    0xdd2(%rip),%rsi
mov    $0xb3,%edx
lea    0xe34(%rip),%rcx
call   1040 <fatal_error@plt>
jmp    124e <real_from_cstr+0x12e>
jmp    1253 <real_from_cstr+0x133>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_from_cstr>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x2eaf(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jne    1145 <real_from_cstr+0x25>
jnp    1193 <real_from_cstr+0x73>
xorpd  0xeb3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1155 <real_from_cstr+0x35>
jnp    1193 <real_from_cstr+0x73>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11af <real_from_cstr+0x8f>
jp     11af <real_from_cstr+0x8f>
mov    0x2e68(%rip),%rax
mov    (%rax),%rax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <real_from_cstr+0x8f>
lea    0xe92(%rip),%rdi
lea    0xe95(%rip),%rsi
lea    0xecc(%rip),%rcx
mov    $0xb1,%edx
jmp    11d0 <real_from_cstr+0xb0>
lea    0xe76(%rip),%rdi
lea    0xe79(%rip),%rsi
lea    0xe81(%rip),%rcx
mov    $0xaf,%edx
jmp    11d0 <real_from_cstr+0xb0>
cmp    %rbx,0x8(%rsp)
jne    11e2 <real_from_cstr+0xc2>
lea    0xe53(%rip),%rdi
lea    0xe56(%rip),%rsi
lea    0xebd(%rip),%rcx
mov    $0xb3,%edx
mov    %rbx,%r8
movsd  %xmm0,(%rsp)
call   1040 <fatal_error@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@HUGE_VAL = global double 0.000000e+00
@.str = [10 x i8] c"cubestr.c\00"
@.str.1 = [15 x i8] c"real_from_cstr\00"
@.str.2 = [47 x i8] c"Cannot parse double from string '%s', overflow\00"
@errno = global i64 0
@ERANGE = global i64 0
@.str.3 = [48 x i8] c"Cannot parse double from string '%s', underflow\00"
@.str.4 = [37 x i8] c"Cannot parse double from string '%s'\00"
define double @real_from_cstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call double @strtod(i8* %5, i8** %3)
store double %6, double* %4
%7 = load double, double* %4
%8 = load double, double* @HUGE_VAL
%9 = fcmp oeq double %7, %8
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load double, double* %4
%12 = load double, double* @HUGE_VAL
%13 = fneg double %12
%14 = fcmp oeq double %11, %13
br i1 %14, label %15, label %18
15: ; preds = %10, %1
%16 = load i8*, i8** %2
%17 = call i32 @fatal_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 175, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %37
18: ; preds = %10
%19 = load double, double* %4
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i64, i64* @errno
%23 = load i64, i64* @ERANGE
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %2
%27 = call i32 @fatal_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 177, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %36
28: ; preds = %21, %18
%29 = load i8*, i8** %3
%30 = load i8*, i8** %2
%31 = icmp eq i8* %29, %30
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %2
%34 = call i32 @fatal_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 179, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %28
br label %36
36: ; preds = %35, %25
br label %37
37: ; preds = %36, %15
%38 = load double, double* %4
ret double %38
}

LLVM IR (-O2):
@HUGE_VAL = global double 0.000000e+00
@.str = [10 x i8] c"cubestr.c\00"
@.str.1 = [15 x i8] c"real_from_cstr\00"
@.str.2 = [47 x i8] c"Cannot parse double from string '%s', overflow\00"
@errno = global i64 0
@ERANGE = global i64 0
@.str.3 = [48 x i8] c"Cannot parse double from string '%s', underflow\00"
@.str.4 = [37 x i8] c"Cannot parse double from string '%s'\00"
define double @real_from_cstr(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call double @strtod(i8* %0, i8** %2)
%5 = load double, double* @HUGE_VAL
%6 = fcmp oeq double %4, %5
%7 = fneg double %5
%8 = fcmp oeq double %4, %7
%9 = or i1 %6, %8
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @fatal_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 175, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %25
12: ; preds = %1
%13 = fcmp oeq double %4, 0.000000e+00
br i1 %13, label %14, label %20
14: ; preds = %12
%15 = load i64, i64* @errno
%16 = load i64, i64* @ERANGE
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @fatal_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 177, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %25
20: ; preds = %14, %12
%21 = load i8*, i8** %2
%22 = icmp eq i8* %21, %0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @fatal_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 179, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %18, %23, %20, %10
ret double %4
}