#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 double int64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
scalar_t__ errno;
int /*<<< orphan*/ isalpha(char const);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
scalar_t__ strncasecmp(char const *, char *, int);
double strtod(char const *, char **);
int a2double(const char *str, double *pval) {
  int64_t mult = 1;
  const char *p = NULL;
  double dval = 0.0;
  size_t numsz = 0;
  static const int ERR_OVERRUN = -3;
  static const int ERR_NUMFMT = -4;
  static const int ERR_BADMULT = -5;
  char buf[64] = {0};
  assert(str);
  for (p = str; *p && !isalpha(*p); ++p)
    ;
  if ('\0' != *p) {
    if (0 == strncasecmp(p, "Kb", 64) || 0 == strncasecmp(p, "K", 64))
      mult = 1024;
    else if (0 == strncasecmp(p, "Mb", 64) || 0 == strncasecmp(p, "M", 64))
      mult = (1024 * 1024);
    else if (0 == strncasecmp(p, "Gb", 64) || 0 == strncasecmp(p, "G", 64))
      mult = (1024 * 1024 * 1024);
    else
      return ERR_BADMULT;
    numsz = p - str;
    if (numsz >= (size_t)64)
      return ERR_OVERRUN;
    (void)memcpy(buf, str, numsz);
    errno = 0;
    dval = strtod(buf, (char **)NULL);
    if (errno)
      return ERR_NUMFMT;
    dval *= mult;
  } else {
    errno = 0;
    dval = strtod(str, (char **)NULL);
    if (errno)
      return ERR_NUMFMT;
  }
  if (NULL != pval)
    *pval = dval;
  return 0;
}


