#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 /*<<< orphan*/ free(char *);
char *malloc(int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
double strtod(char *, char **);
int ED_strtod(char *token, char *dec, double *val) {
  int ret = 0;
  char *endptr;
  if (*dec == '.') {
    *val = strtod(token, &endptr);
  } else if (NULL == strchr(token, '.')) {
    *val = strtod(token, &endptr);
  } else {
    char *token2 = malloc((strlen(token) + 1) * sizeof(char));
    if (token2 != NULL) {
      char *p;
      strcpy(token2, token);
      p = strchr(token2, '.');
      *p = *dec;
      *val = strtod(token2, &endptr);
      if (*endptr != 0) {
        *val = 0.;
        ret = 1;
      }
      free(token2);
    } else {
      ret = 2;
    }
  }
}


x86 assembly (clang, -O0):
<ED_strtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11a5 <ED_strtod+0x45>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1284 <ED_strtod+0x124>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1070 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11db <ED_strtod+0x7b>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    127f <ED_strtod+0x11f>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1273 <ED_strtod+0x113>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    $0x2e,%esi
call   1070 <strchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1265 <ED_strtod+0x105>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    127a <ED_strtod+0x11a>
movl   $0x2,-0x24(%rbp)
jmp    127f <ED_strtod+0x11f>
jmp    1284 <ED_strtod+0x124>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ED_strtod>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
cmpb   $0x2e,(%rsi)
je     11e8 <ED_strtod+0x88>
mov    %rsi,%r15
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     11e8 <ED_strtod+0x88>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f8 <ED_strtod+0x98>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
mov    $0x2e,%esi
call   1070 <strchr@plt>
mov    (%r15),%cl
mov    %cl,(%rax)
mov    %rsp,%rsi
mov    %r12,%rdi
call   1050 <strtod@plt>
movsd  %xmm0,(%r14)
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11d9 <ED_strtod+0x79>
xorps  %xmm0,%xmm0
movsd  %xmm0,(%r14)
mov    %r12,%rdi
call   1030 <free@plt>
jmp    11f8 <ED_strtod+0x98>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <strtod@plt>
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ED_strtod(i8* %0, i8* %1, double* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store double* %2, double** %7
store i32 0, i32* %8
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 46
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call double @strtod(i8* %17, i8** %9)
%19 = load double*, double** %7
store double %18, double* %19
br label %62
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = call i8* @strchr(i8* %21, i8 signext 46)
%23 = icmp eq i8* null, %22
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = call double @strtod(i8* %25, i8** %9)
%27 = load double*, double** %7
store double %26, double* %27
br label %61
28: ; preds = %20
%29 = load i8*, i8** %5
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 1
%34 = trunc i64 %33 to i32
%35 = call i8* @malloc(i32 %34)
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %59
38: ; preds = %28
%39 = load i8*, i8** %10
%40 = load i8*, i8** %5
%41 = call i32 @strcpy(i8* %39, i8* %40)
%42 = load i8*, i8** %10
%43 = call i8* @strchr(i8* %42, i8 signext 46)
store i8* %43, i8** %11
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = load i8*, i8** %11
store i8 %45, i8* %46
%47 = load i8*, i8** %10
%48 = call double @strtod(i8* %47, i8** %9)
%49 = load double*, double** %7
store double %48, double* %49
%50 = load i8*, i8** %9
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %38
%55 = load double*, double** %7
store double 0.000000e+00, double* %55
store i32 1, i32* %8
br label %56
56: ; preds = %54, %38
%57 = load i8*, i8** %10
%58 = call i32 @free(i8* %57)
br label %60
59: ; preds = %28
store i32 2, i32* %8
br label %60
60: ; preds = %59, %56
br label %61
61: ; preds = %60, %24
br label %62
62: ; preds = %61, %16
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
define i32 @ED_strtod(i8* %0, i8* nocapture %1, double* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 46
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call double @strtod(i8* %0, i8** %4)
store double %9, double* %2
br label %30
10: ; preds = %3
%11 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call double @strtod(i8* %0, i8** %4)
store double %14, double* %2
br label %30
15: ; preds = %10
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, 1
%18 = tail call i8* @malloc(i32 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = tail call i32 @strcpy(i8* %18, i8* %0)
%22 = tail call i8* @strchr(i8* %18, i8 signext 46)
%23 = load i8, i8* %1
store i8 %23, i8* %22
%24 = call double @strtod(i8* %18, i8** %4)
store double %24, double* %2
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
%28 = select i1 %27, double %24, double 0.000000e+00
store double %28, double* %2
%29 = tail call i32 @free(i8* %18)
br label %30
30: ; preds = %20, %15, %13, %8
ret i32 undef
}