#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 sscanf(char *, char *, int *);
int strlen(char *);
int parse_size(char *st, int *size) {
  int length = strlen(st);
  char sizet;
  if (length == 0)
    return 1;
  sizet = st[length - 1];
  switch (sizet) {
  case 'B':
  case 'b':
  case 'K':
  case 'k':
  case 'M':
  case 'm':
  case 'G':
    st[length - 1] = '\0';
  }
  if (sscanf(st, "%d", size) < 1)
    return 2;
  switch (sizet) {
  case 'K':
  case 'k':
    *size *= 1024;
    break;
  case 'M':
  case 'm':
    *size *= (1024 * 1024);
    break;
  case 'G':
    *size = 1024 * (1024 * 1024);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1152 <parse_size+0x32>
movl   $0x1,-0x4(%rbp)
jmp    1275 <parse_size+0x155>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x42,%eax
je     11e0 <parse_size+0xc0>
jmp    117a <parse_size+0x5a>
mov    -0x24(%rbp),%eax
sub    $0x47,%eax
je     11e0 <parse_size+0xc0>
jmp    118b <parse_size+0x6b>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     11e0 <parse_size+0xc0>
jmp    119c <parse_size+0x7c>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     11e0 <parse_size+0xc0>
jmp    11ad <parse_size+0x8d>
mov    -0x24(%rbp),%eax
sub    $0x62,%eax
je     11e0 <parse_size+0xc0>
jmp    11be <parse_size+0x9e>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     11e0 <parse_size+0xc0>
jmp    11cf <parse_size+0xaf>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
jne    11f1 <parse_size+0xd1>
jmp    11e0 <parse_size+0xc0>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe9c(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jge    121a <parse_size+0xfa>
movl   $0x2,-0x4(%rbp)
jmp    1275 <parse_size+0x155>
movsbl -0x1d(%rbp),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x26,%eax
ja     126e <parse_size+0x14e>
mov    -0x30(%rbp),%rax
lea    0xdc5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0xa,%ecx
mov    %ecx,(%rax)
jmp    126e <parse_size+0x14e>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x14,%ecx
mov    %ecx,(%rax)
jmp    126e <parse_size+0x14e>
mov    -0x18(%rbp),%rax
movl   $0x40000000,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     11a5 <parse_size+0x85>
cltq
movsbl -0x1(%rax,%rbx,1),%r15d
lea    -0x42(%r15),%ecx
cmp    $0x2b,%ecx
ja     115a <parse_size+0x3a>
movabs $0xa0100000a21,%rdx
bt     %rcx,%rdx
jae    115a <parse_size+0x3a>
movb   $0x0,-0x1(%rbx,%rax,1)
lea    0xf3b(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
test   %eax,%eax
jle    11ac <parse_size+0x8c>
xor    %eax,%eax
add    $0xffffffb9,%r15d
cmp    $0x26,%r15d
ja     11b1 <parse_size+0x91>
mov    $0x40000000,%edx
mov    $0xa,%ecx
lea    0xe73(%rip),%rsi
movslq (%rsi,%r15,4),%rdi
add    %rsi,%rdi
jmp    *%rdi
mov    $0x14,%ecx
mov    (%r14),%edx
shl    %cl,%edx
mov    %edx,(%r14)
jmp    11b1 <parse_size+0x91>
mov    $0x1,%eax
jmp    11b1 <parse_size+0x91>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @parse_size(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %48
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %7
%20 = load i8, i8* %7
%21 = sext i8 %20 to i32
switch i32 %21, label %28 [
i32 66, label %22
i32 98, label %22
i32 75, label %22
i32 107, label %22
i32 77, label %22
i32 109, label %22
i32 71, label %22
]
22: ; preds = %13, %13, %13, %13, %13, %13, %13
%23 = load i8*, i8** %4
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %22, %13
%29 = load i8*, i8** %4
%30 = load i32*, i32** %5
%31 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %30)
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 2, i32* %3
br label %48
34: ; preds = %28
%35 = load i8, i8* %7
%36 = sext i8 %35 to i32
switch i32 %36, label %47 [
i32 75, label %37
i32 107, label %37
i32 77, label %41
i32 109, label %41
i32 71, label %45
]
37: ; preds = %34, %34
%38 = load i32*, i32** %5
%39 = load i32, i32* %38
%40 = mul nsw i32 %39, 1024
store i32 %40, i32* %38
br label %47
41: ; preds = %34, %34
%42 = load i32*, i32** %5
%43 = load i32, i32* %42
%44 = mul nsw i32 %43, 1048576
store i32 %44, i32* %42
br label %47
45: ; preds = %34
%46 = load i32*, i32** %5
store i32 1073741824, i32* %46
br label %47
47: ; preds = %34, %45, %41, %37
store i32 0, i32* %3
br label %48
48: ; preds = %47, %33, %12
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @parse_size(i8* %0, i32* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2
%6 = add nsw i32 %3, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %12 [
i32 66, label %11
i32 98, label %11
i32 75, label %11
i32 107, label %11
i32 77, label %11
i32 109, label %11
i32 71, label %11
]
11: ; preds = %5, %5, %5, %5, %5, %5, %5
store i8 0, i8* %8
br label %12
12: ; preds = %11, %5
%13 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%14 = icmp slt i32 %13, 1
br i1 %14, label %23, label %15
15: ; preds = %12
switch i32 %10, label %23 [
i32 75, label %17
i32 107, label %17
i32 77, label %16
i32 109, label %16
i32 71, label %21
]
16: ; preds = %15, %15
br label %17
17: ; preds = %15, %15, %16
%18 = phi i32 [ 20, %16 ], [ 10, %15 ], [ 10, %15 ]
%19 = load i32, i32* %1
%20 = shl nsw i32 %19, %18
br label %21
21: ; preds = %17, %15
%22 = phi i32 [ 1073741824, %15 ], [ %20, %17 ]
store i32 %22, i32* %1
br label %23
23: ; preds = %21, %15, %12, %2
%24 = phi i32 [ 1, %2 ], [ 2, %12 ], [ 0, %15 ], [ 0, %21 ]
ret i32 %24
}