x86 assembly (clang, -O0):
<a2double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x81(%rbp)
je     11eb <a2double+0x8b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    11fe <a2double+0x9e>
jmp    1214 <a2double+0xb4>
jmp    1203 <a2double+0xa3>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b9 <a2double+0x59>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     13cb <a2double+0x26b>
mov    -0x28(%rbp),%rdi
lea    0xdfc(%rip),%rsi
mov    $0x40,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     126b <a2double+0x10b>
mov    -0x28(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x40,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    127d <a2double+0x11d>
movsd  0xda5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1343 <a2double+0x1e3>
mov    -0x28(%rbp),%rdi
lea    0xda9(%rip),%rsi
mov    $0x40,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12c3 <a2double+0x163>
mov    -0x28(%rbp),%rdi
lea    0xd89(%rip),%rsi
mov    $0x40,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12d5 <a2double+0x175>
movsd  0xd45(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    133e <a2double+0x1de>
mov    -0x28(%rbp),%rdi
lea    0xd56(%rip),%rsi
mov    $0x40,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     131b <a2double+0x1bb>
mov    -0x28(%rbp),%rdi
lea    0xd36(%rip),%rsi
mov    $0x40,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    132d <a2double+0x1cd>
movsd  0xce5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1339 <a2double+0x1d9>
movl   $0xfffffffb,-0x4(%rbp)
jmp    142d <a2double+0x2cd>
jmp    133e <a2double+0x1de>
jmp    1343 <a2double+0x1e3>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x40,-0x38(%rbp)
jb     1369 <a2double+0x209>
movl   $0xfffffffd,-0x4(%rbp)
jmp    142d <a2double+0x2cd>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <memcpy@plt>
mov    0x2c5f(%rip),%rax
movq   $0x0,(%rax)
lea    -0x80(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2c3f(%rip),%rax
cmpq   $0x0,(%rax)
je     13b7 <a2double+0x257>
movl   $0xfffffffc,-0x4(%rbp)
jmp    142d <a2double+0x2cd>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    140d <a2double+0x2ad>
mov    0x2c0e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2bee(%rip),%rax
cmpq   $0x0,(%rax)
je     1408 <a2double+0x2a8>
movl   $0xfffffffc,-0x4(%rbp)
jmp    142d <a2double+0x2cd>
jmp    140d <a2double+0x2ad>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1426 <a2double+0x2c6>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2double>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
call   1040 <assert@plt>
mov    (%r15),%al
test   %al,%al
je     12eb <a2double+0x19b>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1070 <isalpha@plt>
test   %eax,%eax
jne    11af <a2double+0x5f>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1190 <a2double+0x40>
jmp    12eb <a2double+0x19b>
cmpb   $0x0,(%r15,%rbx,1)
je     12eb <a2double+0x19b>
lea    (%r15,%rbx,1),%r12
lea    0xe53(%rip),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1060 <strncasecmp@plt>
movsd  0xe26(%rip),%xmm0
test   %rax,%rax
je     1298 <a2double+0x148>
lea    0xe31(%rip),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1060 <strncasecmp@plt>
movsd  0xe01(%rip),%xmm0
test   %rax,%rax
je     1298 <a2double+0x148>
lea    0xe0e(%rip),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1060 <strncasecmp@plt>
movsd  0xde4(%rip),%xmm0
test   %rax,%rax
je     1298 <a2double+0x148>
lea    0xdf0(%rip),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1060 <strncasecmp@plt>
movsd  0xdc3(%rip),%xmm0
test   %rax,%rax
je     1298 <a2double+0x148>
lea    0xdd1(%rip),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1060 <strncasecmp@plt>
movsd  0xdaa(%rip),%xmm0
test   %rax,%rax
je     1298 <a2double+0x148>
lea    0xdb3(%rip),%rsi
mov    %r12,%rdi
mov    $0x40,%edx
call   1060 <strncasecmp@plt>
movsd  0xd89(%rip),%xmm0
mov    %rax,%rcx
mov    $0xfffffffb,%eax
test   %rcx,%rcx
jne    131d <a2double+0x1cd>
mov    $0xfffffffd,%eax
cmp    $0x3f,%rbx
ja     131d <a2double+0x1cd>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
call   1050 <memcpy@plt>
mov    0x2d1d(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  0x8(%rsp),%xmm1
mov    $0xfffffffc,%eax
cmpq   $0x0,(%rbx)
jne    131d <a2double+0x1cd>
mulsd  %xmm0,%xmm1
jmp    1311 <a2double+0x1c1>
mov    0x2cee(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
mov    $0xfffffffc,%eax
cmpq   $0x0,(%rbx)
jne    131d <a2double+0x1cd>
movaps %xmm0,%xmm1
xor    %eax,%eax
test   %r14,%r14
je     131d <a2double+0x1cd>
movsd  %xmm1,(%r14)
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@a2double.ERR_OVERRUN = internal constant i32 -3
@a2double.ERR_NUMFMT = internal constant i32 -4
@a2double.ERR_BADMULT = internal constant i32 -5
@.str = [3 x i8] c"Kb\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [3 x i8] c"Mb\00"
@.str.3 = [2 x i8] c"M\00"
@.str.4 = [3 x i8] c"Gb\00"
@.str.5 = [2 x i8] c"G\00"
@errno = global i64 0
define i32 @a2double(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca double
%7 = alloca i8*
%8 = alloca double
%9 = alloca i64
%10 = alloca [64 x i8]
store i8* %0, i8** %4
store double* %1, double** %5
store double 1.000000e+00, double* %6
store i8* null, i8** %7
store double 0.000000e+00, double* %8
store i64 0, i64* %9
%11 = bitcast [64 x i8]* %10 to i8*
%12 = load i8*, i8** %4
%13 = call i32 @assert(i8* %12)
%14 = load i8*, i8** %4
store i8* %14, i8** %7
br label %15
15: ; preds = %29, %2
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = call i32 @isalpha(i8 signext %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br label %26
26: ; preds = %20, %15
%27 = phi i1 [ false, %15 ], [ %25, %20 ]
br i1 %27, label %28, label %32
28: ; preds = %26
br label %29
29: ; preds = %28
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %7
br label %15
32: ; preds = %26
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 0, %35
br i1 %36, label %37, label %90
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = call i64 @strncasecmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 64)
%40 = icmp eq i64 0, %39
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i8*, i8** %7
%43 = call i64 @strncasecmp(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 64)
%44 = icmp eq i64 0, %43
br i1 %44, label %45, label %46
45: ; preds = %41, %37
store double 1.024000e+03, double* %6
br label %67
46: ; preds = %41
%47 = load i8*, i8** %7
%48 = call i64 @strncasecmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 64)
%49 = icmp eq i64 0, %48
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = load i8*, i8** %7
%52 = call i64 @strncasecmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 64)
%53 = icmp eq i64 0, %52
br i1 %53, label %54, label %55
54: ; preds = %50, %46
store double 0x4130000000000000, double* %6
br label %66
55: ; preds = %50
%56 = load i8*, i8** %7
%57 = call i64 @strncasecmp(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 64)
%58 = icmp eq i64 0, %57
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i8*, i8** %7
%61 = call i64 @strncasecmp(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 64)
%62 = icmp eq i64 0, %61
br i1 %62, label %63, label %64
63: ; preds = %59, %55
store double 0x41D0000000000000, double* %6
br label %65
64: ; preds = %59
store i32 -5, i32* %3
br label %104
65: ; preds = %63
br label %66
66: ; preds = %65, %54
br label %67
67: ; preds = %66, %45
%68 = load i8*, i8** %7
%69 = load i8*, i8** %4
%70 = ptrtoint i8* %68 to i64
%71 = ptrtoint i8* %69 to i64
%72 = sub i64 %70, %71
store i64 %72, i64* %9
%73 = load i64, i64* %9
%74 = icmp uge i64 %73, 64
br i1 %74, label %75, label %76
75: ; preds = %67
store i32 -3, i32* %3
br label %104
76: ; preds = %67
%77 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%78 = load i8*, i8** %4
%79 = load i64, i64* %9
%80 = call i32 @memcpy(i8* %77, i8* %78, i64 %79)
store i64 0, i64* @errno
%81 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%82 = call double @strtod(i8* %81, i8** null)
store double %82, double* %8
%83 = load i64, i64* @errno
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %76
store i32 -4, i32* %3
br label %104
86: ; preds = %76
%87 = load double, double* %6
%88 = load double, double* %8
%89 = fmul double %88, %87
store double %89, double* %8
br label %97
90: ; preds = %32
store i64 0, i64* @errno
%91 = load i8*, i8** %4
%92 = call double @strtod(i8* %91, i8** null)
store double %92, double* %8
%93 = load i64, i64* @errno
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %96
95: ; preds = %90
store i32 -4, i32* %3
br label %104
96: ; preds = %90
br label %97
97: ; preds = %96, %86
%98 = load double*, double** %5
%99 = icmp ne double* null, %98
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = load double, double* %8
%102 = load double*, double** %5
store double %101, double* %102
br label %103
103: ; preds = %100, %97
store i32 0, i32* %3
br label %104
104: ; preds = %103, %95, %85, %75, %64
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
@.str = [3 x i8] c"Kb\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [3 x i8] c"Mb\00"
@.str.3 = [2 x i8] c"M\00"
@.str.4 = [3 x i8] c"Gb\00"
@.str.5 = [2 x i8] c"G\00"
@errno = global i64 0
define i32 @a2double(i8* %0, double* writeonly %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @assert(i8* %0)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %51, label %8
8: ; preds = %2, %13
%9 = phi i8 [ %15, %13 ], [ %6, %2 ]
%10 = phi i8* [ %14, %13 ], [ %0, %2 ]
%11 = tail call i32 @isalpha(i8 signext %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %51, label %8
17: ; preds = %8
%18 = load i8, i8* %10
%19 = icmp eq i8 %18, 0
br i1 %19, label %51, label %20
20: ; preds = %17
%21 = tail call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 64)
%22 = icmp eq i64 %21, 0
br i1 %22, label %38, label %23
23: ; preds = %20
%24 = tail call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 64)
%25 = icmp eq i64 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %23
%27 = tail call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 64)
%28 = icmp eq i64 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %26
%30 = tail call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 64)
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = tail call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 64)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = tail call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 64)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %59
38: ; preds = %32, %35, %26, %29, %20, %23
%39 = phi double [ 1.024000e+03, %23 ], [ 1.024000e+03, %20 ], [ 0x4130000000000000, %29 ], [ 0x4130000000000000, %26 ], [ 0x41D0000000000000, %35 ], [ 0x41D0000000000000, %32 ]
%40 = ptrtoint i8* %10 to i64
%41 = ptrtoint i8* %0 to i64
%42 = sub i64 %40, %41
%43 = icmp ugt i64 %42, 63
br i1 %43, label %59, label %44
44: ; preds = %38
%45 = call i32 @memcpy(i8* %4, i8* %0, i64 %42)
store i64 0, i64* @errno
%46 = call double @strtod(i8* nocapture %4, i8** null)
%47 = load i64, i64* @errno
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %59
49: ; preds = %44
%50 = fmul double %39, %46
br label %55
51: ; preds = %13, %2, %17
store i64 0, i64* @errno
%52 = tail call double @strtod(i8* nocapture %0, i8** null)
%53 = load i64, i64* @errno
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51, %49
%56 = phi double [ %50, %49 ], [ %52, %51 ]
%57 = icmp eq double* %1, null
br i1 %57, label %59, label %58
58: ; preds = %55
store double %56, double* %1
br label %59
59: ; preds = %55, %58, %51, %44, %38, %35
%60 = phi i32 [ -5, %35 ], [ -3, %38 ], [ -4, %44 ], [ -4, %51 ], [ 0, %58 ], [ 0, %55 ]
ret i32 %60
}