#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*/ fprintf(int /*<<< orphan*/, char *);
int sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int parse_memory_param(char *p) {
  int bytes;
  char units;
  if (2 != sscanf(p, "%d%c", &bytes, &units)) {
    fprintf(stderr, "failed to parse -m\n");
    usage();
  }
  switch (units) {
  case 'b':
  case 'B':
    break;
  case 'k':
  case 'K':
    bytes *= 1024;
    break;
  case 'm':
  case 'M':
    bytes *= 1024 * 1024;
    break;
  case 'g':
  case 'G':
    bytes *= 1024 * 1024 * 1024;
    break;
  default:
    fprintf(stderr, "-m: bad memory units, use b, k, m, g\n");
  }
  return bytes;
}


x86 assembly (clang, -O0):
<parse_memory_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xf69(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0xd(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
je     117f <parse_memory_param+0x4f>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xf42(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1050 <usage@plt>
movsbl -0xd(%rbp),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x2b,%eax
ja     11d8 <parse_memory_param+0xa8>
mov    -0x18(%rbp),%rax
lea    0xe60(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11ed <parse_memory_param+0xbd>
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    11ed <parse_memory_param+0xbd>
mov    -0xc(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0xc(%rbp)
jmp    11ed <parse_memory_param+0xbd>
mov    -0xc(%rbp),%eax
shl    $0x1e,%eax
mov    %eax,-0xc(%rbp)
jmp    11ed <parse_memory_param+0xbd>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xee1(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_memory_param>:
push   %rax
lea    0xf78(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x2,%eax
je     1168 <parse_memory_param+0x38>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xf59(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1050 <usage@plt>
movsbl 0x3(%rsp),%eax
add    $0xffffffbe,%eax
cmp    $0x2b,%eax
ja     119a <parse_memory_param+0x6a>
lea    0xe84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
shll   $0x1e,0x4(%rsp)
jmp    11af <parse_memory_param+0x7f>
shll   $0xa,0x4(%rsp)
jmp    11af <parse_memory_param+0x7f>
shll   $0x14,0x4(%rsp)
jmp    11af <parse_memory_param+0x7f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xf1f(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"failed to parse -m\0A\00"
@.str.2 = [38 x i8] c"-m: bad memory units, use b, k, m, g\0A\00"
define i32 @parse_memory_param(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %4)
%7 = icmp ne i32 2, %6
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (...) @usage()
br label %12
12: ; preds = %8, %1
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
switch i32 %14, label %25 [
i32 98, label %15
i32 66, label %15
i32 107, label %16
i32 75, label %16
i32 109, label %19
i32 77, label %19
i32 103, label %22
i32 71, label %22
]
15: ; preds = %12, %12
br label %28
16: ; preds = %12, %12
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 1024
store i32 %18, i32* %3
br label %28
19: ; preds = %12, %12
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 1048576
store i32 %21, i32* %3
br label %28
22: ; preds = %12, %12
%23 = load i32, i32* %3
%24 = mul nsw i32 %23, 1073741824
store i32 %24, i32* %3
br label %28
25: ; preds = %12
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %22, %19, %16, %15
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"failed to parse -m\0A\00"
@.str.2 = [38 x i8] c"-m: bad memory units, use b, k, m, g\0A\00"
define i32 @parse_memory_param(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %3)
%6 = icmp eq i32 %5, 2
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @usage()
br label %11
11: ; preds = %7, %1
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
switch i32 %13, label %23 [
i32 98, label %26
i32 66, label %26
i32 107, label %14
i32 75, label %14
i32 109, label %17
i32 77, label %17
i32 103, label %20
i32 71, label %20
]
14: ; preds = %11, %11
%15 = load i32, i32* %2
%16 = shl nsw i32 %15, 10
store i32 %16, i32* %2
br label %26
17: ; preds = %11, %11
%18 = load i32, i32* %2
%19 = shl nsw i32 %18, 20
store i32 %19, i32* %2
br label %26
20: ; preds = %11, %11
%21 = load i32, i32* %2
%22 = shl nsw i32 %21, 30
store i32 %22, i32* %2
br label %26
23: ; preds = %11
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %11, %11, %23, %20, %17, %14
%27 = load i32, i32* %2
ret i32 %27
}