#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 */
unsigned long simple_strtoul(char *, char **, int /*<<< orphan*/);
unsigned long memparse(char *ptr, char **retptr) {
  unsigned long ret = simple_strtoul(ptr, retptr, 0);
  switch (**retptr) {
  case 'G':
  case 'g':
    ret <<= 10;
  case 'M':
  case 'm':
    ret <<= 10;
  case 'K':
  case 'k':
    ret <<= 10;
    (*retptr)++;
  default:
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<memparse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1030 <simple_strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x47,%eax
je     11a3 <memparse+0x93>
jmp    114e <memparse+0x3e>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     11bb <memparse+0xab>
jmp    115f <memparse+0x4f>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     11af <memparse+0x9f>
jmp    1170 <memparse+0x60>
mov    -0x1c(%rbp),%eax
sub    $0x67,%eax
je     11a3 <memparse+0x93>
jmp    1181 <memparse+0x71>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     11bb <memparse+0xab>
jmp    1192 <memparse+0x82>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
je     11af <memparse+0x9f>
jmp    11d5 <memparse+0xc5>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11da <memparse+0xca>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memparse>:
push   %rbx
mov    %rsi,%rbx
xor    %edx,%edx
call   1030 <simple_strtoul@plt>
mov    (%rbx),%rcx
movsbl (%rcx),%edx
add    $0xffffffb9,%edx
cmp    $0x26,%edx
ja     1159 <memparse+0x49>
movabs $0x100000001,%rsi
bt     %rdx,%rsi
jb     115b <memparse+0x4b>
movabs $0x1000000010,%rsi
bt     %rdx,%rsi
jb     1163 <memparse+0x53>
movabs $0x4000000040,%rsi
bt     %rdx,%rsi
jb     115f <memparse+0x4f>
pop    %rbx
ret
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
add    $0x1,%rcx
mov    %rcx,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define i64 @memparse(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
%6 = load i8*, i8** %3
%7 = load i8**, i8*** %4
%8 = call i64 @simple_strtoul(i8* %6, i8** %7, i32 0)
store i64 %8, i64* %5
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %25 [
i32 71, label %13
i32 103, label %13
i32 77, label %16
i32 109, label %16
i32 75, label %19
i32 107, label %19
]
13: ; preds = %2, %2
%14 = load i64, i64* %5
%15 = shl i64 %14, 10
store i64 %15, i64* %5
br label %16
16: ; preds = %2, %2, %13
%17 = load i64, i64* %5
%18 = shl i64 %17, 10
store i64 %18, i64* %5
br label %19
19: ; preds = %2, %2, %16
%20 = load i64, i64* %5
%21 = shl i64 %20, 10
store i64 %21, i64* %5
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %22
br label %25
25: ; preds = %2, %19
br label %26
26: ; preds = %25
%27 = load i64, i64* %5
ret i64 %27
}

LLVM IR (-O2):
define i64 @memparse(i8* %0, i8** %1) {
%3 = tail call i64 @simple_strtoul(i8* %0, i8** %1, i32 0)
%4 = load i8*, i8** %1
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %16 [
i32 71, label %7
i32 103, label %7
i32 77, label %9
i32 109, label %9
i32 75, label %12
i32 107, label %12
]
7: ; preds = %2, %2
%8 = shl i64 %3, 10
br label %9
9: ; preds = %2, %2, %7
%10 = phi i64 [ %3, %2 ], [ %3, %2 ], [ %8, %7 ]
%11 = shl i64 %10, 10
br label %12
12: ; preds = %2, %2, %9
%13 = phi i64 [ %3, %2 ], [ %3, %2 ], [ %11, %9 ]
%14 = shl i64 %13, 10
%15 = getelementptr inbounds i8, i8* %4, i64 1
store i8* %15, i8** %1
br label %16
16: ; preds = %12, %2
%17 = phi i64 [ %3, %2 ], [ %14, %12 ]
ret i64 %17
}