#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__ isdigit(char const);
int /*<<< orphan*/ sscanf(char const *, char *, double *);
double strtod(const char *str, char **stringPtr) {
  int oneDecimalPoint = 1;
  while (str[0] == 32)
    str++;
  double result;
  sscanf(str, "%lf", &result);
  while (1) {
    if (isdigit(str[0]) == 0) {
      if ((str[0] == '.') && oneDecimalPoint == 1)
        oneDecimalPoint--;
      else {
        stringPtr[0] = str;
        break;
      }
    }
    str++;
  }
  return result;
}


x86 assembly (clang, -O0):
<strtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1158 <strtod+0x38>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1137 <strtod+0x17>
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11bf <strtod+0x9f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11aa <strtod+0x8a>
cmpl   $0x1,-0x14(%rbp)
jne    11aa <strtod+0x8a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <strtod+0x9a>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11d0 <strtod+0xb0>
jmp    11bf <strtod+0x9f>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116c <strtod+0x4c>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtod>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1140 <strtod+0x20>
lea    0xeaf(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    $0x1,%ebp
jmp    1174 <strtod+0x54>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <strtod+0x50>
cmpb   $0x2e,(%rbx)
jne    1190 <strtod+0x70>
cmp    $0x1,%ebp
mov    $0x0,%ebp
je     1170 <strtod+0x50>
mov    %rbx,(%r14)
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define double @strtod(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca double
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 1, i32* %5
br label %7
7: ; preds = %13, %2
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 32
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
br label %7
16: ; preds = %7
%17 = load i8*, i8** %3
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %6)
br label %19
19: ; preds = %16, %42
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = call i64 @isdigit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 46
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %5
%36 = add nsw i32 %35, -1
store i32 %36, i32* %5
br label %41
37: ; preds = %31, %25
%38 = load i8*, i8** %3
%39 = load i8**, i8*** %4
%40 = getelementptr inbounds i8*, i8** %39, i64 0
store i8* %38, i8** %40
br label %45
41: ; preds = %34
br label %42
42: ; preds = %41, %19
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
br label %19
45: ; preds = %37
%46 = load double, double* %6
ret double %46
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define double @strtod(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca double
br label %4
4: ; preds = %4, %2
%5 = phi i8* [ %0, %2 ], [ %8, %4 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 32
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = bitcast double* %3 to i8*
%11 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
br label %12
12: ; preds = %25, %9
%13 = phi i8* [ %5, %9 ], [ %27, %25 ]
%14 = phi i32 [ 1, %9 ], [ %26, %25 ]
%15 = load i8, i8* %13
%16 = call i64 @isdigit(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = load i8, i8* %13
%20 = icmp eq i8 %19, 46
%21 = icmp eq i32 %14, 1
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %25, label %23
23: ; preds = %18
store i8* %13, i8** %1
%24 = load double, double* %3
ret double %24
25: ; preds = %18, %12
%26 = phi i32 [ %14, %12 ], [ 0, %18 ]
%27 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
}