#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 const *const, char *, long long *, ...);
long long int unit_atoll(const char *const str) {
  long long int x = 0;
  char unit[4];
  if (sscanf(str,
             "%lld"
             "%c",
             &x, unit) == 2) {
    switch ((int)unit[0]) {
    case 'k':
    case 'K':
      x *= 1024;
      break;
    case 'm':
    case 'M':
      x *= 1024;
      x *= 1024;
      break;
    case 'g':
    case 'G':
      x *= 1024;
      x *= 1024;
      x *= 1024;
      break;
    case 't':
    case 'T':
      x *= 1024;
      x *= 1024;
      x *= 1024;
      x *= 1024;
      break;
    }
  } else if (sscanf(str, "%lld", &x) != 1) {
    x = 0;
  }
  return (x);
}


x86 assembly (clang, -O0):
<unit_atoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rcx
lea    0xf85(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    11fd <unit_atoll+0xed>
movsbl -0x14(%rbp),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x2d,%eax
ja     11f8 <unit_atoll+0xe8>
mov    -0x20(%rbp),%rax
lea    0xe98(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11f8 <unit_atoll+0xe8>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11f8 <unit_atoll+0xe8>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11f8 <unit_atoll+0xe8>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    1229 <unit_atoll+0x119>
mov    -0x8(%rbp),%rdi
lea    0xeb7(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1224 <unit_atoll+0x114>
movq   $0x0,-0x10(%rbp)
jmp    1229 <unit_atoll+0x119>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_atoll>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,(%rsp)
lea    0xf91(%rip),%rsi
mov    %rsp,%rdx
lea    0xc(%rsp),%rcx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    115f <unit_atoll+0x4f>
movsbl 0xc(%rsp),%eax
add    $0xffffffb9,%eax
cmp    $0x2d,%eax
ja     1195 <unit_atoll+0x85>
lea    0xeb1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
shlq   $0x1e,(%rsp)
jmp    1195 <unit_atoll+0x85>
lea    0xf59(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1195 <unit_atoll+0x85>
movq   $0x0,(%rsp)
jmp    1195 <unit_atoll+0x85>
shlq   $0x14,(%rsp)
jmp    1195 <unit_atoll+0x85>
shlq   $0x28,(%rsp)
jmp    1195 <unit_atoll+0x85>
shlq   $0xa,(%rsp)
mov    (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%lld%c\00"
@.str.1 = [5 x i8] c"%lld\00"
define i64 @unit_atoll(i8* nocapture %0) {
%2 = alloca i64
%3 = alloca [4 x i8]
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, i8*, i64*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64* %2, i8* %5)
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %23
8: ; preds = %1
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
switch i32 %10, label %27 [
i32 107, label %11
i32 75, label %11
i32 109, label %14
i32 77, label %14
i32 103, label %17
i32 71, label %17
i32 116, label %20
i32 84, label %20
]
11: ; preds = %8, %8
%12 = load i64, i64* %2
%13 = shl nsw i64 %12, 10
store i64 %13, i64* %2
br label %27
14: ; preds = %8, %8
%15 = load i64, i64* %2
%16 = shl nsw i64 %15, 20
store i64 %16, i64* %2
br label %27
17: ; preds = %8, %8
%18 = load i64, i64* %2
%19 = shl nsw i64 %18, 30
store i64 %19, i64* %2
br label %27
20: ; preds = %8, %8
%21 = load i64, i64* %2
%22 = shl nsw i64 %21, 40
store i64 %22, i64* %2
br label %27
23: ; preds = %1
%24 = call i32 (i8*, i8*, i64*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%25 = icmp eq i32 %24, 1
br i1 %25, label %27, label %26
26: ; preds = %23
store i64 0, i64* %2
br label %27
27: ; preds = %23, %26, %11, %14, %17, %20, %8
%28 = load i64, i64* %2
ret i64 %28
}