#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 */
typedef int uint64_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
uint64_t parse_size_str(char *input) {
  if (!strcmp(&input[strlen(input) - 2], "MB")) {
    input[strlen(input) - 2] = 0;
    return (uint64_t)atoi(input) * 1024 * 1024;
  } else if (!strcmp(&input[strlen(input) - 2], "GB")) {
    input[strlen(input) - 3] = 0;
    return (uint64_t)atoi(input) * 1024 * 1024 * 1024;
  } else if (!strcmp(&input[strlen(input) - 1], "B")) {
    input[strlen(input) - 2] = 0;
  }
  return atoi(input);
}


x86 assembly (clang, -O0):
<parse_size_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
sub    $0x2,%eax
cltq
add    %rax,%rdi
lea    0xea0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a6 <parse_size_str+0x76>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    127c <parse_size_str+0x14c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
sub    $0x2,%eax
cltq
add    %rax,%rdi
lea    0xe39(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1213 <parse_size_str+0xe3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
shl    $0xa,%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    127c <parse_size_str+0x14c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
sub    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xdcd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1266 <parse_size_str+0x136>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    126b <parse_size_str+0x13b>
jmp    1270 <parse_size_str+0x140>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size_str>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xeb4(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xfffffffffffffffe,%rdi
test   %ebp,%ebp
je     11ba <parse_size_str+0x8a>
lea    0xe93(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
test   %ebp,%ebp
je     11ca <parse_size_str+0x9a>
lea    (%rax,%rbx,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe70(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    11ac <parse_size_str+0x7c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <atoi@plt>
movb   $0x0,(%rdi)
mov    %rbx,%rdi
call   1050 <atoi@plt>
shl    $0x14,%eax
jmp    11da <parse_size_str+0xaa>
movb   $0x0,-0x3(%rax,%rbx,1)
mov    %rbx,%rdi
call   1050 <atoi@plt>
shl    $0x1e,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"MB\00"
@.str.1 = [3 x i8] c"GB\00"
@.str.2 = [2 x i8] c"B\00"
define i32 @parse_size_str(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 2
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %4, i64 %8
%10 = call i32 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
store i8 0, i8* %18
%19 = load i8*, i8** %3
%20 = call i32 @atoi(i8* %19)
%21 = mul nsw i32 %20, 1024
%22 = mul nsw i32 %21, 1024
store i32 %22, i32* %2
br label %65
23: ; preds = %1
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %44, label %32
32: ; preds = %23
%33 = load i8*, i8** %3
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %33, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %3
%40 = call i32 @atoi(i8* %39)
%41 = mul nsw i32 %40, 1024
%42 = mul nsw i32 %41, 1024
%43 = mul nsw i32 %42, 1024
store i32 %43, i32* %2
br label %65
44: ; preds = %23
%45 = load i8*, i8** %3
%46 = load i8*, i8** %3
%47 = call i32 @strlen(i8* %46)
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %45, i64 %49
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %60, label %53
53: ; preds = %44
%54 = load i8*, i8** %3
%55 = load i8*, i8** %3
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
store i8 0, i8* %59
br label %60
60: ; preds = %53, %44
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
%63 = load i8*, i8** %3
%64 = call i32 @atoi(i8* %63)
store i32 %64, i32* %2
br label %65
65: ; preds = %62, %32, %12
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [3 x i8] c"MB\00"
@.str.1 = [3 x i8] c"GB\00"
@.str.2 = [2 x i8] c"B\00"
define i32 @parse_size_str(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -2
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
%8 = tail call i32 @strlen(i8* %0)
%9 = add nsw i32 %8, -2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
br i1 %7, label %12, label %15
12: ; preds = %1
store i8 0, i8* %11
%13 = tail call i32 @atoi(i8* %0)
%14 = shl nsw i32 %13, 20
br label %38
15: ; preds = %1
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
%18 = tail call i32 @strlen(i8* %0)
br i1 %17, label %19, label %25
19: ; preds = %15
%20 = add nsw i32 %18, -3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 0, i8* %22
%23 = tail call i32 @atoi(i8* %0)
%24 = shl nsw i32 %23, 30
br label %38
25: ; preds = %15
%26 = add nsw i32 %18, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = tail call i32 @strlen(i8* %0)
%33 = add nsw i32 %32, -2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %31, %25
%37 = tail call i32 @atoi(i8* %0)
br label %38
38: ; preds = %36, %19, %12
%39 = phi i32 [ %37, %36 ], [ %24, %19 ], [ %14, %12 ]
ret i32 %39
}