#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;
double strtod(char const *, char **);
int read_double(const char **s, const char *end, double *out) {
  errno = 0;
  char *endptr;
  *out = strtod(*s, &endptr);
  if (endptr != end || errno != 0)
    return 0;
  *s = endptr;
  return 1;
}


x86 assembly (clang, -O0):
<read_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2eb5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1169 <read_double+0x59>
mov    0x2e81(%rip),%rax
cmpq   $0x0,(%rax)
je     1175 <read_double+0x65>
movl   $0x0,-0x4(%rbp)
jmp    1187 <read_double+0x77>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_double>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb8(%rip),%r12
movq   $0x0,(%r12)
mov    (%rdi),%rdi
mov    %rsp,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,(%r15)
xor    %eax,%eax
cmp    %r14,(%rsp)
jne    1157 <read_double+0x47>
cmpq   $0x0,(%r12)
jne    1157 <read_double+0x47>
mov    %r14,(%rbx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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