#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 */
unsigned int arikkei_dtoa_simple(unsigned char *, unsigned int, double,
                                 unsigned int, int /*<<< orphan*/,
                                 unsigned int);
scalar_t__ arikkei_itoa(unsigned char *, unsigned int, int);
int fabs(double);
double floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(int);
double pow(double, double);
unsigned int arikkei_dtoa_exp(unsigned char *buf, unsigned int len, double val,
                              unsigned int tprec, unsigned int padf) {
  if ((val == 0.0) || ((fabs(val) >= 0.01) && (fabs(val) < 10000000))) {
    return arikkei_dtoa_simple(buf, len, val, tprec, 0, padf);
  } else {
    double eval;
    int p;
    eval = floor(log10(fabs(val)));
    val = val / pow(10.0, eval);
    p = arikkei_dtoa_simple(buf, len, val, tprec, 0, padf);
    buf[p++] = 'e';
    p += arikkei_itoa(buf + p, len - p, (int)eval);
    return p;
  }
}


x86 assembly (clang, -O0):
<arikkei_dtoa_exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    %ecx,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1197 <arikkei_dtoa_exp+0x37>
jp     1197 <arikkei_dtoa_exp+0x37>
jmp    11cc <arikkei_dtoa_exp+0x6c>
movsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe53(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ee <arikkei_dtoa_exp+0x8e>
movsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
cmp    $0x989680,%eax
jge    11ee <arikkei_dtoa_exp+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%r8d
xor    %ecx,%ecx
call   1070 <arikkei_dtoa_simple@plt>
mov    %eax,-0x4(%rbp)
jmp    1299 <arikkei_dtoa_exp+0x139>
movsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%edi
call   1060 <log10@plt>
mov    %eax,%edi
call   1080 <floor@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  0xde6(%rip),%xmm0
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%r8d
xor    %ecx,%ecx
call   1070 <arikkei_dtoa_simple@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
movb   $0x65,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x34(%rbp),%esi
cvttsd2si -0x30(%rbp),%edx
call   1030 <arikkei_itoa@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arikkei_dtoa_exp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%rbp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119d <arikkei_dtoa_exp+0x3d>
jp     119d <arikkei_dtoa_exp+0x3d>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r14d,%r8d
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <arikkei_dtoa_simple@plt>
movsd  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm0
test   %eax,%eax
jle    11c4 <arikkei_dtoa_exp+0x64>
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm0
cmp    $0x98967f,%eax
jle    1181 <arikkei_dtoa_exp+0x21>
call   1040 <fabs@plt>
mov    %eax,%edi
call   1060 <log10@plt>
mov    %eax,%edi
call   1080 <floor@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
movsd  0xe17(%rip),%xmm0
call   1050 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    %rbp,%rdi
mov    %ebx,%esi
movapd %xmm1,%xmm0
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r14d,%r8d
call   1070 <arikkei_dtoa_simple@plt>
movslq %eax,%r14
add    $0x1,%eax
movb   $0x65,0x0(%rbp,%r14,1)
lea    (%r14,%rbp,1),%rdi
add    $0x1,%rdi
sub    %eax,%ebx
cvttsd2si 0x10(%rsp),%edx
mov    %ebx,%esi
call   1030 <arikkei_itoa@plt>
add    %r14d,%eax
add    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @arikkei_dtoa_exp(i8* %0, i32 %1, double %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store double %2, double* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = load double, double* %9
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %25, label %16
16: ; preds = %5
%17 = load double, double* %9
%18 = call i32 @fabs(double %17)
%19 = sitofp i32 %18 to double
%20 = fcmp oge double %19, 1.000000e-02
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = load double, double* %9
%23 = call i32 @fabs(double %22)
%24 = icmp slt i32 %23, 10000000
br i1 %24, label %25, label %32
25: ; preds = %21, %5
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = load double, double* %9
%29 = load i32, i32* %10
%30 = load i32, i32* %11
%31 = call i32 @arikkei_dtoa_simple(i8* %26, i32 %27, double %28, i32 %29, i32 0, i32 %30)
store i32 %31, i32* %6
br label %67
32: ; preds = %21, %16
%33 = load double, double* %9
%34 = call i32 @fabs(double %33)
%35 = call i32 @log10(i32 %34)
%36 = call double @floor(i32 %35)
store double %36, double* %12
%37 = load double, double* %9
%38 = load double, double* %12
%39 = call double @pow(double 1.000000e+01, double %38)
%40 = fdiv double %37, %39
store double %40, double* %9
%41 = load i8*, i8** %7
%42 = load i32, i32* %8
%43 = load double, double* %9
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = call i32 @arikkei_dtoa_simple(i8* %41, i32 %42, double %43, i32 %44, i32 0, i32 %45)
store i32 %46, i32* %13
%47 = load i8*, i8** %7
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
store i8 101, i8* %51
%52 = load i8*, i8** %7
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i32, i32* %8
%57 = load i32, i32* %13
%58 = sub i32 %56, %57
%59 = load double, double* %12
%60 = fptosi double %59 to i32
%61 = call i64 @arikkei_itoa(i8* %55, i32 %58, i32 %60)
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = add nsw i64 %63, %61
%65 = trunc i64 %64 to i32
store i32 %65, i32* %13
%66 = load i32, i32* %13
store i32 %66, i32* %6
br label %67
67: ; preds = %32, %25
%68 = load i32, i32* %6
ret i32 %68
}

LLVM IR (-O2):
define i32 @arikkei_dtoa_exp(i8* %0, i32 %1, double %2, i32 %3, i32 %4) {
%6 = fcmp oeq double %2, 0.000000e+00
br i1 %6, label %13, label %7
7: ; preds = %5
%8 = tail call i32 @fabs(double %2)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = tail call i32 @fabs(double %2)
%12 = icmp slt i32 %11, 10000000
br i1 %12, label %13, label %15
13: ; preds = %10, %5
%14 = tail call i32 @arikkei_dtoa_simple(i8* %0, i32 %1, double %2, i32 %3, i32 0, i32 %4)
br label %32
15: ; preds = %10, %7
%16 = tail call i32 @fabs(double %2)
%17 = tail call i32 @log10(i32 %16)
%18 = tail call double @floor(i32 %17)
%19 = tail call double @pow(double 1.000000e+01, double %18)
%20 = fdiv double %2, %19
%21 = tail call i32 @arikkei_dtoa_simple(i8* %0, i32 %1, double %20, i32 %3, i32 0, i32 %4)
%22 = add nsw i32 %21, 1
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 101, i8* %24
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = sub i32 %1, %22
%28 = fptosi double %18 to i32
%29 = tail call i64 @arikkei_itoa(i8* %26, i32 %27, i32 %28)
%30 = trunc i64 %29 to i32
%31 = add i32 %22, %30
br label %32
32: ; preds = %15, %13
%33 = phi i32 [ %14, %13 ], [ %31, %15 ]
ret i32 %33
}