#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*/ printf(char *, size_t, ...);
size_t parseSize(char *size) {
  size_t base = 0, totalSize = 0;
  char *multStr = size;
  base = (size_t)(size[0] - '0');
  switch (multStr[1]) {
  case 'G':
    totalSize = base * (1 << 30);
    printf("Using %zu Gib\n", base);
    break;
  case 'M':
    totalSize = base * (1 << 20);
    printf("Using %zu Gib\n", base);
    break;
  case 'K':
    totalSize = base * (1 << 10);
    printf("Using %zu Kib\n", base);
    break;
  default:
    printf("No valid size detected: Using %z bytes, input: %s\n", base,
           multStr);
  }
  return totalSize;
}


x86 assembly (clang, -O0):
<parseSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffd0,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x47,%eax
je     117f <parseSize+0x6f>
jmp    115d <parseSize+0x4d>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     11c5 <parseSize+0xb5>
jmp    116e <parseSize+0x5e>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     11a2 <parseSize+0x92>
jmp    11e8 <parseSize+0xd8>
mov    -0x10(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <parseSize+0xee>
mov    -0x10(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <parseSize+0xee>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <parseSize+0xee>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseSize>:
push   %rbx
movsbq (%rdi),%rsi
add    $0xffffffffffffffd0,%rsi
movsbl 0x1(%rdi),%eax
cmp    $0x4d,%eax
je     1135 <parseSize+0x25>
cmp    $0x4b,%eax
je     1145 <parseSize+0x35>
cmp    $0x47,%eax
jne    115c <parseSize+0x4c>
mov    %rsi,%rbx
shl    $0x1e,%rbx
jmp    113c <parseSize+0x2c>
mov    %rsi,%rbx
shl    $0x14,%rbx
lea    0xebd(%rip),%rdi
jmp    1153 <parseSize+0x43>
mov    %rsi,%rbx
shl    $0xa,%rbx
lea    0xebc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    116f <parseSize+0x5f>
mov    %rdi,%rdx
lea    0xeb8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Using %zu Gib\0A\00"
@.str.1 = [15 x i8] c"Using %zu Kib\0A\00"
@.str.2 = [51 x i8] c"No valid size detected: Using %z bytes, input: %s\0A\00"
define i64 @parseSize(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
store i64 0, i64* %4
%6 = load i8*, i8** %2
store i8* %6, i8** %5
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = sub nsw i32 %10, 48
%12 = sext i32 %11 to i64
store i64 %12, i64* %3
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %32 [
i32 71, label %17
i32 77, label %22
i32 75, label %27
]
17: ; preds = %1
%18 = load i64, i64* %3
%19 = mul i64 %18, 1073741824
store i64 %19, i64* %4
%20 = load i64, i64* %3
%21 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %20)
br label %36
22: ; preds = %1
%23 = load i64, i64* %3
%24 = mul i64 %23, 1048576
store i64 %24, i64* %4
%25 = load i64, i64* %3
%26 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %25)
br label %36
27: ; preds = %1
%28 = load i64, i64* %3
%29 = mul i64 %28, 1024
store i64 %29, i64* %4
%30 = load i64, i64* %3
%31 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %30)
br label %36
32: ; preds = %1
%33 = load i64, i64* %3
%34 = load i8*, i8** %5
%35 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i64 %33, i8* %34)
br label %36
36: ; preds = %32, %27, %22, %17
%37 = load i64, i64* %4
ret i64 %37
}

LLVM IR (-O2):
@.str = [15 x i8] c"Using %zu Gib\0A\00"
@.str.1 = [15 x i8] c"Using %zu Kib\0A\00"
@.str.2 = [51 x i8] c"No valid size detected: Using %z bytes, input: %s\0A\00"
define i64 @parseSize(i8* %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i64
%4 = add nsw i64 %3, -48
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %17 [
i32 71, label %8
i32 77, label %11
i32 75, label %14
]
8: ; preds = %1
%9 = shl nsw i64 %4, 30
%10 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %4)
br label %19
11: ; preds = %1
%12 = shl nsw i64 %4, 20
%13 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %4)
br label %19
14: ; preds = %1
%15 = shl nsw i64 %4, 10
%16 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %4)
br label %19
17: ; preds = %1
%18 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i64 %4, i8* %0)
br label %19
19: ; preds = %17, %14, %11, %8
%20 = phi i64 [ 0, %17 ], [ %15, %14 ], [ %12, %11 ], [ %9, %8 ]
ret i64 %20
}