#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 fpow10(int);
int str_length(char const *);
char *str_pfindc(char const *, char *);
double str_to_f(const char *s) {
  double sign = 1.0;
  switch (*s) {
  case '-':
    sign = -1.0;
  case '+':
    s++;
  }
  const char *position_of_point = str_pfindc(s, ".,");
  const char *strend = s + str_length(s);
  const char *next_point;
  if ((next_point =
           position_of_point ? str_pfindc(position_of_point + 1, ".,") : NULL))
    strend = next_point;
  int decimal_places = position_of_point ? strend - position_of_point - 1 : 0;
  double factor = fpow10(-decimal_places);
  double total = 0.0;
  for (const char *it = strend; it > s;) {
    if (--it == position_of_point)
      continue;
    total += (double)(*it - '0') * factor;
    factor *= 10.0;
  }
  return total * sign;
}


x86 assembly (clang, -O0):
<str_to_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movabs $0x3ff0000000000000,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x2b,%eax
je     1180 <str_to_f+0x50>
jmp    1162 <str_to_f+0x32>
mov    -0x4c(%rbp),%eax
sub    $0x2d,%eax
jne    118c <str_to_f+0x5c>
jmp    1173 <str_to_f+0x43>
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <str_pfindc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <str_length@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e9 <str_to_f+0xb9>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe35(%rip),%rsi
call   1050 <str_pfindc@plt>
mov    %rax,-0x60(%rbp)
jmp    11f4 <str_to_f+0xc4>
xor    %eax,%eax
mov    %rax,-0x60(%rbp)
jmp    11f4 <str_to_f+0xc4>
mov    -0x60(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     120e <str_to_f+0xde>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1231 <str_to_f+0x101>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    123c <str_to_f+0x10c>
xor    %eax,%eax
mov    %rax,-0x68(%rbp)
jmp    123c <str_to_f+0x10c>
mov    -0x68(%rbp),%rax
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
sub    -0x2c(%rbp),%edi
call   1030 <fpow10@plt>
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    12c7 <str_to_f+0x197>
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
cmp    -0x18(%rbp),%rax
jne    128b <str_to_f+0x15b>
jmp    1262 <str_to_f+0x132>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd50(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1262 <str_to_f+0x132>
movsd  -0x40(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_f>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movsbl (%rdi),%eax
movsd  0xeba(%rip),%xmm0
cmp    $0x2b,%eax
je     1158 <str_to_f+0x28>
cmp    $0x2d,%eax
jne    1163 <str_to_f+0x33>
movsd  0xeb0(%rip),%xmm0
movsd  %xmm0,(%rsp)
add    $0x1,%r14
jmp    1168 <str_to_f+0x38>
movsd  %xmm0,(%rsp)
lea    0xea9(%rip),%rsi
mov    %r14,%rdi
call   1050 <str_pfindc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <str_length@plt>
movslq %eax,%rbx
add    %r14,%rbx
xor    %r12d,%r12d
test   %r15,%r15
je     11a2 <str_to_f+0x72>
lea    0x1(%r15),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <str_pfindc@plt>
jmp    11a4 <str_to_f+0x74>
xor    %eax,%eax
test   %rax,%rax
cmovne %rax,%rbx
mov    %r15d,%edi
sub    %ebx,%edi
add    $0x1,%edi
test   %r15,%r15
cmove  %r12d,%edi
call   1030 <fpow10@plt>
xorpd  %xmm1,%xmm1
movsd  0xe45(%rip),%xmm2
mov    %rbx,%rax
xchg   %ax,%ax
cmp    %r14,%rax
jbe    11ff <str_to_f+0xcf>
mov    %rax,%rbx
add    $0xffffffffffffffff,%rbx
mov    %r15,%rax
cmp    %r15,%rbx
je     11d0 <str_to_f+0xa0>
movsbl (%rbx),%eax
add    $0xffffffd0,%eax
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
jmp    11cb <str_to_f+0x9b>
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c".,\00"
define double @str_to_f(i8* %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i32
switch i32 %3, label %8 [
i32 45, label %4
i32 43, label %5
]
4: ; preds = %1
br label %5
5: ; preds = %1, %4
%6 = phi double [ 1.000000e+00, %1 ], [ -1.000000e+00, %4 ]
%7 = getelementptr inbounds i8, i8* %0, i64 1
br label %8
8: ; preds = %5, %1
%9 = phi double [ 1.000000e+00, %1 ], [ %6, %5 ]
%10 = phi i8* [ %0, %1 ], [ %7, %5 ]
%11 = tail call i8* @str_pfindc(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @str_length(i8* %10)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = icmp eq i8* %11, null
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %11, i64 1
%18 = tail call i8* @str_pfindc(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %8, %16
%20 = phi i8* [ %18, %16 ], [ null, %8 ]
%21 = icmp eq i8* %20, null
%22 = select i1 %21, i8* %14, i8* %20
%23 = ptrtoint i8* %22 to i64
%24 = ptrtoint i8* %11 to i64
%25 = add i64 %24, 1
%26 = sub i64 %25, %23
%27 = trunc i64 %26 to i32
%28 = select i1 %15, i32 0, i32 %27
%29 = tail call double @fpow10(i32 %28)
br label %30
30: ; preds = %42, %19
%31 = phi double [ %48, %42 ], [ %29, %19 ]
%32 = phi double [ %47, %42 ], [ 0.000000e+00, %19 ]
%33 = phi i8* [ %40, %42 ], [ %22, %19 ]
br label %34
34: ; preds = %30, %39
%35 = phi i8* [ %11, %39 ], [ %33, %30 ]
%36 = icmp ugt i8* %35, %10
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = fmul double %9, %32
ret double %38
39: ; preds = %34
%40 = getelementptr inbounds i8, i8* %35, i64 -1
%41 = icmp eq i8* %40, %11
br i1 %41, label %34, label %42
42: ; preds = %39
%43 = load i8, i8* %40
%44 = sext i8 %43 to i32
%45 = add nsw i32 %44, -48
%46 = sitofp i32 %45 to double
%47 = tail call double @llvm.fmuladd.f64(double %46, double %31, double %32)
%48 = fmul double %31, 1.000000e+01
br label %30
}