#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 */
size_t strtoull(char const *, char **, int /*<<< orphan*/);
int parse_mem_arg(const char *str, size_t *result) {
  size_t r;
  char *p;
  r = strtoull(str, &p, 0);
  switch (*p) {
  case 'k':
  case 'K':
    r *= 1024;
    ++p;
    break;
  case 'm':
  case 'M':
    r *= 1024 * 1024;
    ++p;
    break;
  case 'g':
  case 'G':
    r *= 1024 * 1024 * 1024;
    ++p;
    break;
  }
  if (*p) {
    return -1;
  }
  *result = r;
  return 0;
}


x86 assembly (clang, -O0):
<parse_mem_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x47,%eax
je     11da <parse_mem_arg+0xca>
jmp    114b <parse_mem_arg+0x3b>
mov    -0x2c(%rbp),%eax
sub    $0x4b,%eax
je     11a0 <parse_mem_arg+0x90>
jmp    115c <parse_mem_arg+0x4c>
mov    -0x2c(%rbp),%eax
sub    $0x4d,%eax
je     11bd <parse_mem_arg+0xad>
jmp    116d <parse_mem_arg+0x5d>
mov    -0x2c(%rbp),%eax
sub    $0x67,%eax
je     11da <parse_mem_arg+0xca>
jmp    117e <parse_mem_arg+0x6e>
mov    -0x2c(%rbp),%eax
sub    $0x6b,%eax
je     11a0 <parse_mem_arg+0x90>
jmp    118f <parse_mem_arg+0x7f>
mov    -0x2c(%rbp),%eax
sub    $0x6d,%eax
je     11bd <parse_mem_arg+0xad>
jmp    11f2 <parse_mem_arg+0xe2>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f2 <parse_mem_arg+0xe2>
mov    -0x20(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f2 <parse_mem_arg+0xe2>
mov    -0x20(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     120b <parse_mem_arg+0xfb>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <parse_mem_arg+0x10d>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mem_arg>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    (%rsp),%rdx
movsbl (%rdx),%esi
mov    %esi,%edi
add    $0xffffffb9,%edi
cmp    $0x26,%edi
ja     117a <parse_mem_arg+0x6a>
movabs $0x100000001,%rcx
bt     %rdi,%rcx
jb     116e <parse_mem_arg+0x5e>
mov    $0xa,%ecx
movabs $0x1000000010,%rbx
bt     %rdi,%rbx
jb     1173 <parse_mem_arg+0x63>
movabs $0x4000000040,%rcx
bt     %rdi,%rcx
jae    117a <parse_mem_arg+0x6a>
mov    $0x14,%ecx
jmp    1173 <parse_mem_arg+0x63>
mov    $0x1e,%ecx
shl    %cl,%rax
mov    0x1(%rdx),%sil
mov    $0xffffffff,%ecx
test   %sil,%sil
jne    1189 <parse_mem_arg+0x79>
mov    %rax,(%r14)
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @parse_mem_arg(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtoull(i8* %0, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %16 [
i32 107, label %11
i32 75, label %11
i32 109, label %9
i32 77, label %9
i32 103, label %10
i32 71, label %10
]
9: ; preds = %2, %2
br label %11
10: ; preds = %2, %2
br label %11
11: ; preds = %2, %2, %9, %10
%12 = phi i64 [ 20, %9 ], [ 30, %10 ], [ 10, %2 ], [ 10, %2 ]
%13 = shl i64 %5, %12
%14 = getelementptr inbounds i8, i8* %6, i64 1
%15 = load i8, i8* %14
br label %16
16: ; preds = %11, %2
%17 = phi i8 [ %15, %11 ], [ %7, %2 ]
%18 = phi i64 [ %13, %11 ], [ %5, %2 ]
%19 = icmp eq i8 %17, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i64 %18, i64* %1
br label %21
21: ; preds = %16, %20
%22 = phi i32 [ 0, %20 ], [ -1, %16 ]
ret i32 %22
}