#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 */
unsigned long strtoul(char const *, char **, int);
char toupper(char);
size_t parse_size(const char *str) {
  char *endptr;
  unsigned long size = strtoul(str, &endptr, 10);
  if (toupper(*endptr) == 'K')
    size *= 1000;
  else if (toupper(*endptr) == 'M')
    size *= 1000000;
  else if (toupper(*endptr) == 'G')
    size *= 1000000000;
  return size;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x4b,%eax
jne    116b <parse_size+0x4b>
imul   $0x3e8,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11c2 <parse_size+0xa2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x4d,%eax
jne    1194 <parse_size+0x74>
imul   $0xf4240,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11bd <parse_size+0x9d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x47,%eax
jne    11b8 <parse_size+0x98>
imul   $0x3b9aca00,-0x18(%rbp),%rax
3b
mov    %rax,-0x18(%rbp)
jmp    11bd <parse_size+0x9d>
jmp    11c2 <parse_size+0xa2>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%r14
mov    (%rsp),%rbx
movsbl (%rbx),%edi
call   1030 <toupper@plt>
cmp    $0x4b,%al
jne    114d <parse_size+0x2d>
imul   $0x3e8,%r14,%rax
jmp    117a <parse_size+0x5a>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
cmp    $0x4d,%al
jne    1162 <parse_size+0x42>
imul   $0xf4240,%r14,%rax
jmp    117a <parse_size+0x5a>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
imul   $0x3b9aca00,%r14,%rax
cmp    $0x47,%cl
cmovne %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @parse_size(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 10)
store i64 %6, i64* %4
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call signext i8 @toupper(i8 signext %8)
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 75
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i64, i64* %4
%14 = mul i64 %13, 1000
store i64 %14, i64* %4
br label %35
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 77
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i64, i64* %4
%23 = mul i64 %22, 1000000
store i64 %23, i64* %4
br label %34
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call signext i8 @toupper(i8 signext %26)
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 71
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i64, i64* %4
%32 = mul i64 %31, 1000000000
store i64 %32, i64* %4
br label %33
33: ; preds = %30, %24
br label %34
34: ; preds = %33, %21
br label %35
35: ; preds = %34, %12
%36 = load i64, i64* %4
ret i64 %36
}

LLVM IR (-O2):
define i64 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = tail call signext i8 @toupper(i8 signext %6)
%8 = icmp eq i8 %7, 75
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = mul i64 %4, 1000
br label %23
11: ; preds = %1
%12 = load i8, i8* %5
%13 = tail call signext i8 @toupper(i8 signext %12)
%14 = icmp eq i8 %13, 77
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = mul i64 %4, 1000000
br label %23
17: ; preds = %11
%18 = load i8, i8* %5
%19 = tail call signext i8 @toupper(i8 signext %18)
%20 = icmp eq i8 %19, 71
%21 = mul i64 %4, 1000000000
%22 = select i1 %20, i64 %21, i64 %4
br label %23
23: ; preds = %17, %15, %9
%24 = phi i64 [ %10, %9 ], [ %16, %15 ], [ %22, %17 ]
ret i64 %24
}