#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 /*<<< orphan*/ digits;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
char *strstr(char *, char *);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
unsigned long long resolv_number(char *notation, char **endptr) {
  unsigned long long number, unit;
  char digits[64];
  unsigned long digit;
  int len;
  char *p;
  snprintf(digits, sizeof(digits), "%s", notation);
  len = strlen(digits);
  unit = 1;
  if (len > 3) {
    p = strstr(digits, "KiB");
    if (!p)
      p = strstr(digits, "MiB");
    if (!p)
      p = strstr(digits, "GiB");
    if (!p)
      p = strstr(digits, "TiB");
    if (p) {
      switch (*p) {
      case 'K':
        unit = 1024ULL;
        break;
      case 'M':
        unit = 1024ULL * 1024ULL;
        break;
      case 'G':
        unit = 1024ULL * 1024ULL * 1024ULL;
        break;
      case 'T':
        unit = 1024ULL * 1024ULL * 1024ULL * 1024ULL;
        break;
      default:
        unit = 1ULL;
        break;
      }
      *p = '\0';
      len = strlen(digits);
    }
  }
  if (len > 1) {
    switch (digits[len - 1]) {
    case 'k':
    case 'K':
      unit = 1000ULL;
      digits[len - 1] = '\0';
      break;
    case 'm':
    case 'M':
      unit = 1000ULL * 1000ULL;
      digits[len - 1] = '\0';
      break;
    case 'g':
    case 'G':
      unit = 1000ULL * 1000ULL * 1000ULL;
      digits[len - 1] = '\0';
      break;
    case 'T':
      unit = 1000ULL * 1000ULL * 1000ULL * 1000ULL;
      digits[len - 1] = '\0';
      break;
    case 'P':
      unit = 1000ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL;
      digits[len - 1] = '\0';
      break;
    default:
      break;
    }
  }
  digit = strtoul(digits, endptr, 0);
  number = digit * unit;
  return number;
}


