#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 long strtoll(char *, char **, int);
long long parse_size(char *size) {
  char *c;
  long long s = strtoll(size, &c, 10);
  if (s > 0) {
    switch (*c) {
    case 'K':
      c++;
    default:
      s *= 2;
      break;
    case 'M':
      c++;
      s *= 1024 * 2;
      break;
    case 'G':
      c++;
      s *= 1024 * 1024 * 2;
      break;
    }
  }
  if (*c)
    s = -1;
  return s;
}


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   1030 <strtoll@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11ce <parse_size+0xbe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x47,%eax
je     11b1 <parse_size+0xa1>
jmp    1155 <parse_size+0x45>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     1177 <parse_size+0x67>
jmp    1166 <parse_size+0x56>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     1194 <parse_size+0x84>
jmp    1183 <parse_size+0x73>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c9 <parse_size+0xb9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shl    $0xb,%rax
mov    %rax,-0x18(%rbp)
jmp    11c9 <parse_size+0xb9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x15,%rax
mov    %rax,-0x18(%rbp)
jmp    11ce <parse_size+0xbe>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e3 <parse_size+0xd3>
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    (%rsp),%rcx
test   %rax,%rax
jle    1154 <parse_size+0x44>
movsbl (%rcx),%edx
cmp    $0x47,%edx
je     1142 <parse_size+0x32>
cmp    $0x4d,%edx
je     114c <parse_size+0x3c>
cmp    $0x4b,%edx
jne    113d <parse_size+0x2d>
add    $0x1,%rcx
add    %rax,%rax
jmp    1154 <parse_size+0x44>
add    $0x1,%rcx
shl    $0x15,%rax
jmp    1154 <parse_size+0x44>
add    $0x1,%rcx
shl    $0xb,%rax
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %rcx,%rcx
or     %rax,%rcx
mov    %rcx,%rax
pop    %rcx
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 @strtoll(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %16 [
i32 75, label %13
i32 77, label %19
i32 71, label %24
]
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
br label %16
16: ; preds = %9, %13
%17 = load i64, i64* %4
%18 = mul nsw i64 %17, 2
store i64 %18, i64* %4
br label %29
19: ; preds = %9
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
%22 = load i64, i64* %4
%23 = mul nsw i64 %22, 2048
store i64 %23, i64* %4
br label %29
24: ; preds = %9
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = load i64, i64* %4
%28 = mul nsw i64 %27, 2097152
store i64 %28, i64* %4
br label %29
29: ; preds = %24, %19, %16
br label %30
30: ; preds = %29, %1
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i64 -1, i64* %4
br label %35
35: ; preds = %34, %30
%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 @strtoll(i8* %0, i8** %2, i32 10)
%5 = icmp sgt i64 %4, 0
%6 = load i8*, i8** %2
br i1 %5, label %7, label %21
7: ; preds = %1
%8 = load i8, i8* %6
%9 = sext i8 %8 to i32
switch i32 %9, label %12 [
i32 75, label %10
i32 77, label %15
i32 71, label %18
]
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %6, i64 1
br label %12
12: ; preds = %7, %10
%13 = phi i8* [ %6, %7 ], [ %11, %10 ]
%14 = shl nuw nsw i64 %4, 1
br label %21
15: ; preds = %7
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = shl nsw i64 %4, 11
br label %21
18: ; preds = %7
%19 = getelementptr inbounds i8, i8* %6, i64 1
%20 = shl nsw i64 %4, 21
br label %21
21: ; preds = %1, %12, %15, %18
%22 = phi i8* [ %13, %12 ], [ %19, %18 ], [ %16, %15 ], [ %6, %1 ]
%23 = phi i64 [ %14, %12 ], [ %20, %18 ], [ %17, %15 ], [ %4, %1 ]
%24 = load i8, i8* %22
%25 = icmp eq i8 %24, 0
%26 = select i1 %25, i64 %23, i64 -1
ret i64 %26
}