#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);
double str_to_double(char *str) {
  double digits = 0.0;
  double divide = 1.0f;
  int met_dot = 0;
  while (*str) {
    if (met_dot) {
      divide *= 10.0;
    }
    if (isdigit(*str)) {
      digits *= 10.0;
      digits += ((*str) - '0');
    } else if ((*str) == '.' || (*str) == ',') {
      met_dot = 1;
    }
    str++;
  }
  return digits / divide;
}


x86 assembly (clang, -O0):
<str_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e3 <str_to_double+0xd3>
cmpl   $0x0,-0x1c(%rbp)
je     1161 <str_to_double+0x51>
movsd  0xeb1(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11a6 <str_to_double+0x96>
movsd  0xe89(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11d2 <str_to_double+0xc2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11c6 <str_to_double+0xb6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    11cd <str_to_double+0xbd>
movl   $0x1,-0x1c(%rbp)
jmp    11d2 <str_to_double+0xc2>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1138 <str_to_double+0x28>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_double>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    (%rdi),%al
test   %al,%al
je     11be <str_to_double+0xae>
mov    %rdi,%rbx
xorpd  %xmm0,%xmm0
movsd  0xed1(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %ebp,%ebp
jmp    1178 <str_to_double+0x68>
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a0 <str_to_double+0x90>
movsd  0x10(%rsp),%xmm0
mulsd  0xead(%rip),%xmm0
movsbl (%rbx),%eax
add    $0xffffffd0,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11b6 <str_to_double+0xa6>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe7c(%rip),%xmm0
test   %ebp,%ebp
je     1140 <str_to_double+0x30>
movsd  %xmm0,0x8(%rsp)
jmp    1140 <str_to_double+0x30>
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
or     $0x2,%al
cmp    $0x2e,%al
jne    11ae <str_to_double+0x9e>
mov    $0x1,%ebp
movsd  0x10(%rsp),%xmm0
jmp    116c <str_to_double+0x5c>
divsd  0x8(%rsp),%xmm0
jmp    11c2 <str_to_double+0xb2>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @str_to_double(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i8* %0, i8** %2
store double 0.000000e+00, double* %3
store double 1.000000e+00, double* %4
store i32 0, i32* %5
br label %6
6: ; preds = %43, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %46
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load double, double* %4
%15 = fmul double %14, 1.000000e+01
store double %15, double* %4
br label %16
16: ; preds = %13, %10
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = load double, double* %3
%23 = fmul double %22, 1.000000e+01
store double %23, double* %3
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 48
%28 = sitofp i32 %27 to double
%29 = load double, double* %3
%30 = fadd double %29, %28
store double %30, double* %3
br label %43
31: ; preds = %16
%32 = load i8*, i8** %2
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 46
br i1 %35, label %41, label %36
36: ; preds = %31
%37 = load i8*, i8** %2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 44
br i1 %40, label %41, label %42
41: ; preds = %36, %31
store i32 1, i32* %5
br label %42
42: ; preds = %41, %36
br label %43
43: ; preds = %42, %21
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %2
br label %6
46: ; preds = %6
%47 = load double, double* %3
%48 = load double, double* %4
%49 = fdiv double %47, %48
ret double %49
}

LLVM IR (-O2):
define double @str_to_double(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %33, label %4
4: ; preds = %1, %25
%5 = phi i8 [ %29, %25 ], [ %2, %1 ]
%6 = phi i32 [ %27, %25 ], [ 0, %1 ]
%7 = phi double [ %12, %25 ], [ 1.000000e+00, %1 ]
%8 = phi double [ %26, %25 ], [ 0.000000e+00, %1 ]
%9 = phi i8* [ %28, %25 ], [ %0, %1 ]
%10 = icmp eq i32 %6, 0
%11 = fmul double %7, 1.000000e+01
%12 = select i1 %10, double %7, double %11
%13 = tail call i64 @isdigit(i8 signext %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %4
%16 = fmul double %8, 1.000000e+01
%17 = load i8, i8* %9
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, -48
%20 = sitofp i32 %19 to double
%21 = fadd double %16, %20
br label %25
22: ; preds = %4
%23 = load i8, i8* %9
switch i8 %23, label %25 [
i8 46, label %24
i8 44, label %24
]
24: ; preds = %22, %22
br label %25
25: ; preds = %22, %24, %15
%26 = phi double [ %21, %15 ], [ %8, %24 ], [ %8, %22 ]
%27 = phi i32 [ %6, %15 ], [ 1, %24 ], [ %6, %22 ]
%28 = getelementptr inbounds i8, i8* %9, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %4
31: ; preds = %25
%32 = fdiv double %26, %12
br label %33
33: ; preds = %31, %1
%34 = phi double [ %32, %31 ], [ 0.000000e+00, %1 ]
ret double %34
}