#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 */
int /*<<< orphan*/ sscanf(char const *, char *, double *, char *);
double unit_atod(const char *s, int unit_k) {
  double n;
  char suffix = '\0';
  sscanf(s, "%lf%c", &n, &suffix);
  switch (suffix) {
  case 'g':
  case 'G':
    n *= (unit_k * unit_k * unit_k);
    break;
  case 'm':
  case 'M':
    n *= (unit_k * unit_k);
    break;
  case 'k':
  case 'K':
    n *= unit_k;
    break;
  default:
    break;
  }
  return n;
}


x86 assembly (clang, -O0):
<unit_atod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed2(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x19(%rbp),%rcx
call   1030 <sscanf@plt>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x47,%eax
je     11a5 <unit_atod+0x95>
jmp    1150 <unit_atod+0x40>
mov    -0x20(%rbp),%eax
sub    $0x4b,%eax
je     11dd <unit_atod+0xcd>
jmp    1161 <unit_atod+0x51>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     11c3 <unit_atod+0xb3>
jmp    1172 <unit_atod+0x62>
mov    -0x20(%rbp),%eax
sub    $0x67,%eax
je     11a5 <unit_atod+0x95>
jmp    1183 <unit_atod+0x73>
mov    -0x20(%rbp),%eax
sub    $0x6b,%eax
je     11dd <unit_atod+0xcd>
jmp    1194 <unit_atod+0x84>
mov    -0x20(%rbp),%eax
sub    $0x6d,%eax
je     11c3 <unit_atod+0xb3>
jmp    11f1 <unit_atod+0xe1>
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11f6 <unit_atod+0xe6>
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11f6 <unit_atod+0xe6>
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11f6 <unit_atod+0xe6>
jmp    11f6 <unit_atod+0xe6>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_atod>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movb   $0x0,0x7(%rsp)
lea    0xedd(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x7(%rsp),%rcx
call   1030 <sscanf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffb9,%eax
cmp    $0x26,%eax
ja     1190 <unit_atod+0x80>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     1178 <unit_atod+0x68>
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     1172 <unit_atod+0x62>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    1190 <unit_atod+0x80>
imul   %ebx,%ebx
cvtsi2sd %ebx,%xmm0
jmp    1184 <unit_atod+0x74>
mov    %ebx,%eax
imul   %ebx,%eax
imul   %ebx,%eax
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret
movsd  0x8(%rsp),%xmm0
jmp    118a <unit_atod+0x7a>

LLVM IR (-O0):
@.str = [6 x i8] c"%lf%c\00"
define double @unit_atod(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* %6
%7 = load i8*, i8** %3
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double* %5, i8* %6)
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
switch i32 %10, label %32 [
i32 103, label %11
i32 71, label %11
i32 109, label %20
i32 77, label %20
i32 107, label %27
i32 75, label %27
]
11: ; preds = %2, %2
%12 = load i32, i32* %4
%13 = load i32, i32* %4
%14 = mul nsw i32 %12, %13
%15 = load i32, i32* %4
%16 = mul nsw i32 %14, %15
%17 = sitofp i32 %16 to double
%18 = load double, double* %5
%19 = fmul double %18, %17
store double %19, double* %5
br label %33
20: ; preds = %2, %2
%21 = load i32, i32* %4
%22 = load i32, i32* %4
%23 = mul nsw i32 %21, %22
%24 = sitofp i32 %23 to double
%25 = load double, double* %5
%26 = fmul double %25, %24
store double %26, double* %5
br label %33
27: ; preds = %2, %2
%28 = load i32, i32* %4
%29 = sitofp i32 %28 to double
%30 = load double, double* %5
%31 = fmul double %30, %29
store double %31, double* %5
br label %33
32: ; preds = %2
br label %33
33: ; preds = %32, %27, %20, %11
%34 = load double, double* %5
ret double %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lf%c\00"
define double @unit_atod(i8* nocapture %0, i32 %1) {
%3 = alloca double
%4 = alloca i8
%5 = bitcast double* %3 to i8*
store i8 0, i8* %4
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double* %3, i8* %4)
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
switch i32 %8, label %9 [
i32 103, label %11
i32 71, label %11
i32 109, label %17
i32 77, label %17
i32 107, label %22
i32 75, label %22
]
9: ; preds = %2
%10 = load double, double* %3
br label %26
11: ; preds = %2, %2
%12 = mul nsw i32 %1, %1
%13 = mul nsw i32 %12, %1
%14 = sitofp i32 %13 to double
%15 = load double, double* %3
%16 = fmul double %15, %14
br label %26
17: ; preds = %2, %2
%18 = mul nsw i32 %1, %1
%19 = sitofp i32 %18 to double
%20 = load double, double* %3
%21 = fmul double %20, %19
br label %26
22: ; preds = %2, %2
%23 = sitofp i32 %1 to double
%24 = load double, double* %3
%25 = fmul double %24, %23
br label %26
26: ; preds = %9, %22, %17, %11
%27 = phi double [ %10, %9 ], [ %25, %22 ], [ %21, %17 ], [ %16, %11 ]
ret double %27
}