#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 *, char const *);
int /*<<< orphan*/ isdigit(char const);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcasecmp(char *, char *);
size_t strtoul(char const *, char **, int /*<<< orphan*/);
int parse_size(const char *input, size_t *result) {
  char *ep;
  if (!isdigit(input[0]))
    goto failed;
  *result = strtoul(input, &ep, 0);
  if (!strcasecmp(ep, "k"))
    *result *= 1024;
  else if (!strcasecmp(ep, "m"))
    *result *= 1024 * 1024;
  else if (!strcasecmp(ep, "g"))
    *result *= 1024 * 1024 * 1024;
  else if (*ep)
    goto failed;
  return 1;
failed:
  fprintf(stderr, "cannot parse size argument \"%s\"\n", input);
  return 0;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    116a <parse_size+0x2a>
jmp    1234 <parse_size+0xf4>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11af <parse_size+0x6f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
shl    $0xa,%rcx
mov    %rcx,(%rax)
jmp    1228 <parse_size+0xe8>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11db <parse_size+0x9b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
shl    $0x14,%rcx
mov    %rcx,(%rax)
jmp    1223 <parse_size+0xe3>
mov    -0x20(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1207 <parse_size+0xc7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
shl    $0x1e,%rcx
mov    %rcx,(%rax)
jmp    121e <parse_size+0xde>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1219 <parse_size+0xd9>
jmp    1234 <parse_size+0xf4>
jmp    121e <parse_size+0xde>
jmp    1223 <parse_size+0xe3>
jmp    1228 <parse_size+0xe8>
movl   $0x1,-0x4(%rbp)
jmp    1254 <parse_size+0x114>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdbe(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movsbl (%rdi),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     11b1 <parse_size+0x71>
mov    %rsp,%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
mov    (%rsp),%r12
lea    0xe88(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11cd <parse_size+0x8d>
lea    0xe77(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11d3 <parse_size+0x93>
lea    0xe66(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11d9 <parse_size+0x99>
cmpb   $0x0,(%r12)
je     11e0 <parse_size+0xa0>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
jmp    11e5 <parse_size+0xa5>
shl    $0xa,%rbx
jmp    11dd <parse_size+0x9d>
shl    $0x14,%rbx
jmp    11dd <parse_size+0x9d>
shl    $0x1e,%rbx
mov    %rbx,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"k\00"
@.str.1 = [2 x i8] c"m\00"
@.str.2 = [2 x i8] c"g\00"
@stderr = global i32 0
@.str.3 = [33 x i8] c"cannot parse size argument \22%s\22\0A\00"
define i32 @parse_size(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = call i32 @isdigit(i8 signext %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
br label %49
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strtoul(i8* %14, i8** %6, i32 0)
%16 = load i64*, i64** %5
store i64 %15, i64* %16
%17 = load i8*, i8** %6
%18 = call i32 @strcasecmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %13
%21 = load i64*, i64** %5
%22 = load i64, i64* %21
%23 = mul i64 %22, 1024
store i64 %23, i64* %21
br label %48
24: ; preds = %13
%25 = load i8*, i8** %6
%26 = call i32 @strcasecmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i64*, i64** %5
%30 = load i64, i64* %29
%31 = mul i64 %30, 1048576
store i64 %31, i64* %29
br label %47
32: ; preds = %24
%33 = load i8*, i8** %6
%34 = call i32 @strcasecmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i64*, i64** %5
%38 = load i64, i64* %37
%39 = mul i64 %38, 1073741824
store i64 %39, i64* %37
br label %46
40: ; preds = %32
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
br label %49
45: ; preds = %40
br label %46
46: ; preds = %45, %36
br label %47
47: ; preds = %46, %28
br label %48
48: ; preds = %47, %20
store i32 1, i32* %3
br label %53
49: ; preds = %44, %12
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %4
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %49, %48
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [2 x i8] c"k\00"
@.str.1 = [2 x i8] c"m\00"
@.str.2 = [2 x i8] c"g\00"
@stderr = global i32 0
@.str.3 = [33 x i8] c"cannot parse size argument \22%s\22\0A\00"
define i32 @parse_size(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = tail call i32 @isdigit(i8 signext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %2
%9 = call i64 @strtoul(i8* %0, i8** %3, i32 0)
store i64 %9, i64* %1
%10 = load i8*, i8** %3
%11 = tail call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = shl i64 %9, 10
store i64 %14, i64* %1
br label %31
15: ; preds = %8
%16 = tail call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = shl i64 %9, 20
store i64 %19, i64* %1
br label %31
20: ; preds = %15
%21 = tail call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = shl i64 %9, 30
store i64 %24, i64* %1
br label %31
25: ; preds = %20
%26 = load i8, i8* %10
%27 = icmp eq i8 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25, %2
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %31
31: ; preds = %13, %23, %25, %18, %28
%32 = phi i32 [ 0, %28 ], [ 1, %18 ], [ 1, %25 ], [ 1, %23 ], [ 1, %13 ]
ret i32 %32
}