#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*/ err(int, char *, char const *);
unsigned long strtol(char const *, char **, int /*<<< orphan*/);
unsigned long parse_size(const char *arg) {
  unsigned long mult = 1, ret;
  char *s;
  ret = strtol(arg, &s, 0);
  switch (*s++) {
  case 'g':
  case 'G':
    mult = 1024 * 1024 * 1024;
    break;
  case 'm':
  case 'M':
    mult = 1024 * 1024;
    break;
  case 'k':
  case 'K':
    mult = 1024;
    break;
  case '\0':
    return ret;
  default:
  bad:
    err(1, "parse_size: unknown unit in \"%s\"\n", arg);
  }
  if (*s != '\0')
    goto bad;
  return mult * ret;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     11f6 <parse_size+0xd6>
jmp    1169 <parse_size+0x49>
mov    -0x2c(%rbp),%eax
sub    $0x47,%eax
je     11cf <parse_size+0xaf>
jmp    117a <parse_size+0x5a>
mov    -0x2c(%rbp),%eax
sub    $0x4b,%eax
je     11e9 <parse_size+0xc9>
jmp    118b <parse_size+0x6b>
mov    -0x2c(%rbp),%eax
sub    $0x4d,%eax
je     11dc <parse_size+0xbc>
jmp    119c <parse_size+0x7c>
mov    -0x2c(%rbp),%eax
sub    $0x67,%eax
je     11cf <parse_size+0xaf>
jmp    11ad <parse_size+0x8d>
mov    -0x2c(%rbp),%eax
sub    $0x6b,%eax
je     11e9 <parse_size+0xc9>
jmp    11be <parse_size+0x9e>
mov    -0x2c(%rbp),%eax
sub    $0x6d,%eax
je     11dc <parse_size+0xbc>
jmp    1203 <parse_size+0xe3>
movq   $0x40000000,-0x18(%rbp)
40
jmp    121d <parse_size+0xfd>
movq   $0x100000,-0x18(%rbp)
jmp    121d <parse_size+0xfd>
movq   $0x400,-0x18(%rbp)
jmp    121d <parse_size+0xfd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123f <parse_size+0x11f>
jmp    1208 <parse_size+0xe8>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xde8(%rip),%rsi
call   1040 <err@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1232 <parse_size+0x112>
jmp    1208 <parse_size+0xe8>
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,%r14
mov    (%rsp),%r12
movsbl (%r12),%ecx
mov    $0x40000000,%eax
mov    $0x1,%ebx
lea    -0x47(%rcx),%edx
cmp    $0x26,%edx
ja     1191 <parse_size+0x71>
movabs $0x100000001,%rsi
bt     %rdx,%rsi
jb     11ac <parse_size+0x8c>
movabs $0x1000000010,%rax
bt     %rdx,%rax
jb     118a <parse_size+0x6a>
movabs $0x4000000040,%rax
bt     %rdx,%rax
jae    1191 <parse_size+0x71>
mov    $0x100000,%eax
jmp    11ac <parse_size+0x8c>
mov    $0x400,%eax
jmp    11ac <parse_size+0x8c>
test   %ecx,%ecx
je     11bd <parse_size+0x9d>
lea    0xe64(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
call   1040 <err@plt>
mov    %rbx,%rax
cmpb   $0x0,0x1(%r12)
je     11b9 <parse_size+0x99>
mov    %rax,%rbx
jmp    1195 <parse_size+0x75>
imul   %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"parse_size: unknown unit in \22%s\22\0A\00"
define i64 @parse_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i64 1, i64* %4
%7 = load i8*, i8** %3
%8 = call i64 @strtol(i8* %7, i8** %6, i32 0)
store i64 %8, i64* %5
%9 = load i8*, i8** %6
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %6
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
switch i32 %12, label %18 [
i32 103, label %13
i32 71, label %13
i32 109, label %14
i32 77, label %14
i32 107, label %15
i32 75, label %15
i32 0, label %16
]
13: ; preds = %1, %1
store i64 1073741824, i64* %4
br label %22
14: ; preds = %1, %1
store i64 1048576, i64* %4
br label %22
15: ; preds = %1, %1
store i64 1024, i64* %4
br label %22
16: ; preds = %1
%17 = load i64, i64* %5
store i64 %17, i64* %2
br label %32
18: ; preds = %1
br label %19
19: ; preds = %27, %18
%20 = load i8*, i8** %3
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %15, %14, %13
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
br label %19
28: ; preds = %22
%29 = load i64, i64* %4
%30 = load i64, i64* %5
%31 = mul i64 %29, %30
store i64 %31, i64* %2
br label %32
32: ; preds = %28, %16
%33 = load i64, i64* %2
ret i64 %33
}

LLVM IR (-O2):
@.str = [34 x i8] c"parse_size: unknown unit in \22%s\22\0A\00"
define i64 @parse_size(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
switch i32 %8, label %11 [
i32 103, label %14
i32 71, label %14
i32 109, label %9
i32 77, label %9
i32 107, label %10
i32 75, label %10
i32 0, label %20
]
9: ; preds = %1, %1
br label %14
10: ; preds = %1, %1
br label %14
11: ; preds = %14, %1
%12 = phi i64 [ 1, %1 ], [ %15, %14 ]
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %1, %1, %11, %10, %9
%15 = phi i64 [ %12, %11 ], [ 1024, %10 ], [ 1048576, %9 ], [ 1073741824, %1 ], [ 1073741824, %1 ]
%16 = load i8, i8* %6
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %14
%19 = mul i64 %15, %4
br label %20
20: ; preds = %1, %18
%21 = phi i64 [ %19, %18 ], [ %4, %1 ]
ret i64 %21
}