#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
size_t strtoull(char *, char **, int);
size_t strtosize(char *str) {
  size_t size;
  char *unit;
  size = strtoull(str, &unit, 10);
  switch (*unit) {
  case 'b':
  case 'B':
  case '\0':
    break;
  case 'k':
  case 'K':
    size *= 1024;
    break;
  case 'm':
  case 'M':
    size *= 1048576L;
    break;
  case 'g':
  case 'G':
    size *= 1073741824L;
    break;
  default:
    do {
      fprintf(stderr, "memleak: Unknown unit: %s", unit);
      exit(EXIT_FAILURE);
    } while (0);
  }
  return size;
}


x86 assembly (clang, -O0):
<strtosize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11f1 <strtosize+0xc1>
jmp    1169 <strtosize+0x39>
mov    -0x1c(%rbp),%eax
sub    $0x42,%eax
je     11f1 <strtosize+0xc1>
jmp    117a <strtosize+0x4a>
mov    -0x1c(%rbp),%eax
sub    $0x47,%eax
je     1218 <strtosize+0xe8>
jmp    118b <strtosize+0x5b>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     11f6 <strtosize+0xc6>
jmp    119c <strtosize+0x6c>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     1207 <strtosize+0xd7>
jmp    11ad <strtosize+0x7d>
mov    -0x1c(%rbp),%eax
sub    $0x62,%eax
je     11f1 <strtosize+0xc1>
jmp    11be <strtosize+0x8e>
mov    -0x1c(%rbp),%eax
sub    $0x67,%eax
je     1218 <strtosize+0xe8>
jmp    11cf <strtosize+0x9f>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     11f6 <strtosize+0xc6>
jmp    11e0 <strtosize+0xb0>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
je     1207 <strtosize+0xd7>
jmp    1229 <strtosize+0xf9>
jmp    1255 <strtosize+0x125>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    1255 <strtosize+0x125>
mov    -0x10(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x10(%rbp)
jmp    1255 <strtosize+0x125>
mov    -0x10(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x10(%rbp)
jmp    1255 <strtosize+0x125>
jmp    122e <strtosize+0xfe>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdbe(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtosize>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    (%rsp),%rdx
movsbl (%rdx),%esi
lea    -0x42(%rsi),%ecx
cmp    $0x2b,%ecx
ja     116f <strtosize+0x3f>
lea    0xeac(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
shl    $0x1e,%rax
pop    %rcx
ret
shl    $0xa,%rax
jmp    1173 <strtosize+0x43>
shl    $0x14,%rax
pop    %rcx
ret
test   %esi,%esi
jne    1175 <strtosize+0x45>
pop    %rcx
ret
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xf2b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"memleak: Unknown unit: %s\00"
@EXIT_FAILURE = global i32 0
define i64 @strtosize(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtoull(i8* %5, i8** %4, i32 10)
store i64 %6, i64* %3
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %20 [
i32 98, label %10
i32 66, label %10
i32 0, label %10
i32 107, label %11
i32 75, label %11
i32 109, label %14
i32 77, label %14
i32 103, label %17
i32 71, label %17
]
10: ; preds = %1, %1, %1
br label %28
11: ; preds = %1, %1
%12 = load i64, i64* %3
%13 = mul i64 %12, 1024
store i64 %13, i64* %3
br label %28
14: ; preds = %1, %1
%15 = load i64, i64* %3
%16 = mul i64 %15, 1048576
store i64 %16, i64* %3
br label %28
17: ; preds = %1, %1
%18 = load i64, i64* %3
%19 = mul i64 %18, 1073741824
store i64 %19, i64* %3
br label %28
20: ; preds = %1
br label %21
21: ; preds = %20
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %4
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; No predecessors!
br label %28
28: ; preds = %27, %17, %14, %11, %10
%29 = load i64, i64* %3
ret i64 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"memleak: Unknown unit: %s\00"
@EXIT_FAILURE = global i32 0
define i64 @strtosize(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoull(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %14 [
i32 98, label %19
i32 66, label %19
i32 0, label %19
i32 107, label %8
i32 75, label %8
i32 109, label %10
i32 77, label %10
i32 103, label %12
i32 71, label %12
]
8: ; preds = %1, %1
%9 = shl i64 %4, 10
br label %19
10: ; preds = %1, %1
%11 = shl i64 %4, 20
br label %19
12: ; preds = %1, %1
%13 = shl i64 %4, 30
br label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %5)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %1, %1, %1, %12, %10, %8
%20 = phi i64 [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %4, %1 ], [ %4, %1 ], [ %4, %1 ]
ret i64 %20
}