#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 unsigned long long uint64_t;

/* Variables and functions */
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, ...);
unsigned long long strtoull(char const *, char **, int /*<<< orphan*/);
uint64_t grok_size(const char *str, const char *option) {
  uint64_t xxbase = 0, xxmult = 1, xxval = 0;
  char *xxend = 0;
  xxbase = strtoull(str, &xxend, 0);
  if (xxend && *xxend) {
    switch (*xxend) {
    case 'b':
    case 'B':
      break;
    case 'k':
    case 'K':
      xxmult = 1024ULL;
      break;
    case 'M':
      xxmult = (1024ULL * 1024);
      break;
    case 'G':
      xxmult = ((1024ULL * 1024) * 1024);
      break;
    case 'T':
      xxmult = (((1024ULL * 1024) * 1024) * 1024);
      break;
    case 'P':
      xxmult = ((((1024ULL * 1024) * 1024) * 1024) * 1024);
      break;
    default:
      error(1, 0, "unknown multilplier constant '%c'  for '%s'", *xxend,
            option);
      break;
    }
    xxval = xxbase * xxmult;
    if ((xxbase == 18446744073709551615ULL && errno == ERANGE) ||
        (xxval < xxbase)) {
      error(1, 0, "size value overflow for '%s' (base %lu, multiplier %lu)",
            option, xxbase, xxmult);
    }
  } else
    xxval = xxbase;
  return xxval;
}


