#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 */
typedef int /*<<< orphan*/ tmp;

/* Variables and functions */
int /*<<< orphan*/ parseutils_buf2str(char *, char const *, size_t);
int /*<<< orphan*/ strcat(char *, char *);
double strtod(char *, int /*<<< orphan*/ *);
int parseutils_buf2doubleDPA(double *out, const char *buf, size_t len) {
  char tmp[30], newT[50] = {0};
  int i, j;
  if (len >= sizeof(tmp))
    return -1;
  parseutils_buf2str(tmp, buf, len);
  i = j = 0;
  while (tmp[i] == ' ')
    ++i;
  if (tmp[i] == '-') {
    strcat(newT, "-0.");
    j = 3;
    ++i;
  } else {
    strcat(newT, "0.");
    j = 2;
  }
  while (tmp[i] >= '0' && tmp[i] <= '9') {
    newT[j++] = tmp[i++];
    newT[j] = '\0';
  }
  if (tmp[i] == '-' || tmp[i] == '+') {
    strcat(newT, "e");
    strcat(newT, tmp + i);
  }
  *out = strtod(newT, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<parseutils_buf2doubleDPA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1050 <memset@plt>
cmpq   $0x1e,-0x20(%rbp)
jb     117e <parseutils_buf2doubleDPA+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1322 <parseutils_buf2doubleDPA+0x1e2>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <parseutils_buf2str@plt>
movl   $0x0,-0x88(%rbp)
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    11cc <parseutils_buf2doubleDPA+0x8c>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11a3 <parseutils_buf2doubleDPA+0x63>
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x2d,%eax
jne    120f <parseutils_buf2doubleDPA+0xcf>
lea    -0x80(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcat@plt>
movl   $0x3,-0x88(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1229 <parseutils_buf2doubleDPA+0xe9>
lea    -0x80(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1060 <strcat@plt>
movl   $0x2,-0x88(%rbp)
jmp    122e <parseutils_buf2doubleDPA+0xee>
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x89(%rbp)
jl     1263 <parseutils_buf2doubleDPA+0x123>
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    1276 <parseutils_buf2doubleDPA+0x136>
jmp    12b5 <parseutils_buf2doubleDPA+0x175>
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
cltq
mov    -0x40(%rbp,%rax,1),%cl
mov    -0x88(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x88(%rbp)
cltq
mov    %cl,-0x80(%rbp,%rax,1)
movslq -0x88(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
jmp    122e <parseutils_buf2doubleDPA+0xee>
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x2d,%eax
je     12df <parseutils_buf2doubleDPA+0x19f>
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x2b,%eax
jne    1306 <parseutils_buf2doubleDPA+0x1c6>
lea    -0x80(%rbp),%rdi
lea    0xd1a(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
movslq -0x84(%rbp),%rax
add    %rax,%rsi
call   1060 <strcat@plt>
lea    -0x80(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseutils_buf2doubleDPA>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
mov    $0xffffffff,%ebx
cmp    $0x1d,%rdx
ja     122c <parseutils_buf2doubleDPA+0xfc>
mov    %rdi,%r14
lea    0x40(%rsp),%rdi
call   1030 <parseutils_buf2str@plt>
xor    %ebx,%ebx
nop
movzbl 0x40(%rsp,%rbx,1),%eax
cmp    $0x20,%al
jne    117f <parseutils_buf2doubleDPA+0x4f>
add    $0x1,%rbx
jmp    1170 <parseutils_buf2doubleDPA+0x40>
cmp    $0x2d,%al
jne    119d <parseutils_buf2doubleDPA+0x6d>
lea    0xe76(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcat@plt>
add    $0x1,%rbx
mov    $0x3,%edx
jmp    11b1 <parseutils_buf2doubleDPA+0x81>
lea    0xe5d(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcat@plt>
mov    $0x2,%edx
movslq %ebx,%rax
mov    0x40(%rsp,%rax,1),%cl
lea    -0x30(%rcx),%esi
cmp    $0x9,%sil
ja     11ec <parseutils_buf2doubleDPA+0xbc>
mov    %rsp,%rsi
add    %rsi,%rdx
add    $0x1,%rdx
nopl   0x0(%rax,%rax,1)
mov    %cl,-0x1(%rdx)
movb   $0x0,(%rdx)
movzbl 0x41(%rsp,%rax,1),%ecx
add    $0x1,%rax
lea    -0x30(%rcx),%esi
add    $0x1,%rdx
cmp    $0xa,%sil
jb     11d0 <parseutils_buf2doubleDPA+0xa0>
cmp    $0x2d,%cl
je     11f6 <parseutils_buf2doubleDPA+0xc6>
cmp    $0x2b,%cl
jne    121b <parseutils_buf2doubleDPA+0xeb>
lea    (%rsp,%rax,1),%rbx
add    $0x40,%rbx
lea    0xdff(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <strtod@plt>
movsd  %xmm0,(%r14)
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"-0.\00"
@.str.1 = [3 x i8] c"0.\00"
@.str.2 = [2 x i8] c"e\00"
define i32 @parseutils_buf2doubleDPA(double* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [30 x i8]
%9 = alloca [50 x i8]
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = bitcast [50 x i8]* %9 to i8*
%13 = load i64, i64* %7
%14 = icmp uge i64 %13, 30
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %103
16: ; preds = %3
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %6
%19 = load i64, i64* %7
%20 = call i32 @parseutils_buf2str(i8* %17, i8* %18, i64 %19)
store i32 0, i32* %11
store i32 0, i32* %10
br label %21
21: ; preds = %28, %16
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 1
store i32 %30, i32* %10
br label %21
31: ; preds = %21
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 45
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 3, i32* %11
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %46
43: ; preds = %31
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %11
br label %46
46: ; preds = %43, %38
br label %47
47: ; preds = %63, %46
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp sge i32 %52, 48
br i1 %53, label %54, label %61
54: ; preds = %47
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp sle i32 %59, 57
br label %61
61: ; preds = %54, %47
%62 = phi i1 [ false, %47 ], [ %60, %54 ]
br i1 %62, label %63, label %76
63: ; preds = %61
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
%71 = sext i32 %69 to i64
%72 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 %71
store i8 %68, i8* %72
%73 = load i32, i32* %11
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 %74
store i8 0, i8* %75
br label %47
76: ; preds = %61
%77 = load i32, i32* %10
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %78
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 45
br i1 %82, label %90, label %83
83: ; preds = %76
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 43
br i1 %89, label %90, label %99
90: ; preds = %83, %76
%91 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%92 = call i32 @strcat(i8* %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%93 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%94 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = call i32 @strcat(i8* %93, i8* %97)
br label %99
99: ; preds = %90, %83
%100 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%101 = call double @strtod(i8* %100, i32* null)
%102 = load double*, double** %5
store double %101, double* %102
store i32 0, i32* %4
br label %103
103: ; preds = %99, %15
%104 = load i32, i32* %4
ret i32 %104
}

LLVM IR (-O2):
@.str = [4 x i8] c"-0.\00"
@.str.1 = [3 x i8] c"0.\00"
@.str.2 = [2 x i8] c"e\00"
define i32 @parseutils_buf2doubleDPA(double* nocapture writeonly %0, i8* %1, i64 %2) {
%4 = alloca [30 x i8]
%5 = alloca [50 x i8]
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%8 = icmp ugt i64 %2, 29
br i1 %8, label %52, label %9
9: ; preds = %3
%10 = call i32 @parseutils_buf2str(i8* %6, i8* %1, i64 %2)
br label %11
11: ; preds = %15, %9
%12 = phi i64 [ %16, %15 ], [ 0, %9 ]
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %20 [
i8 32, label %15
i8 45, label %17
]
15: ; preds = %11
%16 = add nuw i64 %12, 1
br label %11
17: ; preds = %11
%18 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = add i64 %12, 1
br label %22
20: ; preds = %11
%21 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = phi i64 [ %19, %17 ], [ %12, %20 ]
%24 = phi i64 [ 3, %17 ], [ 2, %20 ]
%25 = shl i64 %23, 32
%26 = ashr exact i64 %25, 32
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = add i8 %28, -48
%30 = icmp ult i8 %29, 10
br i1 %30, label %31, label %43
31: ; preds = %22, %31
%32 = phi i64 [ %35, %31 ], [ %26, %22 ]
%33 = phi i64 [ %36, %31 ], [ %24, %22 ]
%34 = phi i8 [ %40, %31 ], [ %28, %22 ]
%35 = add i64 %32, 1
%36 = add nuw nsw i64 %33, 1
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %33
store i8 %34, i8* %37
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %36
store i8 0, i8* %38
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %35
%40 = load i8, i8* %39
%41 = add i8 %40, -48
%42 = icmp ult i8 %41, 10
br i1 %42, label %31, label %43
43: ; preds = %31, %22
%44 = phi i64 [ %26, %22 ], [ %35, %31 ]
%45 = phi i8 [ %28, %22 ], [ %40, %31 ]
switch i8 %45, label %50 [
i8 45, label %46
i8 43, label %46
]
46: ; preds = %43, %43
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %44
%48 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @strcat(i8* %7, i8* %47)
br label %50
50: ; preds = %43, %46
%51 = call double @strtod(i8* nocapture %7, i32* null)
store double %51, double* %0
br label %52
52: ; preds = %3, %50
%53 = phi i32 [ 0, %50 ], [ -1, %3 ]
ret i32 %53
}