#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 atof(char *);
int atoi(char *);
int /*<<< orphan*/ *strchr(char *, char);
int /*<<< orphan*/ strtoken(char *, char *, char **);
double get_double(char string[]) {
  double ret = 0;
  if (strchr(string, '.') != NULL) {
    ret = atof(string);
  } else {
    int pre_comma_i = -1.0, post_comma_i = -1.0;
    char *tokens[2];
    char separator[] = ",. ";
    strtoken(string, separator, tokens);
    pre_comma_i = atoi(tokens[0]);
    post_comma_i = atoi(tokens[1]);
    int sizeOfToken1 = 0;
    int i = 0;
    while (tokens[1][i] != 0) {
      sizeOfToken1++;
      i++;
    }
    double pre_comma_d = (double)pre_comma_i,
           post_comma_d = (double)post_comma_i;
    while (sizeOfToken1 > 1) {
      post_comma_d *= 0.1;
      sizeOfToken1--;
    }
    ret = pre_comma_d + post_comma_d;
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     117f <get_double+0x3f>
mov    -0x8(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    1246 <get_double+0x106>
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    0xe75(%rip),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strtoken@plt>
mov    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11f9 <get_double+0xb9>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cd <get_double+0x8d>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
cmpl   $0x1,-0x38(%rbp)
jle    1237 <get_double+0xf7>
movsd  0xde1(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    120d <get_double+0xcd>
movsd  -0x48(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_double>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1166 <get_double+0x26>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <atof@plt>
movl   $0x202e2c,0xc(%rsp)
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <strtoken@plt>
mov    0x10(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <atoi@plt>
cmpb   $0x0,(%rbx)
je     11ce <get_double+0x8e>
xor    %ecx,%ecx
cmpb   $0x0,0x1(%rbx,%rcx,1)
lea    0x1(%rcx),%rcx
jne    11a0 <get_double+0x60>
cvtsi2sd %eax,%xmm1
cmp    $0x2,%ecx
jl     11d2 <get_double+0x92>
add    $0x1,%rcx
movsd  0xe40(%rip),%xmm0
mulsd  %xmm0,%xmm1
add    $0xffffffff,%ecx
cmp    $0x2,%ecx
ja     11c0 <get_double+0x80>
jmp    11d2 <get_double+0x92>
cvtsi2sd %eax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.get_double.separator = [4 x i8] c",. \00"
define double @get_double(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8*]
%7 = alloca [4 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
store i8* %0, i8** %2
store double 0.000000e+00, double* %3
%12 = load i8*, i8** %2
%13 = call i32* @strchr(i8* %12, i8 signext 46)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call double @atof(i8* %16)
store double %17, double* %3
br label %61
18: ; preds = %1
store i32 -1, i32* %4
store i32 -1, i32* %5
%19 = bitcast [4 x i8]* %7 to i8*
%20 = load i8*, i8** %2
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%23 = call i32 @strtoken(i8* %20, i8* %21, i8** %22)
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %4
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %5
store i32 0, i32* %8
store i32 0, i32* %9
br label %30
30: ; preds = %39, %18
%31 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %30
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %30
44: ; preds = %30
%45 = load i32, i32* %4
%46 = sitofp i32 %45 to double
store double %46, double* %10
%47 = load i32, i32* %5
%48 = sitofp i32 %47 to double
store double %48, double* %11
br label %49
49: ; preds = %52, %44
%50 = load i32, i32* %8
%51 = icmp sgt i32 %50, 1
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load double, double* %11
%54 = fmul double %53, 1.000000e-01
store double %54, double* %11
%55 = load i32, i32* %8
%56 = add nsw i32 %55, -1
store i32 %56, i32* %8
br label %49
57: ; preds = %49
%58 = load double, double* %10
%59 = load double, double* %11
%60 = fadd double %58, %59
store double %60, double* %3
br label %61
61: ; preds = %57, %15
%62 = load double, double* %3
ret double %62
}

LLVM IR (-O2):
define double @get_double(i8* %0) {
%2 = alloca [2 x i8*]
%3 = alloca i32
%4 = tail call i32* @strchr(i8* %0, i8 signext 46)
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call double @atof(i8* %0)
br label %42
8: ; preds = %1
%9 = bitcast [2 x i8*]* %2 to i8*
%10 = bitcast i32* %3 to i8*
store i32 2108972, i32* %3
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%12 = call i32 @strtoken(i8* %0, i8* %10, i8** %11)
%13 = load i8*, i8** %11
%14 = call i32 @atoi(i8* %13)
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %8
%21 = sitofp i32 %17 to double
br label %38
22: ; preds = %8, %22
%23 = phi i64 [ %24, %22 ], [ 0, %8 ]
%24 = add nuw nsw i64 %23, 1
%25 = getelementptr inbounds i8, i8* %16, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %22
28: ; preds = %22
%29 = trunc i64 %24 to i32
%30 = sitofp i32 %17 to double
%31 = icmp sgt i32 %29, 1
br i1 %31, label %32, label %38
32: ; preds = %28, %32
%33 = phi double [ %35, %32 ], [ %30, %28 ]
%34 = phi i32 [ %36, %32 ], [ %29, %28 ]
%35 = fmul double %33, 1.000000e-01
%36 = add nsw i32 %34, -1
%37 = icmp ugt i32 %34, 2
br i1 %37, label %32, label %38
38: ; preds = %32, %20, %28
%39 = phi double [ %30, %28 ], [ %21, %20 ], [ %35, %32 ]
%40 = sitofp i32 %14 to double
%41 = fadd double %39, %40
br label %42
42: ; preds = %38, %6
%43 = phi double [ %7, %6 ], [ %41, %38 ]
ret double %43
}