#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 strtol(char const *, char **, int);
int parse_size(const char *size) {
  int value;
  char *end;
  value = strtol(size, &end, 10);
  switch (*end) {
  case 'k':
  case 'K':
    value *= 1024;
    break;
  case 'm':
  case 'M':
    value *= 1024 * 1024;
    break;
  case 'g':
  case 'G':
    value *= 1024 * 1024 * 1024;
    break;
  }
  return value;
}


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 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x47,%eax
je     11ba <parse_size+0xaa>
jmp    1149 <parse_size+0x39>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     119e <parse_size+0x8e>
jmp    115a <parse_size+0x4a>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     11ac <parse_size+0x9c>
jmp    116b <parse_size+0x5b>
mov    -0x1c(%rbp),%eax
sub    $0x67,%eax
je     11ba <parse_size+0xaa>
jmp    117c <parse_size+0x6c>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     119e <parse_size+0x8e>
jmp    118d <parse_size+0x7d>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
je     11ac <parse_size+0x9c>
jmp    11c3 <parse_size+0xb3>
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11c3 <parse_size+0xb3>
mov    -0xc(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0xc(%rbp)
jmp    11c3 <parse_size+0xb3>
mov    -0xc(%rbp),%eax
shl    $0x1e,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    (%rsp),%rcx
movsbl (%rcx),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     1165 <parse_size+0x55>
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     1162 <parse_size+0x52>
movabs $0x1000000010,%rdx
bt     %rcx,%rdx
jb     1167 <parse_size+0x57>
movabs $0x4000000040,%rdx
bt     %rcx,%rdx
jae    1165 <parse_size+0x55>
shl    $0x14,%eax
pop    %rcx
ret
shl    $0x1e,%eax
pop    %rcx
ret
shl    $0xa,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i32 @strtol(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 %14 [
i32 107, label %8
i32 75, label %8
i32 109, label %10
i32 77, label %10
i32 103, label %12
i32 71, label %12
]
8: ; preds = %1, %1
%9 = shl nsw i32 %4, 10
br label %14
10: ; preds = %1, %1
%11 = shl nsw i32 %4, 20
br label %14
12: ; preds = %1, %1
%13 = shl nsw i32 %4, 30
br label %14
14: ; preds = %1, %12, %10, %8
%15 = phi i32 [ %4, %1 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ]
ret i32 %15
}