#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 */
char *GetSubString(char const *, unsigned int, unsigned int);
double _Power(double, int /*<<< orphan*/);
double atof(char const *);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ free(char *);
unsigned int strlen(char const *);
double FormatNumber(const char *numstr) {
  unsigned int i = 0;
  unsigned int s_len = strlen(numstr);
  unsigned int num_len_counter = 0;
  char *num_part = (0);
  char *e_part = (0);
  int has_e = 0;
  double rtn = 0;
  for (i = 0; i < s_len; ++i) {
    if (numstr[i] == 'e' || numstr[i] == 'E') {
      has_e = 1;
      num_len_counter = i;
      break;
    }
  }
  if (has_e) {
    num_part = GetSubString(numstr, 0, num_len_counter);
    e_part =
        GetSubString(numstr, num_len_counter + 1, s_len - num_len_counter - 1);
    rtn = atof(num_part) * _Power(10.0, atoi(e_part));
    free(num_part);
    free(e_part);
  } else {
    rtn = atof(numstr);
  }
  return rtn;
}


x86 assembly (clang, -O0):
<FormatNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1205 <FormatNumber+0xa5>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x65,%eax
je     11e0 <FormatNumber+0x80>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x45,%eax
jne    11f2 <FormatNumber+0x92>
movl   $0x1,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1205 <FormatNumber+0xa5>
jmp    11f7 <FormatNumber+0x97>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <FormatNumber+0x4c>
cmpl   $0x0,-0x2c(%rbp)
je     128b <FormatNumber+0x12b>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1070 <GetSubString@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1070 <GetSubString@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
movsd  0xda2(%rip),%xmm0
call   1060 <_Power@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1299 <FormatNumber+0x139>
mov    -0x8(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatNumber>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
test   %eax,%eax
je     1195 <FormatNumber+0x35>
mov    %eax,%r14d
mov    %eax,%eax
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%ecx
or     $0x20,%cl
cmp    $0x65,%cl
je     11a7 <FormatNumber+0x47>
add    $0x1,%rbp
cmp    %rbp,%rax
jne    1180 <FormatNumber+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <atof@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <GetSubString@plt>
mov    %rax,%r15
lea    0x1(%rbp),%esi
not    %ebp
add    %r14d,%ebp
mov    %rbx,%rdi
mov    %ebp,%edx
call   1070 <GetSubString@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1080 <atoi@plt>
movsd  0xe18(%rip),%xmm0
mov    %eax,%edi
call   1060 <_Power@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @FormatNumber(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca double
store i8* %0, i8** %2
store i32 0, i32* %3
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
store i32 0, i32* %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %8
store double 0.000000e+00, double* %9
store i32 0, i32* %3
br label %12
12: ; preds = %35, %1
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %38
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 101
br i1 %23, label %32, label %24
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = load i32, i32* %3
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 69
br i1 %31, label %32, label %34
32: ; preds = %24, %16
store i32 1, i32* %8
%33 = load i32, i32* %3
store i32 %33, i32* %5
br label %38
34: ; preds = %24
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
%37 = add i32 %36, 1
store i32 %37, i32* %3
br label %12
38: ; preds = %32, %12
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %63
41: ; preds = %38
%42 = load i8*, i8** %2
%43 = load i32, i32* %5
%44 = call i8* @GetSubString(i8* %42, i32 0, i32 %43)
store i8* %44, i8** %6
%45 = load i8*, i8** %2
%46 = load i32, i32* %5
%47 = add i32 %46, 1
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = sub i32 %48, %49
%51 = sub i32 %50, 1
%52 = call i8* @GetSubString(i8* %45, i32 %47, i32 %51)
store i8* %52, i8** %7
%53 = load i8*, i8** %6
%54 = call double @atof(i8* %53)
%55 = load i8*, i8** %7
%56 = call i32 @atoi(i8* %55)
%57 = call double @_Power(double 1.000000e+01, i32 %56)
%58 = fmul double %54, %57
store double %58, double* %9
%59 = load i8*, i8** %6
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %7
%62 = call i32 @free(i8* %61)
br label %66
63: ; preds = %38
%64 = load i8*, i8** %2
%65 = call double @atof(i8* %64)
store double %65, double* %9
br label %66
66: ; preds = %63, %41
%67 = load double, double* %9
ret double %67
}

LLVM IR (-O2):
define double @FormatNumber(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %10
%7 = phi i64 [ 0, %4 ], [ %11, %10 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 101, label %13
i8 69, label %13
]
10: ; preds = %6
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, %5
br i1 %12, label %26, label %6
13: ; preds = %6, %6
%14 = trunc i64 %7 to i32
%15 = tail call i8* @GetSubString(i8* %0, i32 0, i32 %14)
%16 = add nuw i32 %14, 1
%17 = xor i32 %14, -1
%18 = add i32 %2, %17
%19 = tail call i8* @GetSubString(i8* %0, i32 %16, i32 %18)
%20 = tail call double @atof(i8* %15)
%21 = tail call i32 @atoi(i8* %19)
%22 = tail call double @_Power(double 1.000000e+01, i32 %21)
%23 = fmul double %20, %22
%24 = tail call i32 @free(i8* %15)
%25 = tail call i32 @free(i8* %19)
br label %28
26: ; preds = %10, %1
%27 = tail call double @atof(i8* %0)
br label %28
28: ; preds = %26, %13
%29 = phi double [ %23, %13 ], [ %27, %26 ]
ret double %29
}