#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__ EINVAL;
scalar_t__ ERANGE;
double HUGE_VAL;
scalar_t__ errno;
scalar_t__ isnan(double);
scalar_t__ isspace(char);
int /*<<< orphan*/ memcpy(char *, char const *, long);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
double strtod(char *, char **);
int getDoubleFromObject(const char *_o, long olen, double *target) {
  double value;
  char *eptr;
  char o[64];
  if (_o == NULL) {
    *target = 0;
    return 0;
  }
  if (olen > 63) {
    return -1;
  }
  memcpy(o, _o, olen * sizeof(char));
  memset(&o[olen], 0, 64 - olen);
  errno = 0;
  value = strtod(o, &eptr);
  if (isspace(((char *)o)[0]) || eptr[0] != '\0' ||
      (errno == ERANGE &&
       (value == HUGE_VAL || value == -HUGE_VAL || value == 0)) ||
      errno == EINVAL || isnan(value))
    return -1;
  *target = value;
  return 0;
}


x86 assembly (clang, -O0):
<getDoubleFromObject>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <getDoubleFromObject+0x36>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12f1 <getDoubleFromObject+0x1a1>
cmpq   $0x3f,-0x18(%rbp)
jle    119d <getDoubleFromObject+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f1 <getDoubleFromObject+0x1a1>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
shl    $0x0,%rdx
call   1060 <memcpy@plt>
lea    -0x70(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    $0x40,%eax
sub    -0x18(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2dfd(%rip),%rax
movq   $0x0,(%rax)
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
movsbl -0x70(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
jne    12d1 <getDoubleFromObject+0x181>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12d1 <getDoubleFromObject+0x181>
mov    0x2dba(%rip),%rax
mov    (%rax),%rax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
jne    12a3 <getDoubleFromObject+0x153>
movsd  -0x28(%rbp),%xmm0
mov    0x2db3(%rip),%rax
ucomisd (%rax),%xmm0
jne    124a <getDoubleFromObject+0xfa>
jp     124a <getDoubleFromObject+0xfa>
jmp    12d1 <getDoubleFromObject+0x181>
movsd  -0x28(%rbp),%xmm0
mov    0x2d92(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    1286 <getDoubleFromObject+0x136>
jp     1286 <getDoubleFromObject+0x136>
jmp    12d1 <getDoubleFromObject+0x181>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12a3 <getDoubleFromObject+0x153>
jp     12a3 <getDoubleFromObject+0x153>
jmp    12d1 <getDoubleFromObject+0x181>
mov    0x2d26(%rip),%rax
mov    (%rax),%rax
mov    0x2d14(%rip),%rcx
cmp    (%rcx),%rax
je     12d1 <getDoubleFromObject+0x181>
movsd  -0x28(%rbp),%xmm0
call   1070 <isnan@plt>
cmp    $0x0,%rax
je     12dd <getDoubleFromObject+0x18d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f1 <getDoubleFromObject+0x1a1>
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDoubleFromObject>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%r14
test   %rdi,%rdi
je     1242 <getDoubleFromObject+0xf2>
mov    %rsi,%rbx
mov    $0xffffffff,%ebp
cmp    $0x3f,%rsi
jg     124d <getDoubleFromObject+0xfd>
mov    %rdi,%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    $0x40,%edx
sub    %ebx,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2e28(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1030 <strtod@plt>
movsd  %xmm0,(%rsp)
movsbl 0x10(%rsp),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    124d <getDoubleFromObject+0xfd>
movsd  (%rsp),%xmm2
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    124d <getDoubleFromObject+0xfd>
mov    (%rbx),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
jne    1221 <getDoubleFromObject+0xd1>
mov    0x2df3(%rip),%rcx
movsd  (%rcx),%xmm0
ucomisd %xmm0,%xmm2
jne    1201 <getDoubleFromObject+0xb1>
jnp    124d <getDoubleFromObject+0xfd>
movapd %xmm2,%xmm3
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    1211 <getDoubleFromObject+0xc1>
jnp    124d <getDoubleFromObject+0xfd>
xorpd  0xde7(%rip),%xmm0
ucomisd %xmm0,%xmm3
jne    1221 <getDoubleFromObject+0xd1>
jnp    124d <getDoubleFromObject+0xfd>
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%rax
je     124d <getDoubleFromObject+0xfd>
movapd %xmm2,%xmm0
call   1070 <isnan@plt>
movsd  (%rsp),%xmm0
test   %rax,%rax
jne    124d <getDoubleFromObject+0xfd>
jmp    1246 <getDoubleFromObject+0xf6>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@HUGE_VAL = global double 0.000000e+00
@EINVAL = global i64 0
define i32 @getDoubleFromObject(i8* %0, i64 %1, double* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca double*
%8 = alloca double
%9 = alloca i8*
%10 = alloca [64 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store double* %2, double** %7
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load double*, double** %7
store double 0.000000e+00, double* %14
store i32 0, i32* %4
br label %72
15: ; preds = %3
%16 = load i64, i64* %6
%17 = icmp sgt i64 %16, 63
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %4
br label %72
19: ; preds = %15
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = mul i64 %22, 1
%24 = call i32 @memcpy(i8* %20, i8* %21, i64 %23)
%25 = load i64, i64* %6
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %25
%27 = load i64, i64* %6
%28 = sub nsw i64 64, %27
%29 = trunc i64 %28 to i32
%30 = call i32 @memset(i8* %26, i32 0, i32 %29)
store i64 0, i64* @errno
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%32 = call double @strtod(i8* %31, i8** %9)
store double %32, double* %8
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = call i64 @isspace(i8 signext %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %68, label %38
38: ; preds = %19
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %68, label %44
44: ; preds = %38
%45 = load i64, i64* @errno
%46 = load i64, i64* @ERANGE
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %60
48: ; preds = %44
%49 = load double, double* %8
%50 = load double, double* @HUGE_VAL
%51 = fcmp oeq double %49, %50
br i1 %51, label %68, label %52
52: ; preds = %48
%53 = load double, double* %8
%54 = load double, double* @HUGE_VAL
%55 = fneg double %54
%56 = fcmp oeq double %53, %55
br i1 %56, label %68, label %57
57: ; preds = %52
%58 = load double, double* %8
%59 = fcmp oeq double %58, 0.000000e+00
br i1 %59, label %68, label %60
60: ; preds = %57, %44
%61 = load i64, i64* @errno
%62 = load i64, i64* @EINVAL
%63 = icmp eq i64 %61, %62
br i1 %63, label %68, label %64
64: ; preds = %60
%65 = load double, double* %8
%66 = call i64 @isnan(double %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %64, %60, %57, %52, %48, %38, %19
store i32 -1, i32* %4
br label %72
69: ; preds = %64
%70 = load double, double* %8
%71 = load double*, double** %7
store double %70, double* %71
store i32 0, i32* %4
br label %72
72: ; preds = %69, %68, %18, %13
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@HUGE_VAL = global double 0.000000e+00
@EINVAL = global i64 0
define i32 @getDoubleFromObject(i8* %0, i64 %1, double* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca [64 x i8]
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %0, null
br i1 %8, label %46, label %9
9: ; preds = %3
%10 = icmp sgt i64 %1, 63
br i1 %10, label %48, label %11
11: ; preds = %9
%12 = call i32 @memcpy(i8* %7, i8* %0, i64 %1)
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %1
%14 = trunc i64 %1 to i32
%15 = sub i32 64, %14
%16 = call i32 @memset(i8* %13, i32 0, i32 %15)
store i64 0, i64* @errno
%17 = call double @strtod(i8* %7, i8** %4)
%18 = load i8, i8* %7
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %48
21: ; preds = %11
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @ERANGE
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load double, double* @HUGE_VAL
%31 = fcmp oeq double %17, %30
br i1 %31, label %48, label %32
32: ; preds = %29
%33 = fneg double %30
%34 = fcmp oeq double %17, %33
%35 = fcmp oeq double %17, 0.000000e+00
%36 = or i1 %35, %34
%37 = load i64, i64* @EINVAL
%38 = icmp eq i64 %26, %37
%39 = select i1 %36, i1 true, i1 %38
br i1 %39, label %48, label %43
40: ; preds = %25
%41 = load i64, i64* @EINVAL
%42 = icmp eq i64 %26, %41
br i1 %42, label %48, label %43
43: ; preds = %32, %40
%44 = call i64 @isnan(double %17)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43, %3
%47 = phi double [ 0.000000e+00, %3 ], [ %17, %43 ]
store double %47, double* %2
br label %48
48: ; preds = %46, %11, %21, %29, %32, %40, %43, %9
%49 = phi i32 [ -1, %9 ], [ -1, %43 ], [ -1, %40 ], [ -1, %32 ], [ -1, %29 ], [ -1, %21 ], [ -1, %11 ], [ 0, %46 ]
ret i32 %49
}