x86 assembly (clang, -O0):
<grok_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1283 <grok_size+0x163>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1283 <grok_size+0x163>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x29,%eax
ja     11fd <grok_size+0xdd>
mov    -0x38(%rbp),%rax
lea    0xe5e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    121d <grok_size+0xfd>
movq   $0x400,-0x20(%rbp)
jmp    121d <grok_size+0xfd>
movq   $0x100000,-0x20(%rbp)
jmp    121d <grok_size+0xfd>
movq   $0x40000000,-0x20(%rbp)
40
jmp    121d <grok_size+0xfd>
movabs $0x10000000000,%rax
mov    %rax,-0x20(%rbp)
jmp    121d <grok_size+0xfd>
movabs $0x4000000000000,%rax
mov    %rax,-0x20(%rbp)
jmp    121d <grok_size+0xfd>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x10(%rbp),%r8
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe92(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    124f <grok_size+0x12f>
mov    0x2d9c(%rip),%rax
mov    (%rax),%rax
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%rax
je     125d <grok_size+0x13d>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    127e <grok_size+0x15e>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe5d(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
jmp    128b <grok_size+0x16b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grok_size>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
movq   $0x0,(%rsp)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,%r12
mov    (%rsp),%rax
test   %rax,%rax
je     1176 <grok_size+0x56>
movsbl (%rax),%ecx
test   %ecx,%ecx
je     1176 <grok_size+0x56>
mov    $0x1,%r15d
lea    -0x42(%rcx),%eax
cmp    $0x29,%eax
ja     117e <grok_size+0x5e>
lea    0xe9b(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    $0x400,%r15d
jmp    11be <grok_size+0x9e>
mov    %r12,%rax
jmp    1216 <grok_size+0xf6>
lea    0xf23(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
mov    %r14,%r8
xor    %eax,%eax
call   1040 <error@plt>
jmp    11be <grok_size+0x9e>
mov    $0x40000000,%r15d
jmp    11be <grok_size+0x9e>
mov    $0x100000,%r15d
jmp    11be <grok_size+0x9e>
movabs $0x4000000000000,%r15
jmp    11be <grok_size+0x9e>
movabs $0x10000000000,%r15
mov    %r15,%rbx
imul   %r12,%rbx
cmp    $0xffffffffffffffff,%r12
je     11d2 <grok_size+0xb2>
cmp    %r12,%rbx
jb     11f5 <grok_size+0xd5>
jmp    1213 <grok_size+0xf3>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
je     11f5 <grok_size+0xd5>
mov    $0xffffffffffffffff,%rax
cmp    $0xffffffffffffffff,%rbx
je     1216 <grok_size+0xf6>
lea    0xed8(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
mov    %r14,%rcx
mov    %r12,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1040 <error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [44 x i8] c"unknown multilplier constant '%c' for '%s'\00"
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [56 x i8] c"size value overflow for '%s' (base %lu, multiplier %lu)\00"
define i64 @grok_size(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %5
store i64 1, i64* %6
store i64 0, i64* %7
store i8* null, i8** %8
%9 = load i8*, i8** %3
%10 = call i64 @strtoull(i8* %9, i8** %8, i32 0)
store i64 %10, i64* %5
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %54
13: ; preds = %2
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %54
18: ; preds = %13
%19 = load i8*, i8** %8
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %28 [
i32 98, label %22
i32 66, label %22
i32 107, label %23
i32 75, label %23
i32 77, label %24
i32 71, label %25
i32 84, label %26
i32 80, label %27
]
22: ; preds = %18, %18
br label %34
23: ; preds = %18, %18
store i64 1024, i64* %6
br label %34
24: ; preds = %18
store i64 1048576, i64* %6
br label %34
25: ; preds = %18
store i64 1073741824, i64* %6
br label %34
26: ; preds = %18
store i64 1099511627776, i64* %6
br label %34
27: ; preds = %18
store i64 1125899906842624, i64* %6
br label %34
28: ; preds = %18
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = load i8*, i8** %4
%33 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %31, i8* %32)
br label %34
34: ; preds = %28, %27, %26, %25, %24, %23, %22
%35 = load i64, i64* %5
%36 = load i64, i64* %6
%37 = mul i64 %35, %36
store i64 %37, i64* %7
%38 = load i64, i64* %5
%39 = icmp eq i64 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i64, i64* @errno
%42 = load i64, i64* @ERANGE
%43 = icmp eq i64 %41, %42
br i1 %43, label %48, label %44
44: ; preds = %40, %34
%45 = load i64, i64* %7
%46 = load i64, i64* %5
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %44, %40
%49 = load i8*, i8** %4
%50 = load i64, i64* %5
%51 = load i64, i64* %6
%52 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %49, i64 %50, i64 %51)
br label %53
53: ; preds = %48, %44
br label %56
54: ; preds = %13, %2
%55 = load i64, i64* %5
store i64 %55, i64* %7
br label %56
56: ; preds = %54, %53
%57 = load i64, i64* %7
ret i64 %57
}

LLVM IR (-O2):
@.str = [44 x i8] c"unknown multilplier constant '%c' for '%s'\00"
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [56 x i8] c"size value overflow for '%s' (base %lu, multiplier %lu)\00"
define i64 @grok_size(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i64 @strtoull(i8* %0, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = icmp eq i8 %9, 0
br i1 %11, label %34, label %12
12: ; preds = %8
switch i32 %10, label %18 [
i32 98, label %20
i32 66, label %20
i32 107, label %13
i32 75, label %13
i32 77, label %14
i32 71, label %15
i32 84, label %16
i32 80, label %17
]
13: ; preds = %12, %12
br label %20
14: ; preds = %12
br label %20
15: ; preds = %12
br label %20
16: ; preds = %12
br label %20
17: ; preds = %12
br label %20
18: ; preds = %12
%19 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %1)
br label %20
20: ; preds = %12, %12, %18, %17, %16, %15, %14, %13
%21 = phi i64 [ 1, %18 ], [ 1125899906842624, %17 ], [ 1099511627776, %16 ], [ 1073741824, %15 ], [ 1048576, %14 ], [ 1024, %13 ], [ 1, %12 ], [ 1, %12 ]
%22 = mul i64 %21, %5
%23 = icmp eq i64 %5, -1
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = load i64, i64* @ERANGE
%27 = icmp eq i64 %25, %26
%28 = icmp ne i64 %22, -1
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %32, label %34
30: ; preds = %20
%31 = icmp ult i64 %22, %5
br i1 %31, label %32, label %34
32: ; preds = %30, %24
%33 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %1, i64 %5, i64 %21)
br label %34
34: ; preds = %2, %8, %24, %30, %32
%35 = phi i64 [ %22, %32 ], [ %22, %30 ], [ -1, %24 ], [ %5, %8 ], [ %5, %2 ]
ret i64 %35
}