#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 decimalNumberToDouble(char const *, double *);
double pow(int, double);
int stringToDouble(const char *str, double *output) {
  int i = 0;
  int exponentAt = -1;
  for (i = 0;; i++) {
    char c = str[i];
    if (c == 'e') {
      exponentAt = i;
      break;
    } else if (c == '\n' || c == '\r' || c == ' ' || c == 0)
      break;
  }
  if (exponentAt == -1) {
    return decimalNumberToDouble(str, output);
  } else {
    double base, exponent;
    if (decimalNumberToDouble(str, &base) != 1)
      return 0;
    if (decimalNumberToDouble(str + i + 1, &exponent) != 1)
      return 0;
    *output = base * pow(10, exponent);
    return 1;
  }
}


x86 assembly (clang, -O0):
<stringToDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x65,%eax
jne    116b <stringToDouble+0x4b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11bc <stringToDouble+0x9c>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
je     119f <stringToDouble+0x7f>
movsbl -0x21(%rbp),%eax
cmp    $0xd,%eax
je     119f <stringToDouble+0x7f>
movsbl -0x21(%rbp),%eax
cmp    $0x20,%eax
je     119f <stringToDouble+0x7f>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    11a4 <stringToDouble+0x84>
jmp    11bc <stringToDouble+0x9c>
jmp    11a9 <stringToDouble+0x89>
jmp    11ae <stringToDouble+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <stringToDouble+0x25>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11db <stringToDouble+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <decimalNumberToDouble@plt>
mov    %eax,-0x4(%rbp)
jmp    125e <stringToDouble+0x13e>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <decimalNumberToDouble@plt>
cmp    $0x1,%eax
je     11fd <stringToDouble+0xdd>
movl   $0x0,-0x4(%rbp)
jmp    125e <stringToDouble+0x13e>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    -0x38(%rbp),%rsi
call   1030 <decimalNumberToDouble@plt>
cmp    $0x1,%eax
je     122a <stringToDouble+0x10a>
movl   $0x0,-0x4(%rbp)
jmp    125e <stringToDouble+0x13e>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringToDouble>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
movabs $0x100002401,%rax
nopl   0x0(%rax)
movzbl (%rbx,%rbp,1),%ecx
cmp    $0x20,%rcx
ja     1150 <stringToDouble+0x30>
bt     %rcx,%rax
jb     115b <stringToDouble+0x3b>
cmp    $0x65,%cl
je     1170 <stringToDouble+0x50>
add    $0x1,%rbp
jmp    1140 <stringToDouble+0x20>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <decimalNumberToDouble@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <decimalNumberToDouble@plt>
xor    %r15d,%r15d
cmp    $0x1,%eax
jne    11c9 <stringToDouble+0xa9>
mov    %ebp,%eax
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
lea    0x8(%rsp),%rsi
call   1030 <decimalNumberToDouble@plt>
cmp    $0x1,%eax
jne    11c9 <stringToDouble+0xa9>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @stringToDouble(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca double
%10 = alloca double
store i8* %0, i8** %4
store double* %1, double** %5
store i32 0, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %6
br label %11
11: ; preds = %41, %2
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
store i8 %16, i8* %8
%17 = load i8, i8* %8
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 101
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = load i32, i32* %6
store i32 %21, i32* %7
br label %44
22: ; preds = %11
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %38, label %26
26: ; preds = %22
%27 = load i8, i8* %8
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 13
br i1 %29, label %38, label %30
30: ; preds = %26
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 32
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34, %30, %26, %22
br label %44
39: ; preds = %34
br label %40
40: ; preds = %39
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %11
44: ; preds = %38, %20
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = load double*, double** %5
%50 = call i32 @decimalNumberToDouble(i8* %48, double* %49)
store i32 %50, i32* %3
br label %71
51: ; preds = %44
%52 = load i8*, i8** %4
%53 = call i32 @decimalNumberToDouble(i8* %52, double* %9)
%54 = icmp ne i32 %53, 1
br i1 %54, label %55, label %56
55: ; preds = %51
store i32 0, i32* %3
br label %71
56: ; preds = %51
%57 = load i8*, i8** %4
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = call i32 @decimalNumberToDouble(i8* %61, double* %10)
%63 = icmp ne i32 %62, 1
br i1 %63, label %64, label %65
64: ; preds = %56
store i32 0, i32* %3
br label %71
65: ; preds = %56
%66 = load double, double* %9
%67 = load double, double* %10
%68 = call double @pow(i32 10, double %67)
%69 = fmul double %66, %68
%70 = load double*, double** %5
store double %69, double* %70
store i32 1, i32* %3
br label %71
71: ; preds = %65, %64, %55, %47
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
define i32 @stringToDouble(i8* %0, double* %1) {
%3 = alloca double
%4 = alloca double
br label %5
5: ; preds = %9, %2
%6 = phi i64 [ %10, %9 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 101, label %13
i8 32, label %11
i8 13, label %11
i8 10, label %11
i8 0, label %11
]
9: ; preds = %5
%10 = add nuw i64 %6, 1
br label %5
11: ; preds = %5, %5, %5, %5
%12 = tail call i32 @decimalNumberToDouble(i8* %0, double* %1)
br label %31
13: ; preds = %5
%14 = bitcast double* %3 to i8*
%15 = bitcast double* %4 to i8*
%16 = call i32 @decimalNumberToDouble(i8* %0, double* %3)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = and i64 %6, 4294967295
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @decimalNumberToDouble(i8* %21, double* %4)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load double, double* %3
%26 = load double, double* %4
%27 = call double @pow(i32 10, double %26)
%28 = fmul double %25, %27
store double %28, double* %1
br label %29
29: ; preds = %18, %13, %24
%30 = phi i32 [ 1, %24 ], [ 0, %13 ], [ 0, %18 ]
br label %31
31: ; preds = %29, %11
%32 = phi i32 [ %12, %11 ], [ %30, %29 ]
ret i32 %32
}