#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 */
long strtoul(char *, char **, int /*<<< orphan*/);
int toupper(char);
long memsize(char *s) {
  char *end;
  long length = strtoul(s, &end, 0);
  switch (toupper(*end)) {
  case 'G':
    length *= 1024;
  case 'M':
    length *= 1024;
  case 'K':
    length *= 1024;
    break;
  }
  return length;
}


x86 assembly (clang, -O0):
<memsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x47,%eax
je     1180 <memsize+0x60>
jmp    115e <memsize+0x3e>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     1198 <memsize+0x78>
jmp    116f <memsize+0x4f>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     118c <memsize+0x6c>
jmp    11a4 <memsize+0x84>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memsize>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
cmp    $0x4d,%eax
je     1154 <memsize+0x34>
cmp    $0x4b,%eax
je     1158 <memsize+0x38>
cmp    $0x47,%eax
jne    115c <memsize+0x3c>
shl    $0xa,%rbx
shl    $0xa,%rbx
shl    $0xa,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @memsize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtoul(i8* %5, i8** %3, i32 0)
store i64 %6, i64* %4
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call i32 @toupper(i8 signext %8)
switch i32 %9, label %19 [
i32 71, label %10
i32 77, label %13
i32 75, label %16
]
10: ; preds = %1
%11 = load i64, i64* %4
%12 = mul nsw i64 %11, 1024
store i64 %12, i64* %4
br label %13
13: ; preds = %1, %10
%14 = load i64, i64* %4
%15 = mul nsw i64 %14, 1024
store i64 %15, i64* %4
br label %16
16: ; preds = %1, %13
%17 = load i64, i64* %4
%18 = mul nsw i64 %17, 1024
store i64 %18, i64* %4
br label %19
19: ; preds = %1, %16
%20 = load i64, i64* %4
ret i64 %20
}

LLVM IR (-O2):
define i64 @memsize(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = tail call i32 @toupper(i8 signext %6)
switch i32 %7, label %16 [
i32 71, label %8
i32 77, label %10
i32 75, label %13
]
8: ; preds = %1
%9 = shl nsw i64 %4, 10
br label %10
10: ; preds = %1, %8
%11 = phi i64 [ %4, %1 ], [ %9, %8 ]
%12 = shl nsw i64 %11, 10
br label %13
13: ; preds = %1, %10
%14 = phi i64 [ %4, %1 ], [ %12, %10 ]
%15 = shl nsw i64 %14, 10
br label %16
16: ; preds = %1, %13
%17 = phi i64 [ %4, %1 ], [ %15, %13 ]
ret i64 %17
}