#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 */
double strtod(char const *, char **);
size_t _parse_size(const char *string) {
  struct {
    char symbol;
    size_t multiplier;
  } quanta[] = {{'k', 1024},
                {'K', 1024},
                {'m', 1024 * 1024},
                {'M', 1024 * 1024},
                {'g', 1024 * 1024 * 1024},
                {'G', 1024 * 1024 * 1024},
                {0, 0}};
  const char *end = string;
  double value;
  value = NULL == string ? 0.0 : strtod(string, (char **)&end);
  if (end > string && '\0' != *end) {
    int i;
    for (i = 0; '\0' != quanta[i].symbol; ++i) {
      if (*end == quanta[i].symbol) {
        value *= quanta[i].multiplier;
        break;
      }
    }
  }
  return (size_t)value;
}


x86 assembly (clang, -O0):
<_parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xef6(%rip),%rsi
mov    $0x70,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    116b <_parse_size+0x4b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
jmp    1183 <_parse_size+0x63>
mov    -0x8(%rbp),%rdi
lea    -0x88(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x88(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    126e <_parse_size+0x14e>
mov    -0x88(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     126e <_parse_size+0x14e>
movl   $0x0,-0x94(%rbp)
movslq -0x94(%rbp),%rcx
lea    -0x80(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1269 <_parse_size+0x149>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
movslq -0x94(%rbp),%rdx
lea    -0x80(%rbp),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1250 <_parse_size+0x130>
movslq -0x94(%rbp),%rax
shl    $0x4,%rax
movq   -0x78(%rbp,%rax,1),%xmm0
movaps 0xde0(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xde4(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
jmp    1269 <_parse_size+0x149>
jmp    1255 <_parse_size+0x135>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11c2 <_parse_size+0xa2>
jmp    126e <_parse_size+0x14e>
movsd  -0x90(%rbp),%xmm0
ff
movsd  0xda2(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_size>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
test   %rdi,%rdi
je     115c <_parse_size+0x4c>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x8(%rsp),%rax
cmp    %rbx,%rax
jbe    11ac <_parse_size+0x9c>
mov    (%rax),%cl
add    $0xb9,%cl
cmp    $0x26,%cl
ja     11ac <_parse_size+0x9c>
xor    %eax,%eax
movzbl %cl,%ecx
lea    0xee4(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x5,%eax
jmp    117c <_parse_size+0x6c>
xorpd  %xmm0,%xmm0
jmp    11ac <_parse_size+0x9c>
mov    $0x1,%eax
jmp    117c <_parse_size+0x6c>
mov    $0x3,%eax
jmp    117c <_parse_size+0x6c>
mov    $0x4,%eax
jmp    117c <_parse_size+0x6c>
mov    $0x2,%eax
shl    $0x4,%rax
lea    0xf49(%rip),%rcx
movsd  0x8(%rax,%rcx,1),%xmm1
unpcklps 0xe6c(%rip),%xmm1
subpd  0xe74(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xe60(%rip),%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.anon = type { i8, i64 }
@__const._parse_size.quanta = [7 x %struct.anon] [%struct.anon { i8 107, i64 1024 }, %struct.anon { i8 75, i64 1024 }, %struct.anon { i8 109, i64 1048576 }, %struct.anon { i8 77, i64 1048576 }, %struct.anon { i8 103, i64 1073741824 }, %struct.anon { i8 71, i64 1073741824 }, %struct.anon zeroinitializer]
define i64 @_parse_size(i8* %0) {
%2 = alloca i8*
%3 = alloca [7 x %struct.anon]
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
store i8* %0, i8** %2
%7 = bitcast [7 x %struct.anon]* %3 to i8*
%8 = load i8*, i8** %2
store i8* %8, i8** %4
%9 = load i8*, i8** %2
%10 = icmp eq i8* null, %9
br i1 %10, label %11, label %12
11: ; preds = %1
br label %15
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call double @strtod(i8* %13, i8** %4)
br label %15
15: ; preds = %12, %11
%16 = phi double [ 0.000000e+00, %11 ], [ %14, %12 ]
store double %16, double* %5
%17 = load i8*, i8** %4
%18 = load i8*, i8** %2
%19 = icmp ugt i8* %17, %18
br i1 %19, label %20, label %59
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 0, %23
br i1 %24, label %25, label %59
25: ; preds = %20
store i32 0, i32* %6
br label %26
26: ; preds = %55, %25
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* %3, i64 0, i64 %28
%30 = getelementptr inbounds %struct.anon, %struct.anon* %29, i32 0, i32 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 0, %32
br i1 %33, label %34, label %58
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* %3, i64 0, i64 %39
%41 = getelementptr inbounds %struct.anon, %struct.anon* %40, i32 0, i32 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %37, %43
br i1 %44, label %45, label %54
45: ; preds = %34
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* %3, i64 0, i64 %47
%49 = getelementptr inbounds %struct.anon, %struct.anon* %48, i32 0, i32 1
%50 = load i64, i64* %49
%51 = uitofp i64 %50 to double
%52 = load double, double* %5
%53 = fmul double %52, %51
store double %53, double* %5
br label %58
54: ; preds = %34
br label %55
55: ; preds = %54
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %26
58: ; preds = %45, %26
br label %59
59: ; preds = %58, %20, %15
%60 = load double, double* %5
%61 = fptoui double %60 to i64
ret i64 %61
}

LLVM IR (-O2):
%struct.anon = type { i8, i64 }
@__const._parse_size.quanta = [7 x %struct.anon] [%struct.anon { i8 107, i64 1024 }, %struct.anon { i8 75, i64 1024 }, %struct.anon { i8 109, i64 1048576 }, %struct.anon { i8 77, i64 1048576 }, %struct.anon { i8 103, i64 1073741824 }, %struct.anon { i8 71, i64 1073741824 }, %struct.anon zeroinitializer]
define i64 @_parse_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* %0, i8** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = call double @strtod(i8* %0, i8** %2)
%7 = load i8*, i8** %2
%8 = icmp ugt i8* %7, %0
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = load i8, i8* %7
switch i8 %10, label %22 [
i8 71, label %15
i8 107, label %16
i8 75, label %11
i8 109, label %12
i8 77, label %13
i8 103, label %14
]
11: ; preds = %9
br label %16
12: ; preds = %9
br label %16
13: ; preds = %9
br label %16
14: ; preds = %9
br label %16
15: ; preds = %9
br label %16
16: ; preds = %9, %15, %14, %13, %12, %11
%17 = phi i64 [ 0, %9 ], [ 1, %11 ], [ 2, %12 ], [ 3, %13 ], [ 4, %14 ], [ 5, %15 ]
%18 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* @__const._parse_size.quanta, i64 0, i64 %17, i32 1
%19 = load i64, i64* %18
%20 = uitofp i64 %19 to double
%21 = fmul double %6, %20
br label %22
22: ; preds = %9, %1, %16, %5
%23 = phi double [ %6, %5 ], [ %21, %16 ], [ 0.000000e+00, %1 ], [ %6, %9 ]
%24 = fptoui double %23 to i64
ret i64 %24
}