#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 */
int errno;
double strtod(char *, char **);
int strto_double(char *s, double *val) {
  char *end;
  int status = 0;
  double v;
  int save_errno;
  save_errno = errno;
  errno = 0;
  v = strtod(s, &end);
  if ((end == s) || (*end != '\0'))
    status = 1;
  if (status == 0)
    *val = v;
  errno = save_errno;
  return (status);
}


x86 assembly (clang, -O0):
<strto_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ea6(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1170 <strto_double+0x60>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1177 <strto_double+0x67>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118e <strto_double+0x7e>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%ecx
mov    0x2e48(%rip),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strto_double>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ebc(%rip),%r15
mov    (%r15),%ebp
movl   $0x0,(%r15)
mov    %rsp,%rsi
call   1030 <strtod@plt>
mov    (%rsp),%rcx
mov    $0x1,%eax
cmp    %rbx,%rcx
je     1150 <strto_double+0x40>
cmpb   $0x0,(%rcx)
jne    1150 <strto_double+0x40>
movsd  %xmm0,(%r14)
xor    %eax,%eax
mov    %ebp,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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