#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*/ assert(int /*<<< orphan*/);
size_t strtoul(char *, char **, int);
size_t read_size(char *arg) {
  size_t value;
  char *p;
  assert(arg != NULL);
  value = strtoul(arg, &p, 10);
  switch (*p) {
  case 'k':
    value *= 1024uL;
    break;
  case 'm':
    value *= (1024uL * 1024uL);
    break;
  case 'g':
    value *= (1024uL * 1024uL * 1024uL);
    break;
  case 'b':
  default:
    break;
  }
  return value;
}


x86 assembly (clang, -O0):
<read_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xb,%eax
ja     11b9 <read_size+0x99>
mov    -0x20(%rbp),%rax
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11be <read_size+0x9e>
mov    -0x10(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x10(%rbp)
jmp    11be <read_size+0x9e>
mov    -0x10(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x10(%rbp)
jmp    11be <read_size+0x9e>
jmp    11b9 <read_size+0x99>
jmp    11be <read_size+0x9e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_size>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    0x8(%rsp),%rcx
movsbl (%rcx),%ecx
cmp    $0x67,%ecx
je     1165 <read_size+0x45>
cmp    $0x6d,%ecx
je     116b <read_size+0x4b>
cmp    $0x6b,%ecx
jne    116f <read_size+0x4f>
shl    $0xa,%rax
jmp    116f <read_size+0x4f>
shl    $0x1e,%rax
jmp    116f <read_size+0x4f>
shl    $0x14,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @read_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %2
%10 = call i64 @strtoul(i8* %9, i8** %4, i32 10)
store i64 %10, i64* %3
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %24 [
i32 107, label %14
i32 109, label %17
i32 103, label %20
i32 98, label %23
]
14: ; preds = %1
%15 = load i64, i64* %3
%16 = mul i64 %15, 1024
store i64 %16, i64* %3
br label %25
17: ; preds = %1
%18 = load i64, i64* %3
%19 = mul i64 %18, 1048576
store i64 %19, i64* %3
br label %25
20: ; preds = %1
%21 = load i64, i64* %3
%22 = mul i64 %21, 1073741824
store i64 %22, i64* %3
br label %25
23: ; preds = %1
br label %24
24: ; preds = %1, %23
br label %25
25: ; preds = %24, %20, %17, %14
%26 = load i64, i64* %3
ret i64 %26
}

LLVM IR (-O2):
define i64 @read_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = call i64 @strtoul(i8* %0, i8** %2, i32 10)
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %17 [
i32 107, label %11
i32 109, label %13
i32 103, label %15
]
11: ; preds = %1
%12 = shl i64 %7, 10
br label %17
13: ; preds = %1
%14 = shl i64 %7, 20
br label %17
15: ; preds = %1
%16 = shl i64 %7, 30
br label %17
17: ; preds = %1, %15, %13, %11
%18 = phi i64 [ %7, %1 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ]
ret i64 %18
}