#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 pow(double, unsigned int);
unsigned int strcspn(char const *, char const *);
double _atof(const char *s) {
  const char *p = s;
  const char *cset = ".";
  double ret = 0;
  unsigned int length = 0;
  double tmp = 0;
  int pos = 1;
  if (*s == '-')
    pos = -1;
  for (length = strcspn(s, cset); *p != '.'; p++, length--) {
    if (*p >= '0' && *p <= '9') {
      tmp = (double)((int)(*p) - 48);
      ret += tmp * pow(10.0, length - 1);
    }
  }
  for (unsigned int i = 0; *p != '\0'; p++, i++) {
    if (*p >= '0' && *p <= '9') {
      tmp = (double)((int)(*p) - 48);
      ret += tmp * pow(0.1, i);
    }
  }
  return ret * pos;
}


x86 assembly (clang, -O0):
<_atof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xed5(%rip),%rax
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1174 <_atof+0x54>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     121d <_atof+0xfd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11fe <_atof+0xde>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     11fe <_atof+0xde>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%edi
sub    $0x1,%edi
movsd  0xe29(%rip),%xmm0
call   1040 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1203 <_atof+0xe3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <_atof+0x64>
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12ba <_atof+0x19a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     129b <_atof+0x17b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     129b <_atof+0x17b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%edi
movsd  0xd84(%rip),%xmm0
call   1040 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12a0 <_atof+0x180>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1224 <_atof+0x104>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
mulsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_atof>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    (%rdi),%r14b
xorps  %xmm0,%xmm0
cmp    $0x2e,%r14b
jne    11ab <_atof+0x8b>
mov    $0x2e,%al
xor    %ebp,%ebp
jmp    114d <_atof+0x2d>
nopl   (%rax)
movzbl 0x1(%rbx,%rbp,1),%eax
add    $0x1,%rbp
test   %al,%al
je     1195 <_atof+0x75>
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     1140 <_atof+0x20>
movzbl %al,%eax
add    $0xffffffd0,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x18(%rsp)
movaps %xmm0,(%rsp)
movsd  0xe94(%rip),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
mulsd  0x18(%rsp),%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movaps (%rsp),%xmm0
jmp    1140 <_atof+0x20>
cmp    $0x2d,%r14b
jne    11a2 <_atof+0x82>
xorps  0xe6e(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcspn@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
mov    %r14d,%eax
jmp    1221 <_atof+0x101>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %al,%eax
add    $0xffffffd0,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x18(%rsp)
add    $0xffffffff,%ebp
movaps %xmm0,(%rsp)
movsd  0xe0e(%rip),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
mulsd  0x18(%rsp),%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movaps (%rsp),%xmm0
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x2e,%al
je     1137 <_atof+0x17>
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
jb     11d0 <_atof+0xb0>
add    $0xffffffff,%ebp
jmp    1211 <_atof+0xf1>

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

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