#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 *, char *, unsigned long *, char *);
char tolower(char);
unsigned long getsize(char *str) {
  char m;
  unsigned long sz = 0UL;
  sscanf(str, "%lu%c", &sz, &m);
  m = tolower(m);
  switch (m) {
  case '\0':
  case 'b':
    sz = sz;
    break;
  case 'k':
    sz = sz * 1024;
    break;
  case 'm':
    sz = sz * 1024 * 1024;
    break;
  case 'g':
    sz = sz * 1024 * 1024 * 1024;
    break;
  default:
    sz = 0UL;
  }
  return sz;
}


x86 assembly (clang, -O0):
<getsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec1(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x9(%rbp),%rcx
call   1040 <sscanf@plt>
movsbl -0x9(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11b0 <getsize+0x90>
jmp    116c <getsize+0x4c>
mov    -0x1c(%rbp),%eax
sub    $0x62,%eax
je     11b0 <getsize+0x90>
jmp    117d <getsize+0x5d>
mov    -0x1c(%rbp),%eax
sub    $0x67,%eax
je     11e3 <getsize+0xc3>
jmp    118e <getsize+0x6e>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     11bd <getsize+0x9d>
jmp    119f <getsize+0x7f>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
je     11ce <getsize+0xae>
jmp    11fc <getsize+0xdc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1204 <getsize+0xe4>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1204 <getsize+0xe4>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1204 <getsize+0xe4>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1204 <getsize+0xe4>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsize>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
lea    0xefc(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xf(%rsp),%rcx
call   1040 <sscanf@plt>
movsbl 0xf(%rsp),%edi
call   1030 <tolower@plt>
movsbl %al,%ecx
lea    -0x62(%rcx),%eax
cmp    $0xb,%eax
ja     1170 <getsize+0x50>
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
shlq   $0x1e,0x10(%rsp)
jmp    118d <getsize+0x6d>
test   %ecx,%ecx
je     118d <getsize+0x6d>
movq   $0x0,0x10(%rsp)
jmp    118d <getsize+0x6d>
shlq   $0xa,0x10(%rsp)
jmp    118d <getsize+0x6d>
shlq   $0x14,0x10(%rsp)
mov    0x10(%rsp),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%lu%c\00"
define i64 @getsize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %4
%5 = load i8*, i8** %2
%6 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %4, i8* %3)
%7 = load i8, i8* %3
%8 = call signext i8 @tolower(i8 signext %7)
store i8 %8, i8* %3
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
switch i32 %10, label %25 [
i32 0, label %11
i32 98, label %11
i32 107, label %13
i32 109, label %16
i32 103, label %20
]
11: ; preds = %1, %1
%12 = load i64, i64* %4
store i64 %12, i64* %4
br label %26
13: ; preds = %1
%14 = load i64, i64* %4
%15 = mul i64 %14, 1024
store i64 %15, i64* %4
br label %26
16: ; preds = %1
%17 = load i64, i64* %4
%18 = mul i64 %17, 1024
%19 = mul i64 %18, 1024
store i64 %19, i64* %4
br label %26
20: ; preds = %1
%21 = load i64, i64* %4
%22 = mul i64 %21, 1024
%23 = mul i64 %22, 1024
%24 = mul i64 %23, 1024
store i64 %24, i64* %4
br label %26
25: ; preds = %1
store i64 0, i64* %4
br label %26
26: ; preds = %25, %20, %16, %13, %11
%27 = load i64, i64* %4
ret i64 %27
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lu%c\00"
define i64 @getsize(i8* nocapture %0) {
%2 = alloca i8
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %3, i8* %2)
%6 = load i8, i8* %2
%7 = call signext i8 @tolower(i8 signext %6)
%8 = sext i8 %7 to i32
switch i32 %8, label %18 [
i32 0, label %19
i32 98, label %19
i32 107, label %9
i32 109, label %12
i32 103, label %15
]
9: ; preds = %1
%10 = load i64, i64* %3
%11 = shl i64 %10, 10
store i64 %11, i64* %3
br label %19
12: ; preds = %1
%13 = load i64, i64* %3
%14 = shl i64 %13, 20
store i64 %14, i64* %3
br label %19
15: ; preds = %1
%16 = load i64, i64* %3
%17 = shl i64 %16, 30
store i64 %17, i64* %3
br label %19
18: ; preds = %1
store i64 0, i64* %3
br label %19
19: ; preds = %1, %1, %18, %15, %12, %9
%20 = load i64, i64* %3
ret i64 %20
}