#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;
scalar_t__ errno;
double strtod(char *, char **);
double parse_double(char *str, bool *success) {
  char *pEnd;
  errno = 0;
  double num = strtod(str, &pEnd);
  if ((pEnd != str && *pEnd != '\0') || pEnd == str || errno == ERANGE) {
    *success = false;
  }
  return (double)num;
}


x86 assembly (clang, -O0):
<parse_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     115e <parse_double+0x4e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1186 <parse_double+0x76>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1186 <parse_double+0x76>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    1190 <parse_double+0x80>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_double>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb2(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x8(%rsp),%rax
cmp    %rbx,%rax
je     1155 <parse_double+0x45>
cmpb   $0x0,(%rax)
jne    1155 <parse_double+0x45>
mov    (%r15),%rax
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%rax
jne    115c <parse_double+0x4c>
movl   $0x0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define double @parse_double(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca double
store i8* %0, i8** %3
store i32* %1, i32** %4
store i64 0, i64* @errno
%7 = load i8*, i8** %3
%8 = call double @strtod(i8* %7, i8** %5)
store double %8, double* %6
%9 = load i8*, i8** %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* %9, %10
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %12, %2
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = icmp eq i8* %18, %19
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = load i64, i64* @ERANGE
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21, %17, %12
%26 = load i32*, i32** %4
store i32 0, i32* %26
br label %27
27: ; preds = %25, %21
%28 = load double, double* %6
ret double %28
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define double @parse_double(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2, %11, %8
store i32 0, i32* %1
br label %16
16: ; preds = %15, %11
ret double %5
}