#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 charToInt(char const);
double fastPower10(int);
double bufferLineToDouble(const char *buffer) {
  if (buffer[0] == '1')
    return 1.0;
  int len, p, value;
  len = p = value = 0;
  while (buffer[len] != '\n' && buffer[len] != '\0') {
    len++;
  }
  if (len == 1 && buffer[0] == '0')
    return 0.0;
  for (int i = len - 1; i >= 2; i--) {
    value += charToInt(buffer[i]) * fastPower10(p);
    p++;
  }
  double valueDouble = (double)value / fastPower10(len - 2);
  return valueDouble;
}


x86 assembly (clang, -O0):
<bufferLineToDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    114e <bufferLineToDouble+0x2e>
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126f <bufferLineToDouble+0x14f>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x29(%rbp)
je     1192 <bufferLineToDouble+0x72>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a2 <bufferLineToDouble+0x82>
jmp    11b0 <bufferLineToDouble+0x90>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <bufferLineToDouble+0x43>
cmpl   $0x1,-0x14(%rbp)
jne    11d7 <bufferLineToDouble+0xb7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11d7 <bufferLineToDouble+0xb7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126f <bufferLineToDouble+0x14f>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jl     123f <bufferLineToDouble+0x11f>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <charToInt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <fastPower10@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11e0 <bufferLineToDouble+0xc0>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x14(%rbp),%edi
sub    $0x2,%edi
call   1040 <fastPower10@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferLineToDouble>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    (%rdi),%al
cmp    $0x31,%al
jne    113f <bufferLineToDouble+0x1f>
movsd  0xec6(%rip),%xmm0
jmp    1209 <bufferLineToDouble+0xe9>
mov    %rdi,%r15
lea    0x1(%rdi),%rcx
xor    %r12d,%r12d
mov    %eax,%edx
test   %dl,%dl
je     1164 <bufferLineToDouble+0x44>
nop
cmp    $0xa,%dl
je     1164 <bufferLineToDouble+0x44>
movzbl (%rcx),%edx
add    $0xffffffff,%r12d
add    $0x1,%rcx
test   %dl,%dl
jne    1150 <bufferLineToDouble+0x30>
cmp    $0xffffffff,%r12d
jne    1176 <bufferLineToDouble+0x56>
xorpd  %xmm0,%xmm0
cmp    $0x30,%al
je     1209 <bufferLineToDouble+0xe9>
mov    %r12d,%eax
neg    %eax
mov    $0xfffffffe,%r14d
cmp    $0x2,%eax
jbe    11e8 <bufferLineToDouble+0xc8>
sub    %r12d,%r14d
mov    %eax,%eax
add    %rax,%r15
xor    %ebp,%ebp
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
mov    $0xffffffffffffffff,%rbx
movsbl (%r15,%rbx,1),%edi
call   1030 <charToInt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %ebp,%edi
call   1040 <fastPower10@plt>
mulsd  0x18(%rsp),%xmm0
addsd  (%rsp),%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
movapd %xmm0,(%rsp)
add    $0xffffffffffffffff,%rbx
lea    (%r12,%rbp,1),%eax
add    $0x1,%ebp
cmp    $0xfffffffd,%eax
jne    11a0 <bufferLineToDouble+0x80>
jmp    11f4 <bufferLineToDouble+0xd4>
sub    %r12d,%r14d
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
mov    %r14d,%edi
call   1040 <fastPower10@plt>
movapd (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @bufferLineToDouble(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 49
br i1 %13, label %14, label %15
14: ; preds = %1
store double 1.000000e+00, double* %2
br label %80
15: ; preds = %1
store i32 0, i32* %6
store i32 0, i32* %5
store i32 0, i32* %4
br label %16
16: ; preds = %34, %15
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 10
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br label %32
32: ; preds = %24, %16
%33 = phi i1 [ false, %16 ], [ %31, %24 ]
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %16
37: ; preds = %32
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 48
br i1 %45, label %46, label %47
46: ; preds = %40
store double 0.000000e+00, double* %2
br label %80
47: ; preds = %40, %37
%48 = load i32, i32* %4
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %7
br label %50
50: ; preds = %69, %47
%51 = load i32, i32* %7
%52 = icmp sge i32 %51, 2
br i1 %52, label %53, label %72
53: ; preds = %50
%54 = load i8*, i8** %3
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = call i32 @charToInt(i8 signext %58)
%60 = sitofp i32 %59 to double
%61 = load i32, i32* %5
%62 = call double @fastPower10(i32 %61)
%63 = load i32, i32* %6
%64 = sitofp i32 %63 to double
%65 = call double @llvm.fmuladd.f64(double %60, double %62, double %64)
%66 = fptosi double %65 to i32
store i32 %66, i32* %6
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
br label %69
69: ; preds = %53
%70 = load i32, i32* %7
%71 = add nsw i32 %70, -1
store i32 %71, i32* %7
br label %50
72: ; preds = %50
%73 = load i32, i32* %6
%74 = sitofp i32 %73 to double
%75 = load i32, i32* %4
%76 = sub nsw i32 %75, 2
%77 = call double @fastPower10(i32 %76)
%78 = fdiv double %74, %77
store double %78, double* %8
%79 = load double, double* %8
store double %79, double* %2
br label %80
80: ; preds = %72, %46, %14
%81 = load double, double* %2
ret double %81
}

LLVM IR (-O2):
define double @bufferLineToDouble(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 49
br i1 %3, label %43, label %4
4: ; preds = %1, %7
%5 = phi i8 [ %10, %7 ], [ %2, %1 ]
%6 = phi i64 [ %8, %7 ], [ 0, %1 ]
switch i8 %5, label %7 [
i8 10, label %11
i8 0, label %11
]
7: ; preds = %4
%8 = add nuw i64 %6, 1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
br label %4
11: ; preds = %4, %4
%12 = trunc i64 %6 to i32
%13 = icmp eq i32 %12, 1
%14 = icmp eq i8 %2, 48
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %43, label %16
16: ; preds = %11
%17 = icmp ugt i32 %12, 2
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = add nsw i32 %12, -2
br label %23
20: ; preds = %16
%21 = and i64 %6, 4294967295
%22 = add nsw i32 %12, -2
br label %28
23: ; preds = %28, %18
%24 = phi i32 [ %19, %18 ], [ %22, %28 ]
%25 = phi double [ 0.000000e+00, %18 ], [ %41, %28 ]
%26 = tail call double @fastPower10(i32 %24)
%27 = fdiv double %25, %26
br label %43
28: ; preds = %20, %28
%29 = phi i64 [ %21, %20 ], [ %32, %28 ]
%30 = phi double [ 0.000000e+00, %20 ], [ %41, %28 ]
%31 = phi i32 [ 0, %20 ], [ %40, %28 ]
%32 = add nsw i64 %29, -1
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = load i8, i8* %33
%35 = tail call i32 @charToInt(i8 signext %34)
%36 = sitofp i32 %35 to double
%37 = tail call double @fastPower10(i32 %31)
%38 = tail call double @llvm.fmuladd.f64(double %36, double %37, double %30)
%39 = fptosi double %38 to i32
%40 = add nuw nsw i32 %31, 1
%41 = sitofp i32 %39 to double
%42 = icmp eq i32 %40, %22
br i1 %42, label %23, label %28
43: ; preds = %11, %23, %1
%44 = phi double [ 1.000000e+00, %1 ], [ %27, %23 ], [ 0.000000e+00, %11 ]
ret double %44
}