x86 assembly (clang, -O0):
<resolv_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x40,%esi
lea    0xf6d(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x6c(%rbp)
movq   $0x1,-0x20(%rbp)
cmpl   $0x3,-0x6c(%rbp)
jle    128d <resolv_number+0x14d>
lea    -0x60(%rbp),%rdi
lea    0xf42(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11bd <resolv_number+0x7d>
lea    -0x60(%rbp),%rdi
lea    0xf27(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11dc <resolv_number+0x9c>
lea    -0x60(%rbp),%rdi
lea    0xf0c(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11fb <resolv_number+0xbb>
lea    -0x60(%rbp),%rdi
lea    0xef1(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1288 <resolv_number+0x148>
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x80(%rbp)
sub    $0xd,%eax
ja     126d <resolv_number+0x12d>
mov    -0x80(%rbp),%rax
lea    0xdd6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x400,-0x20(%rbp)
jmp    1275 <resolv_number+0x135>
movq   $0x100000,-0x20(%rbp)
jmp    1275 <resolv_number+0x135>
movq   $0x40000000,-0x20(%rbp)
40
jmp    1275 <resolv_number+0x135>
movabs $0x10000000000,%rax
mov    %rax,-0x20(%rbp)
jmp    1275 <resolv_number+0x135>
movq   $0x1,-0x20(%rbp)
mov    -0x78(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x6c(%rbp)
jmp    128d <resolv_number+0x14d>
cmpl   $0x1,-0x6c(%rbp)
jle    1368 <resolv_number+0x228>
mov    -0x6c(%rbp),%eax
add    $0xffffffff,%eax
cltq
movsbl -0x60(%rbp,%rax,1),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x88(%rbp)
sub    $0x26,%eax
ja     135e <resolv_number+0x21e>
mov    -0x88(%rbp),%rax
lea    0xd71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x3e8,-0x20(%rbp)
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1363 <resolv_number+0x223>
movq   $0xf4240,-0x20(%rbp)
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1363 <resolv_number+0x223>
movq   $0x3b9aca00,-0x20(%rbp)
3b
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1363 <resolv_number+0x223>
movabs $0xe8d4a51000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1363 <resolv_number+0x223>
movabs $0x38d7ea4c68000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1363 <resolv_number+0x223>
jmp    1363 <resolv_number+0x223>
jmp    1368 <resolv_number+0x228>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolv_number>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
lea    0xf7e(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    $0x1,%r15d
cmp    $0x4,%eax
jl     1223 <resolv_number+0xe3>
lea    0xf51(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11d3 <resolv_number+0x93>
lea    0xf41(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11d3 <resolv_number+0x93>
lea    0xf31(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11d3 <resolv_number+0x93>
lea    0xf21(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1292 <resolv_number+0x152>
movsbl (%rax),%ecx
add    $0xffffffb9,%ecx
cmp    $0xd,%ecx
ja     11fc <resolv_number+0xbc>
mov    $0x400,%r15d
lea    0xe15(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x40000000,%r15d
jmp    1216 <resolv_number+0xd6>
mov    $0x1,%r15d
jmp    1216 <resolv_number+0xd6>
mov    $0x100000,%r15d
jmp    1216 <resolv_number+0xd6>
movabs $0x10000000000,%r15
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
cmp    $0x2,%ebx
jl     1277 <resolv_number+0x137>
add    $0xffffffff,%ebx
movsbl (%rsp,%rbx,1),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     1277 <resolv_number+0x137>
mov    $0x3e8,%eax
lea    0xdf5(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x3b9aca00,%eax
jmp    1270 <resolv_number+0x130>
mov    $0xf4240,%eax
jmp    1270 <resolv_number+0x130>
movabs $0x38d7ea4c68000,%rax
jmp    1270 <resolv_number+0x130>
movabs $0xe8d4a51000,%rax
movb   $0x0,(%rsp,%rbx,1)
mov    %rax,%r15
mov    %rsp,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
imul   %r15,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%r15d
jmp    1228 <resolv_number+0xe8>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"KiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@.str.3 = [4 x i8] c"GiB\00"
@.str.4 = [4 x i8] c"TiB\00"
define i64 @resolv_number(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
%7 = alloca [64 x i8]
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @snprintf(i8* %11, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %9
store i64 1, i64* %6
%16 = load i32, i32* %9
%17 = icmp sgt i32 %16, 3
br i1 %17, label %18, label %55
18: ; preds = %2
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%20 = call i8* @strstr(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %10
%21 = load i8*, i8** %10
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %10
br label %26
26: ; preds = %23, %18
%27 = load i8*, i8** %10
%28 = icmp ne i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%31 = call i8* @strstr(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %31, i8** %10
br label %32
32: ; preds = %29, %26
%33 = load i8*, i8** %10
%34 = icmp ne i8* %33, null
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i8* %37, i8** %10
br label %38
38: ; preds = %35, %32
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %54
41: ; preds = %38
%42 = load i8*, i8** %10
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
switch i32 %44, label %49 [
i32 75, label %45
i32 77, label %46
i32 71, label %47
i32 84, label %48
]
45: ; preds = %41
store i64 1024, i64* %6
br label %50
46: ; preds = %41
store i64 1048576, i64* %6
br label %50
47: ; preds = %41
store i64 1073741824, i64* %6
br label %50
48: ; preds = %41
store i64 1099511627776, i64* %6
br label %50
49: ; preds = %41
store i64 1, i64* %6
br label %50
50: ; preds = %49, %48, %47, %46, %45
%51 = load i8*, i8** %10
store i8 0, i8* %51
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
store i32 %53, i32* %9
br label %54
54: ; preds = %50, %38
br label %55
55: ; preds = %54, %2
%56 = load i32, i32* %9
%57 = icmp sgt i32 %56, 1
br i1 %57, label %58, label %92
58: ; preds = %55
%59 = load i32, i32* %9
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
switch i32 %64, label %90 [
i32 107, label %65
i32 75, label %65
i32 109, label %70
i32 77, label %70
i32 103, label %75
i32 71, label %75
i32 84, label %80
i32 80, label %85
]
65: ; preds = %58, %58
store i64 1000, i64* %6
%66 = load i32, i32* %9
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %68
store i8 0, i8* %69
br label %91
70: ; preds = %58, %58
store i64 1000000, i64* %6
%71 = load i32, i32* %9
%72 = sub nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %73
store i8 0, i8* %74
br label %91
75: ; preds = %58, %58
store i64 1000000000, i64* %6
%76 = load i32, i32* %9
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %78
store i8 0, i8* %79
br label %91
80: ; preds = %58
store i64 1000000000000, i64* %6
%81 = load i32, i32* %9
%82 = sub nsw i32 %81, 1
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %83
store i8 0, i8* %84
br label %91
85: ; preds = %58
store i64 1000000000000000, i64* %6
%86 = load i32, i32* %9
%87 = sub nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %88
store i8 0, i8* %89
br label %91
90: ; preds = %58
br label %91
91: ; preds = %90, %85, %80, %75, %70, %65
br label %92
92: ; preds = %91, %55
%93 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%94 = load i8**, i8*** %4
%95 = call i64 @strtoul(i8* %93, i8** %94, i32 0)
store i64 %95, i64* %8
%96 = load i64, i64* %8
%97 = load i64, i64* %6
%98 = mul i64 %96, %97
store i64 %98, i64* %5
%99 = load i64, i64* %5
ret i64 %99
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"KiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@.str.3 = [4 x i8] c"GiB\00"
@.str.4 = [4 x i8] c"TiB\00"
define i64 @resolv_number(i8* %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32 @strlen(i8* %4)
%7 = icmp sgt i32 %6, 3
br i1 %7, label %8, label %31
8: ; preds = %2
%9 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %35, label %20
20: ; preds = %8, %11, %14, %17
%21 = phi i8* [ %18, %17 ], [ %15, %14 ], [ %12, %11 ], [ %9, %8 ]
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %27 [
i32 75, label %28
i32 77, label %24
i32 71, label %25
i32 84, label %26
]
24: ; preds = %20
br label %28
25: ; preds = %20
br label %28
26: ; preds = %20
br label %28
27: ; preds = %20
br label %28
28: ; preds = %20, %27, %26, %25, %24
%29 = phi i64 [ 1, %27 ], [ 1099511627776, %26 ], [ 1073741824, %25 ], [ 1048576, %24 ], [ 1024, %20 ]
store i8 0, i8* %21
%30 = call i32 @strlen(i8* %4)
br label %31
31: ; preds = %28, %2
%32 = phi i64 [ %29, %28 ], [ 1, %2 ]
%33 = phi i32 [ %30, %28 ], [ %6, %2 ]
%34 = icmp sgt i32 %33, 1
br i1 %34, label %35, label %49
35: ; preds = %17, %31
%36 = phi i32 [ %33, %31 ], [ %6, %17 ]
%37 = phi i64 [ %32, %31 ], [ 1, %17 ]
%38 = add nsw i32 %36, -1
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
switch i32 %42, label %49 [
i32 107, label %47
i32 75, label %47
i32 109, label %43
i32 77, label %43
i32 103, label %44
i32 71, label %44
i32 84, label %45
i32 80, label %46
]
43: ; preds = %35, %35
br label %47
44: ; preds = %35, %35
br label %47
45: ; preds = %35
br label %47
46: ; preds = %35
br label %47
47: ; preds = %35, %35, %46, %45, %44, %43
%48 = phi i64 [ 1000000, %43 ], [ 1000000000, %44 ], [ 1000000000000, %45 ], [ 1000000000000000, %46 ], [ 1000, %35 ], [ 1000, %35 ]
store i8 0, i8* %40
br label %49
49: ; preds = %47, %35, %31
%50 = phi i64 [ %37, %35 ], [ %32, %31 ], [ %48, %47 ]
%51 = call i64 @strtoul(i8* %4, i8** %1, i32 0)
%52 = mul i64 %51, %50
ret i64 %52
}