#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 */
unsigned long long strtoll(char const *, char **, int);
unsigned long long parse_size(const char *p) {
  unsigned long long size;
  char *q;
  size = strtoll(p, &q, 10);
  switch (*q) {
  case 'K':
  case 'k':
    size *= 1024;
    q++;
    break;
  case 'M':
  case 'm':
    size *= 1024 * 1024;
    q++;
    break;
  case 'G':
  case 'g':
    size *= 1024 * 1024 * 1024;
    q++;
    break;
  default:
    break;
  }
  if (*q != '\0')
    size = 0;
  return size;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x47,%eax
je     11d9 <parse_size+0xc9>
jmp    114a <parse_size+0x3a>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     119f <parse_size+0x8f>
jmp    115b <parse_size+0x4b>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     11bc <parse_size+0xac>
jmp    116c <parse_size+0x5c>
mov    -0x1c(%rbp),%eax
sub    $0x67,%eax
je     11d9 <parse_size+0xc9>
jmp    117d <parse_size+0x6d>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     119f <parse_size+0x8f>
jmp    118e <parse_size+0x7e>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
je     11bc <parse_size+0xac>
jmp    11f6 <parse_size+0xe6>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11fb <parse_size+0xeb>
mov    -0x10(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11fb <parse_size+0xeb>
mov    -0x10(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11fb <parse_size+0xeb>
jmp    11fb <parse_size+0xeb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1213 <parse_size+0x103>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    (%rsp),%rdx
movsbl (%rdx),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     1171 <parse_size+0x61>
movabs $0x100000001,%rsi
bt     %rcx,%rsi
jb     1163 <parse_size+0x53>
movabs $0x1000000010,%rsi
bt     %rcx,%rsi
jb     1169 <parse_size+0x59>
movabs $0x4000000040,%rsi
bt     %rcx,%rsi
jae    1171 <parse_size+0x61>
shl    $0x14,%rax
jmp    116d <parse_size+0x5d>
shl    $0x1e,%rax
jmp    116d <parse_size+0x5d>
shl    $0xa,%rax
add    $0x1,%rdx
xor    %ecx,%ecx
cmpb   $0x0,(%rdx)
cmove  %rax,%rcx
mov    %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtoll(i8* %5, i8** %4, i32 10)
store i64 %6, i64* %3
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %25 [
i32 75, label %10
i32 107, label %10
i32 77, label %15
i32 109, label %15
i32 71, label %20
i32 103, label %20
]
10: ; preds = %1, %1
%11 = load i64, i64* %3
%12 = mul i64 %11, 1024
store i64 %12, i64* %3
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
br label %26
15: ; preds = %1, %1
%16 = load i64, i64* %3
%17 = mul i64 %16, 1048576
store i64 %17, i64* %3
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
br label %26
20: ; preds = %1, %1
%21 = load i64, i64* %3
%22 = mul i64 %21, 1073741824
store i64 %22, i64* %3
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %26
25: ; preds = %1
br label %26
26: ; preds = %25, %20, %15, %10
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i64 0, i64* %3
br label %32
32: ; preds = %31, %26
%33 = load i64, i64* %3
ret i64 %33
}

LLVM IR (-O2):
define i64 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoll(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %17 [
i32 75, label %8
i32 107, label %8
i32 77, label %11
i32 109, label %11
i32 71, label %14
i32 103, label %14
]
8: ; preds = %1, %1
%9 = shl i64 %4, 10
%10 = getelementptr inbounds i8, i8* %5, i64 1
br label %17
11: ; preds = %1, %1
%12 = shl i64 %4, 20
%13 = getelementptr inbounds i8, i8* %5, i64 1
br label %17
14: ; preds = %1, %1
%15 = shl i64 %4, 30
%16 = getelementptr inbounds i8, i8* %5, i64 1
br label %17
17: ; preds = %1, %14, %11, %8
%18 = phi i8* [ %5, %1 ], [ %16, %14 ], [ %13, %11 ], [ %10, %8 ]
%19 = phi i64 [ %4, %1 ], [ %15, %14 ], [ %12, %11 ], [ %9, %8 ]
%20 = load i8, i8* %18
%21 = icmp eq i8 %20, 0
%22 = select i1 %21, i64 %19, i64 0
ret i64 %22
}