#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 */
typedef int uint;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int atoi(char *);
int strlen(char *);
int convert_size(char *size) {
  assert(size != NULL);
  uint len = strlen(size);
  char *end = size + len;
  while (*(end) == ' ')
    end--;
  end -= 1;
  int multiplier = 1;
  switch (*end) {
  case 'G':
    multiplier = 1024 * 1024 * 1024;
    break;
  case 'M':
    multiplier = 1024 * 1024;
    break;
  case 'K':
    multiplier = 1024;
    break;
  default:
    break;
  }
  return atoi(size) * multiplier;
}


x86 assembly (clang, -O0):
<convert_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    118a <convert_size+0x5a>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1169 <convert_size+0x39>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x47,%eax
je     11d7 <convert_size+0xa7>
jmp    11b5 <convert_size+0x85>
mov    -0x20(%rbp),%eax
sub    $0x4b,%eax
je     11ef <convert_size+0xbf>
jmp    11c6 <convert_size+0x96>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     11e3 <convert_size+0xb3>
jmp    11fb <convert_size+0xcb>
movl   $0x40000000,-0x1c(%rbp)
jmp    1200 <convert_size+0xd0>
movl   $0x100000,-0x1c(%rbp)
jmp    1200 <convert_size+0xd0>
movl   $0x400,-0x1c(%rbp)
jmp    1200 <convert_size+0xd0>
jmp    1200 <convert_size+0xd0>
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
imul   -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_size>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rax)
lea    -0x1(%rax),%rax
je     1160 <convert_size+0x30>
movsbl (%rax),%eax
lea    -0x47(%rax),%ecx
mov    $0x1,%ebp
cmp    $0x6,%ecx
ja     1189 <convert_size+0x59>
cltq
lea    0xe7e(%rip),%rcx
mov    -0x11c(%rcx,%rax,4),%ebp
mov    %rbx,%rdi
call   1050 <atoi@plt>
imul   %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@switch.table.convert_size = [7 x i32] [i32 1073741824, i32 1, i32 1, i32 1, i32 1024, i32 1, i32 1048576]
define i32 @convert_size(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
br label %8
8: ; preds = %8, %1
%9 = phi i8* [ %7, %1 ], [ %12, %8 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 32
%12 = getelementptr inbounds i8, i8* %9, i64 -1
br i1 %11, label %8, label %13
13: ; preds = %8
%14 = load i8, i8* %12
%15 = sext i8 %14 to i32
%16 = add nsw i32 %15, -71
%17 = icmp ult i32 %16, 7
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.convert_size, i64 0, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %18, %13
%23 = phi i32 [ 1, %13 ], [ %21, %18 ]
%24 = tail call i32 @atoi(i8* %0)
%25 = mul nsw i32 %24, %23
ret i32 %25
}