#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*/ ss;

/* Variables and functions */
int sscanf(char *, char *, double *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ suicidef(char *, char const *);
double string_to_unitized_double(const char *s, int byThousands) {
  char ss[20];
  int len = strlen(s);
  char *parseMe;
  double v;
  char extra;
  int mult;
  mult = 1;
  if (len >= (int)sizeof(ss))
    parseMe = (char *)s;
  else {
    parseMe = ss;
    strcpy(ss, s);
    if (len > 0) {
      switch (ss[len - 1]) {
      case 'K':
      case 'k':
        mult = (byThousands) ? 1000 : 1024;
        break;
      case 'M':
      case 'm':
        mult = (byThousands) ? 1000000 : 1024L * 1024L;
        break;
      case 'G':
      case 'g':
        mult = (byThousands) ? 1000000000 : 1024L * 1024L * 1024L;
        break;
      }
      if (mult != 1)
        ss[len - 1] = 0;
    }
  }
  if (sscanf(parseMe, "%lf%c", &v, &extra) != 1)
    suicidef("\"%s\" is not a number", s);
  return v * mult;
}


x86 assembly (clang, -O0):
<string_to_unitized_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x40(%rbp)
cmpl   $0x14,-0x24(%rbp)
jl     1179 <string_to_unitized_double+0x39>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    127a <string_to_unitized_double+0x13a>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x24(%rbp)
jle    1275 <string_to_unitized_double+0x135>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
cltq
movsbl -0x20(%rbp,%rax,1),%eax
mov    %eax,-0x44(%rbp)
sub    $0x47,%eax
je     1242 <string_to_unitized_double+0x102>
jmp    11b6 <string_to_unitized_double+0x76>
mov    -0x44(%rbp),%eax
sub    $0x4b,%eax
je     120b <string_to_unitized_double+0xcb>
jmp    11c7 <string_to_unitized_double+0x87>
mov    -0x44(%rbp),%eax
sub    $0x4d,%eax
je     1226 <string_to_unitized_double+0xe6>
jmp    11d8 <string_to_unitized_double+0x98>
mov    -0x44(%rbp),%eax
sub    $0x67,%eax
je     1242 <string_to_unitized_double+0x102>
jmp    11e9 <string_to_unitized_double+0xa9>
mov    -0x44(%rbp),%eax
sub    $0x6b,%eax
je     120b <string_to_unitized_double+0xcb>
jmp    11fa <string_to_unitized_double+0xba>
mov    -0x44(%rbp),%eax
sub    $0x6d,%eax
je     1226 <string_to_unitized_double+0xe6>
jmp    1259 <string_to_unitized_double+0x119>
mov    -0xc(%rbp),%edx
mov    $0x400,%eax
mov    $0x3e8,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x40(%rbp)
jmp    1259 <string_to_unitized_double+0x119>
mov    -0xc(%rbp),%edx
mov    $0x100000,%eax
mov    $0xf4240,%ecx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %eax,-0x40(%rbp)
jmp    1259 <string_to_unitized_double+0x119>
mov    -0xc(%rbp),%edx
mov    $0x40000000,%eax
mov    $0x3b9aca00,%ecx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %eax,-0x40(%rbp)
cmpl   $0x1,-0x40(%rbp)
je     1270 <string_to_unitized_double+0x130>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
jmp    1275 <string_to_unitized_double+0x135>
jmp    127a <string_to_unitized_double+0x13a>
mov    -0x30(%rbp),%rdi
lea    0xd7b(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x39(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     12ab <string_to_unitized_double+0x16b>
mov    -0x8(%rbp),%rsi
lea    0xd60(%rip),%rdi
call   1050 <suicidef@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_unitized_double>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r12d
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    $0x1,%ebp
cmp    $0x13,%eax
jle    1169 <string_to_unitized_double+0x29>
mov    %r15,%r14
jmp    11f2 <string_to_unitized_double+0xb2>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
test   %ebx,%ebx
jle    11f2 <string_to_unitized_double+0xb2>
add    $0xffffffff,%ebx
movsbl 0x10(%rsp,%rbx,1),%eax
add    $0xffffffb9,%eax
cmp    $0x26,%eax
ja     11f2 <string_to_unitized_double+0xb2>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     11ce <string_to_unitized_double+0x8e>
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     11dd <string_to_unitized_double+0x9d>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    11f2 <string_to_unitized_double+0xb2>
test   %r12d,%r12d
mov    $0x100000,%eax
mov    $0xf4240,%ebp
jmp    11ea <string_to_unitized_double+0xaa>
test   %r12d,%r12d
mov    $0x40000000,%eax
mov    $0x3b9aca00,%ebp
jmp    11ea <string_to_unitized_double+0xaa>
test   %r12d,%r12d
mov    $0x400,%eax
mov    $0x3e8,%ebp
cmove  %eax,%ebp
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0xe07(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x7(%rsp),%rcx
mov    %r14,%rdi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     121f <string_to_unitized_double+0xdf>
lea    0xdef(%rip),%rdi
mov    %r15,%rsi
call   1050 <suicidef@plt>
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%lf%c\00"
@.str.1 = [21 x i8] c"\22%s\22 is not a number\00"
define double @string_to_unitized_double(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca double
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %6
store i32 1, i32* %10
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 20
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i8*, i8** %3
store i8* %16, i8** %7
br label %58
17: ; preds = %2
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
store i8* %18, i8** %7
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %57
24: ; preds = %17
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
switch i32 %30, label %48 [
i32 75, label %31
i32 107, label %31
i32 77, label %36
i32 109, label %36
i32 71, label %42
i32 103, label %42
]
31: ; preds = %24, %24
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 1000, i32 1024
store i32 %35, i32* %10
br label %48
36: ; preds = %24, %24
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i64 1000000, i64 1048576
%41 = trunc i64 %40 to i32
store i32 %41, i32* %10
br label %48
42: ; preds = %24, %24
%43 = load i32, i32* %4
%44 = icmp ne i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i64 1000000000, i64 1073741824
%47 = trunc i64 %46 to i32
store i32 %47, i32* %10
br label %48
48: ; preds = %24, %42, %36, %31
%49 = load i32, i32* %10
%50 = icmp ne i32 %49, 1
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i32, i32* %6
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %54
store i8 0, i8* %55
br label %56
56: ; preds = %51, %48
br label %57
57: ; preds = %56, %17
br label %58
58: ; preds = %57, %15
%59 = load i8*, i8** %7
%60 = call i32 @sscanf(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double* %8, i8* %9)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i8*, i8** %3
%64 = call i32 @suicidef(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %58
%66 = load double, double* %8
%67 = load i32, i32* %10
%68 = sitofp i32 %67 to double
%69 = fmul double %66, %68
ret double %69
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lf%c\00"
@.str.1 = [21 x i8] c"\22%s\22 is not a number\00"
define double @string_to_unitized_double(i8* %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = alloca double
%5 = alloca i8
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %0)
%8 = bitcast double* %4 to i8*
%9 = icmp sgt i32 %7, 19
br i1 %9, label %30, label %10
10: ; preds = %2
%11 = call i32 @strcpy(i8* %6, i8* %0)
%12 = icmp sgt i32 %7, 0
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = add nsw i32 %7, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %30 [
i32 75, label %19
i32 107, label %19
i32 77, label %22
i32 109, label %22
i32 71, label %25
i32 103, label %25
]
19: ; preds = %13, %13
%20 = icmp eq i32 %1, 0
%21 = select i1 %20, i32 1024, i32 1000
br label %28
22: ; preds = %13, %13
%23 = icmp eq i32 %1, 0
%24 = select i1 %23, i32 1048576, i32 1000000
br label %28
25: ; preds = %13, %13
%26 = icmp eq i32 %1, 0
%27 = select i1 %26, i32 1073741824, i32 1000000000
br label %28
28: ; preds = %25, %22, %19
%29 = phi i32 [ %21, %19 ], [ %24, %22 ], [ %27, %25 ]
store i8 0, i8* %16
br label %30
30: ; preds = %13, %2, %10, %28
%31 = phi i8* [ %6, %28 ], [ %6, %10 ], [ %0, %2 ], [ %6, %13 ]
%32 = phi i32 [ %29, %28 ], [ 1, %10 ], [ 1, %2 ], [ 1, %13 ]
%33 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double* %4, i8* %5)
%34 = icmp eq i32 %33, 1
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 @suicidef(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %37
37: ; preds = %35, %30
%38 = load double, double* %4
%39 = sitofp i32 %32 to double
%40 = fmul double %38, %39
ret double %40
}