#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int sscanf(char const *, char *, unsigned int *, char *);
int /*<<< orphan*/ stderr;
size_t parse_size(const char *input) {
  unsigned parsed_result = 0;
  char type[2] = "b";
  int scanf_result = sscanf(input, "%u%[bBkKmMgG]", &parsed_result, type);
  if (scanf_result == EOF) {
    perror("parse_size");
    exit(1);
  }
  if (scanf_result == 0) {
    fprintf(stderr, "Error in size input.\n");
    exit(1);
  }
  size_t result = parsed_result;
  switch (type[0]) {
  case 'b':
  case 'B':
    break;
  case 'g':
    result *= 1024;
  case 'm':
    result *= 1024;
  case 'k':
    result *= 1024;
    break;
  case 'G':
    result *= 1000;
  case 'M':
    result *= 1000;
  case 'K':
    result *= 1000;
    break;
  }
  return result;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0xf56(%rip),%ax
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xe(%rbp),%rcx
lea    0xf45(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%eax
jne    11a1 <parse_size+0x61>
lea    0xf2e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11ca <parse_size+0x8a>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xf10(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %rax,-0x20(%rbp)
movsbl -0xe(%rbp),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x2b,%eax
ja     124d <parse_size+0x10d>
mov    -0x28(%rbp),%rax
lea    0xe0e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    124d <parse_size+0x10d>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
jmp    124d <parse_size+0x10d>
imul   $0x3e8,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0x3e8,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0x3e8,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %rax
movl   $0x0,0x4(%rsp)
movw   $0x62,0x2(%rsp)
lea    0xf45(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x2(%rsp),%rcx
call   1040 <sscanf@plt>
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
je     11bb <parse_size+0x7b>
test   %eax,%eax
je     11d1 <parse_size+0x91>
mov    0x4(%rsp),%eax
movsbl 0x2(%rsp),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     11ab <parse_size+0x6b>
lea    0xe73(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
imul   $0x3e8,%rax,%rax
pop    %rcx
ret
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
pop    %rcx
ret
lea    0xee8(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xed4(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.parse_size.type = [2 x i8] c"b\00"
@.str = [14 x i8] c"%u%[bBkKmMgG]\00"
@EOF = global i32 0
@.str.1 = [11 x i8] c"parse_size\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Error in size input.\0A\00"
define i64 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = bitcast [2 x i8]* %4 to i8*
%8 = load i8*, i8** %2
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%10 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = load i32, i32* %3
%26 = zext i32 %25 to i64
store i64 %26, i64* %6
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
switch i32 %29, label %49 [
i32 98, label %30
i32 66, label %30
i32 103, label %31
i32 109, label %34
i32 107, label %37
i32 71, label %40
i32 77, label %43
i32 75, label %46
]
30: ; preds = %24, %24
br label %49
31: ; preds = %24
%32 = load i64, i64* %6
%33 = mul i64 %32, 1024
store i64 %33, i64* %6
br label %34
34: ; preds = %24, %31
%35 = load i64, i64* %6
%36 = mul i64 %35, 1024
store i64 %36, i64* %6
br label %37
37: ; preds = %24, %34
%38 = load i64, i64* %6
%39 = mul i64 %38, 1024
store i64 %39, i64* %6
br label %49
40: ; preds = %24
%41 = load i64, i64* %6
%42 = mul i64 %41, 1000
store i64 %42, i64* %6
br label %43
43: ; preds = %24, %40
%44 = load i64, i64* %6
%45 = mul i64 %44, 1000
store i64 %45, i64* %6
br label %46
46: ; preds = %24, %43
%47 = load i64, i64* %6
%48 = mul i64 %47, 1000
store i64 %48, i64* %6
br label %49
49: ; preds = %24, %46, %37, %30
%50 = load i64, i64* %6
ret i64 %50
}

LLVM IR (-O2):
@.str = [14 x i8] c"%u%[bBkKmMgG]\00"
@EOF = global i32 0
@.str.1 = [11 x i8] c"parse_size\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Error in size input.\0A\00"
define i64 @parse_size(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i16
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i16* %3 to i8*
store i16 98, i16* %3
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %5)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = icmp eq i32 %6, 0
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = load i32, i32* %2
%20 = zext i32 %19 to i64
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
switch i32 %22, label %39 [
i32 75, label %36
i32 77, label %33
i32 103, label %23
i32 109, label %25
i32 107, label %28
i32 71, label %31
]
23: ; preds = %18
%24 = shl nuw nsw i64 %20, 10
br label %25
25: ; preds = %18, %23
%26 = phi i64 [ %20, %18 ], [ %24, %23 ]
%27 = shl nuw nsw i64 %26, 10
br label %28
28: ; preds = %18, %25
%29 = phi i64 [ %20, %18 ], [ %27, %25 ]
%30 = shl nuw nsw i64 %29, 10
br label %39
31: ; preds = %18
%32 = mul nuw nsw i64 %20, 1000
br label %33
33: ; preds = %18, %31
%34 = phi i64 [ %32, %31 ], [ %20, %18 ]
%35 = mul nuw nsw i64 %34, 1000
br label %36
36: ; preds = %18, %33
%37 = phi i64 [ %35, %33 ], [ %20, %18 ]
%38 = mul nuw nsw i64 %37, 1000
br label %39
39: ; preds = %18, %36, %28
%40 = phi i64 [ %20, %18 ], [ %38, %36 ], [ %30, %28 ]
ret i64 %40
}