#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 atoll(char *);
int strlen(char *);
char tolower(char);
uint64_t parse_bytes(char *tar) {
  if (tar == NULL || strlen(tar) == 0 || tar[0] < '0' || tar[0] > '9') {
    return 0;
  }
  uint64_t number = atoll(tar);
  if (number == 0) {
    return 0;
  }
  char unit = tar[strlen(tar) - 1];
  if (tolower(unit) == 'm') {
    return number * 1024 * 1024;
  } else if (tolower(unit) == 'k') {
    return number * 1024;
  } else if (tolower(unit) == 'b') {
    return number;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<parse_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1179 <parse_bytes+0x49>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     1179 <parse_bytes+0x49>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1179 <parse_bytes+0x49>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1185 <parse_bytes+0x55>
movl   $0x0,-0x4(%rbp)
jmp    123a <parse_bytes+0x10a>
mov    -0x10(%rbp),%rdi
call   1040 <atoll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a7 <parse_bytes+0x77>
movl   $0x0,-0x4(%rbp)
jmp    123a <parse_bytes+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <tolower@plt>
movsbl %al,%eax
cmp    $0x6d,%eax
jne    11f0 <parse_bytes+0xc0>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    123a <parse_bytes+0x10a>
movsbl -0x15(%rbp),%edi
call   1050 <tolower@plt>
movsbl %al,%eax
cmp    $0x6b,%eax
jne    1213 <parse_bytes+0xe3>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    123a <parse_bytes+0x10a>
movsbl -0x15(%rbp),%edi
call   1050 <tolower@plt>
movsbl %al,%eax
cmp    $0x62,%eax
jne    1233 <parse_bytes+0x103>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <parse_bytes+0x10a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_bytes>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     11a5 <parse_bytes+0x75>
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
je     11a5 <parse_bytes+0x75>
mov    0x0(%rbp),%al
add    $0xc6,%al
cmp    $0xf6,%al
jb     11a5 <parse_bytes+0x75>
mov    %rbp,%rdi
call   1040 <atoll@plt>
test   %eax,%eax
je     11a5 <parse_bytes+0x75>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbp,1),%ebx
mov    %ebx,%edi
call   1050 <tolower@plt>
cmp    $0x6d,%al
jne    1182 <parse_bytes+0x52>
shl    $0x14,%r14d
mov    %r14d,%ebx
jmp    11a5 <parse_bytes+0x75>
mov    %ebx,%edi
call   1050 <tolower@plt>
cmp    $0x6b,%al
jne    1196 <parse_bytes+0x66>
shl    $0xa,%r14d
mov    %r14d,%ebx
jmp    11a5 <parse_bytes+0x75>
mov    %ebx,%edi
call   1050 <tolower@plt>
xor    %ebx,%ebx
cmp    $0x62,%al
cmove  %r14d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_bytes(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %24, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp slt i32 %16, 48
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp sgt i32 %22, 57
br i1 %23, label %24, label %25
24: ; preds = %18, %12, %8, %1
store i32 0, i32* %2
br label %63
25: ; preds = %18
%26 = load i8*, i8** %3
%27 = call i32 @atoll(i8* %26)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %2
br label %63
31: ; preds = %25
%32 = load i8*, i8** %3
%33 = load i8*, i8** %3
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %32, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %5
%39 = load i8, i8* %5
%40 = call signext i8 @tolower(i8 signext %39)
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 109
br i1 %42, label %43, label %47
43: ; preds = %31
%44 = load i32, i32* %4
%45 = mul nsw i32 %44, 1024
%46 = mul nsw i32 %45, 1024
store i32 %46, i32* %2
br label %63
47: ; preds = %31
%48 = load i8, i8* %5
%49 = call signext i8 @tolower(i8 signext %48)
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 107
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* %4
%54 = mul nsw i32 %53, 1024
store i32 %54, i32* %2
br label %63
55: ; preds = %47
%56 = load i8, i8* %5
%57 = call signext i8 @tolower(i8 signext %56)
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 98
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = load i32, i32* %4
store i32 %61, i32* %2
br label %63
62: ; preds = %55
store i32 0, i32* %2
br label %63
63: ; preds = %62, %60, %52, %43, %30, %24
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
define i32 @parse_bytes(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %32, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %32, label %6
6: ; preds = %3
%7 = load i8, i8* %0
%8 = add i8 %7, -58
%9 = icmp ult i8 %8, -10
br i1 %9, label %32, label %10
10: ; preds = %6
%11 = tail call i32 @atoll(i8* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %32, label %13
13: ; preds = %10
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call signext i8 @tolower(i8 signext %18)
%20 = icmp eq i8 %19, 109
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = shl nsw i32 %11, 20
br label %32
23: ; preds = %13
%24 = tail call signext i8 @tolower(i8 signext %18)
%25 = icmp eq i8 %24, 107
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = shl nsw i32 %11, 10
br label %32
28: ; preds = %23
%29 = tail call signext i8 @tolower(i8 signext %18)
%30 = icmp eq i8 %29, 98
%31 = select i1 %30, i32 %11, i32 0
br label %32
32: ; preds = %10, %28, %26, %21, %1, %3, %6
%33 = phi i32 [ 0, %6 ], [ 0, %3 ], [ 0, %1 ], [ 0, %10 ], [ %22, %21 ], [ %27, %26 ], [ %31, %28 ]
ret i32 %33
}