#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 */
double atof(char *);
scalar_t__ isdigit(char);
void stub1();
double parsedouble(char **sp, void (*errorfn)(void)) {
  char *s = *sp;
  double num = atof(s);
  while (isdigit(*s) || *s == '-' || *s == '.')
    s++;
  if (*sp == s)
    (*errorfn)();
  *sp = s;
  return (num);
}


x86 assembly (clang, -O0):
<parsedouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    118c <parsedouble+0x6c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2d,%ecx
mov    %al,-0x21(%rbp)
je     118c <parsedouble+0x6c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    119c <parsedouble+0x7c>
jmp    11ad <parsedouble+0x8d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1149 <parsedouble+0x29>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    11c1 <parsedouble+0xa1>
call   *-0x10(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsedouble>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
jmp    1154 <parsedouble+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1150 <parsedouble+0x30>
movzbl (%rbx),%eax
add    $0xd3,%al
cmp    $0x1,%al
jbe    1150 <parsedouble+0x30>
cmp    (%r14),%rbx
jne    1172 <parsedouble+0x52>
call   *%r15
mov    %rbx,(%r14)
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @parsedouble(i8** %0, void ()* %1) {
%3 = alloca i8**
%4 = alloca void ()*
%5 = alloca i8*
%6 = alloca double
store i8** %0, i8*** %3
store void ()* %1, void ()** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = call double @atof(i8* %9)
store double %10, double* %6
br label %11
11: ; preds = %28, %2
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 45
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 46
br label %26
26: ; preds = %21, %16, %11
%27 = phi i1 [ true, %16 ], [ true, %11 ], [ %25, %21 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
br label %11
31: ; preds = %26
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = load i8*, i8** %5
%35 = icmp eq i8* %33, %34
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load void ()*, void ()** %4
br label %38
38: ; preds = %36, %31
%39 = load i8*, i8** %5
%40 = load i8**, i8*** %3
store i8* %39, i8** %40
%41 = load double, double* %6
ret double %41
}

LLVM IR (-O2):
define double @parsedouble(i8** nocapture %0, void ()* nocapture %1) {
%3 = load i8*, i8** %0
%4 = tail call double @atof(i8* %3)
br label %5
5: ; preds = %14, %2
%6 = phi i8* [ %3, %2 ], [ %15, %14 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isdigit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i8, i8* %6
%12 = add i8 %11, -45
%13 = icmp ult i8 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %10, %5
%15 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
16: ; preds = %10
%17 = load i8*, i8** %0
%18 = icmp eq i8* %17, %6
br i1 %18, label %19, label %20
19: ; preds = %16
tail call void %1()
br label %20
20: ; preds = %19, %16
store i8* %6, i8** %0
ret double %4
}