#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__ errno;
scalar_t__ isspace(char);
double strtod(char const *, char **);
int parse_double(const char *s, double *val) {
  char *end;
  errno = 0;
  *val = strtod(s, &end);
  if ((end == s) || (errno != 0)) {
    return 0;
  }
  while (isspace(*end))
    end++;
  if (*end != '\0') {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1172 <parse_double+0x52>
mov    0x2e78(%rip),%rax
cmpq   $0x0,(%rax)
je     117e <parse_double+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11cd <parse_double+0xad>
jmp    1183 <parse_double+0x63>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11aa <parse_double+0x8a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1183 <parse_double+0x63>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c6 <parse_double+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11cd <parse_double+0xad>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_double>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2eab(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,(%r14)
mov    (%rsp),%rbx
xor    %eax,%eax
cmp    %r15,%rbx
je     117a <parse_double+0x5a>
cmpq   $0x0,(%r12)
jne    117a <parse_double+0x5a>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <parse_double+0x40>
xor    %eax,%eax
cmpb   $0x0,-0x1(%rbx)
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@errno = global i64 0
define i32 @parse_double(i8* %0, double* 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)
store double %5, double* %1
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %21, label %11
11: ; preds = %2, %11
%12 = phi i8* [ %16, %11 ], [ %6, %2 ]
%13 = load i8, i8* %12
%14 = tail call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
%16 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %15, label %17, label %11
17: ; preds = %11
%18 = load i8, i8* %12
%19 = icmp eq i8 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %17, %2
%22 = phi i32 [ 0, %2 ], [ %20, %17 ]
ret i32 %22
}