#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ stderr;
char *strdupa(char const *);
size_t strlen(char *);
int parse_size(unsigned long *size_num, const char *__size_text) {
  size_t len;
  char suffix;
  char *size_text;
  unsigned long factor;
  size_text = strdupa(__size_text);
  if (size_text == NULL)
    do {
      fprintf(stderr, "Out of memory"
                      "\n");
      exit(1);
    } while (0);
  len = strlen(size_text);
  suffix = size_text[len - 1];
  factor = 1;
  switch (suffix) {
  case 'G':
  case 'g':
    factor *= 1024;
  case 'M':
  case 'm':
    factor *= 1024;
  case 'K':
  case 'k':
    factor *= 1024;
    size_text[len - 1] = 0;
    break;
  default:
    if (suffix < '0' || suffix > '9') {
      fprintf(stderr,
              "Illegal suffix: %c"
              "\n",
              suffix);
      return -1;
    }
  }
  if (sscanf(size_text, "%lu", size_num) != 1) {
    fprintf(stderr,
            "Unable to parse numeric size '%s'"
            "\n",
            size_text);
    return -1;
  }
  *size_num *= factor;
  return 0;
}


x86 assembly (clang, -O0):
<parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strdupa@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119e <parse_size+0x4e>
jmp    117d <parse_size+0x2d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    -0x1(%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movq   $0x1,-0x38(%rbp)
movsbl -0x21(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x47,%eax
je     122c <parse_size+0xdc>
jmp    11d7 <parse_size+0x87>
mov    -0x3c(%rbp),%eax
sub    $0x4b,%eax
je     1244 <parse_size+0xf4>
jmp    11e8 <parse_size+0x98>
mov    -0x3c(%rbp),%eax
sub    $0x4d,%eax
je     1238 <parse_size+0xe8>
jmp    11f9 <parse_size+0xa9>
mov    -0x3c(%rbp),%eax
sub    $0x67,%eax
je     122c <parse_size+0xdc>
jmp    120a <parse_size+0xba>
mov    -0x3c(%rbp),%eax
sub    $0x6b,%eax
je     1244 <parse_size+0xf4>
jmp    121b <parse_size+0xcb>
mov    -0x3c(%rbp),%eax
sub    $0x6d,%eax
je     1238 <parse_size+0xe8>
jmp    1265 <parse_size+0x115>
mov    -0x38(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12ab <parse_size+0x15b>
movsbl -0x21(%rbp),%eax
cmp    $0x30,%eax
jl     127f <parse_size+0x12f>
movsbl -0x21(%rbp),%eax
cmp    $0x39,%eax
jle    12a6 <parse_size+0x156>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
movsbl -0x21(%rbp),%edx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <parse_size+0x1b5>
jmp    12ab <parse_size+0x15b>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd69(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12ef <parse_size+0x19f>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <parse_size+0x1b5>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
imul   (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_size>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <strdupa@plt>
test   %rax,%rax
je     1235 <parse_size+0xe5>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
movsbl -0x1(%rax,%rbx,1),%edx
lea    -0x47(%rdx),%ecx
cmp    $0x26,%ecx
ja     11bd <parse_size+0x6d>
movabs $0x100000001,%rsi
bt     %rcx,%rsi
jb     11e3 <parse_size+0x93>
mov    $0x400,%r15d
movabs $0x1000000010,%rsi
bt     %rcx,%rsi
jb     11e9 <parse_size+0x99>
mov    $0x100000,%r15d
movabs $0x4000000040,%rsi
bt     %rcx,%rsi
jb     11e9 <parse_size+0x99>
lea    -0x3a(%rdx),%eax
mov    $0x1,%r15d
cmp    $0xf5,%al
ja     11ee <parse_size+0x9e>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    122a <parse_size+0xda>
mov    $0x40000000,%r15d
movb   $0x0,-0x1(%rbx,%rax,1)
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1210 <parse_size+0xc0>
imul   (%r14),%r15
mov    %r15,(%r14)
xor    %eax,%eax
jmp    122f <parse_size+0xdf>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [20 x i8] c"Illegal suffix: %c\0A\00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [35 x i8] c"Unable to parse numeric size '%s'\0A\00"
define i32 @parse_size(i64* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i64
store i64* %0, i64** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i8* @strdupa(i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
br label %15
15: ; preds = %14
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; No predecessors!
br label %20
20: ; preds = %19, %2
%21 = load i8*, i8** %8
%22 = call i64 @strlen(i8* %21)
store i64 %22, i64* %6
%23 = load i8*, i8** %8
%24 = load i64, i64* %6
%25 = sub i64 %24, 1
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %7
store i64 1, i64* %9
%28 = load i8, i8* %7
%29 = sext i8 %28 to i32
switch i32 %29, label %43 [
i32 71, label %30
i32 103, label %30
i32 77, label %33
i32 109, label %33
i32 75, label %36
i32 107, label %36
]
30: ; preds = %20, %20
%31 = load i64, i64* %9
%32 = mul i64 %31, 1024
store i64 %32, i64* %9
br label %33
33: ; preds = %20, %20, %30
%34 = load i64, i64* %9
%35 = mul i64 %34, 1024
store i64 %35, i64* %9
br label %36
36: ; preds = %20, %20, %33
%37 = load i64, i64* %9
%38 = mul i64 %37, 1024
store i64 %38, i64* %9
%39 = load i8*, i8** %8
%40 = load i64, i64* %6
%41 = sub i64 %40, 1
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
br label %57
43: ; preds = %20
%44 = load i8, i8* %7
%45 = sext i8 %44 to i32
%46 = icmp slt i32 %45, 48
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = load i8, i8* %7
%49 = sext i8 %48 to i32
%50 = icmp sgt i32 %49, 57
br i1 %50, label %51, label %56
51: ; preds = %47, %43
%52 = load i32, i32* @stderr
%53 = load i8, i8* %7
%54 = sext i8 %53 to i32
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %54)
store i32 -1, i32* %3
br label %71
56: ; preds = %47
br label %57
57: ; preds = %56, %36
%58 = load i8*, i8** %8
%59 = load i64*, i64** %4
%60 = call i32 @sscanf(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %59)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %8
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %64)
store i32 -1, i32* %3
br label %71
66: ; preds = %57
%67 = load i64, i64* %9
%68 = load i64*, i64** %4
%69 = load i64, i64* %68
%70 = mul i64 %69, %67
store i64 %70, i64* %68
store i32 0, i32* %3
br label %71
71: ; preds = %66, %62, %51
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [20 x i8] c"Illegal suffix: %c\0A\00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [35 x i8] c"Unable to parse numeric size '%s'\0A\00"
define i32 @parse_size(i64* %0, i8* %1) {
%3 = tail call i8* @strdupa(i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i64 @strlen(i8* %3)
%11 = add i64 %10, -1
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %20 [
i32 71, label %15
i32 103, label %15
i32 77, label %16
i32 109, label %16
i32 75, label %18
i32 107, label %18
]
15: ; preds = %9, %9
br label %16
16: ; preds = %9, %9, %15
%17 = phi i64 [ 1048576, %9 ], [ 1048576, %9 ], [ 1073741824, %15 ]
br label %18
18: ; preds = %9, %9, %16
%19 = phi i64 [ 1024, %9 ], [ 1024, %9 ], [ %17, %16 ]
store i8 0, i8* %12
br label %26
20: ; preds = %9
%21 = add i8 %13, -58
%22 = icmp ult i8 %21, -10
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %36
26: ; preds = %20, %18
%27 = phi i64 [ 1, %20 ], [ %19, %18 ]
%28 = tail call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %0)
%29 = icmp eq i32 %28, 1
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %36
33: ; preds = %26
%34 = load i64, i64* %0
%35 = mul i64 %34, %27
store i64 %35, i64* %0
br label %36
36: ; preds = %33, %30, %23
%37 = phi i32 [ -1, %23 ], [ -1, %30 ], [ 0, %33 ]
ret i32 %37
}