#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ print_usage(int /*<<< orphan*/);
int sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stderr;
int read_size(char *str) {
  int size = 0;
  char mult = ' ';
  int r = sscanf(str, "%u%c", &size, &mult);
  if (r == 1)
    return size;
  if (r == 2) {
    switch (mult) {
    case 'K':
      size = size << 10;
      break;
    case 'M':
      size = size << 20;
      break;
    case 'G':
      size = size << 30;
      break;
    default:
      fprintf(stderr,
              "RTS Opts: Unable to recognize size suffix `%c'.\n"
              "          Possible suffixes are K or M or G.\n",
              mult);
      print_usage(stderr);
      exit(EXIT_FAILURE);
    }
    return size;
  }
  fprintf(stderr, "RTS Opts: Unable to parse size. Egs: 1K, 10M, 2G.\n");
  print_usage(stderr);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<read_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x20,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x15(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1187 <read_size+0x47>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <read_size+0x127>
cmpl   $0x2,-0x1c(%rbp)
jne    1234 <read_size+0xf4>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x47,%eax
je     11e4 <read_size+0xa4>
jmp    11a6 <read_size+0x66>
mov    -0x20(%rbp),%eax
sub    $0x4b,%eax
je     11c8 <read_size+0x88>
jmp    11b7 <read_size+0x77>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     11d6 <read_size+0x96>
jmp    11f2 <read_size+0xb2>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x14(%rbp)
jmp    1229 <read_size+0xe9>
mov    -0x14(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x14(%rbp)
jmp    1229 <read_size+0xe9>
mov    -0x14(%rbp),%eax
shl    $0x1e,%eax
mov    %eax,-0x14(%rbp)
jmp    1229 <read_size+0xe9>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
movsbl -0x15(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1060 <print_usage@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <read_size+0x127>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1060 <print_usage@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_size>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
movb   $0x20,0xb(%rsp)
lea    0xea7(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0xb(%rsp),%rcx
call   1040 <sscanf@plt>
cmp    $0x2,%eax
je     1178 <read_size+0x38>
cmp    $0x1,%eax
jne    11ab <read_size+0x6b>
mov    0xc(%rsp),%eax
jmp    11a5 <read_size+0x65>
movsbl 0xb(%rsp),%edx
cmp    $0x47,%edx
je     1195 <read_size+0x55>
cmp    $0x4d,%edx
je     119e <read_size+0x5e>
cmp    $0x4b,%edx
jne    11c4 <read_size+0x84>
mov    0xc(%rsp),%eax
shl    $0xa,%eax
jmp    11a5 <read_size+0x65>
mov    0xc(%rsp),%eax
shl    $0x1e,%eax
jmp    11a5 <read_size+0x65>
mov    0xc(%rsp),%eax
shl    $0x14,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e2e(%rip),%rbx
mov    (%rbx),%edi
lea    0xea8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11db <read_size+0x9b>
mov    0x2e15(%rip),%rbx
mov    (%rbx),%edi
lea    0xe31(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <print_usage@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%u%c\00"
@stderr = global i32 0
@.str.1 = [94 x i8] c"RTS Opts: Unable to recognize size suffix `%c'.\0A Possible suffixes are K or M or G.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [51 x i8] c"RTS Opts: Unable to parse size. Egs: 1K, 10M, 2G.\0A\00"
define i32 @read_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i8 32, i8* %5
%7 = load i8*, i8** %3
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %5)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %46
13: ; preds = %1
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %39
16: ; preds = %13
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
switch i32 %18, label %28 [
i32 75, label %19
i32 77, label %22
i32 71, label %25
]
19: ; preds = %16
%20 = load i32, i32* %4
%21 = shl i32 %20, 10
store i32 %21, i32* %4
br label %37
22: ; preds = %16
%23 = load i32, i32* %4
%24 = shl i32 %23, 20
store i32 %24, i32* %4
br label %37
25: ; preds = %16
%26 = load i32, i32* %4
%27 = shl i32 %26, 30
store i32 %27, i32* %4
br label %37
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = load i8, i8* %5
%31 = sext i8 %30 to i32
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @stderr
%34 = call i32 @print_usage(i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %25, %22, %19
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %46
39: ; preds = %13
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @stderr
%43 = call i32 @print_usage(i32 %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %37, %11
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@.str = [5 x i8] c"%u%c\00"
@stderr = global i32 0
@.str.1 = [94 x i8] c"RTS Opts: Unable to recognize size suffix `%c'.\0A Possible suffixes are K or M or G.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [51 x i8] c"RTS Opts: Unable to parse size. Egs: 1K, 10M, 2G.\0A\00"
define i32 @read_size(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
store i8 32, i8* %3
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %3)
switch i32 %5, label %27 [
i32 1, label %6
i32 2, label %8
]
6: ; preds = %1
%7 = load i32, i32* %2
br label %34
8: ; preds = %1
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
switch i32 %10, label %20 [
i32 75, label %11
i32 77, label %14
i32 71, label %17
]
11: ; preds = %8
%12 = load i32, i32* %2
%13 = shl i32 %12, 10
br label %34
14: ; preds = %8
%15 = load i32, i32* %2
%16 = shl i32 %15, 20
br label %34
17: ; preds = %8
%18 = load i32, i32* %2
%19 = shl i32 %18, 30
br label %34
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%23 = load i32, i32* @stderr
%24 = call i32 @print_usage(i32 %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %1
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 @print_usage(i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %6, %11, %14, %17
%35 = phi i32 [ %7, %6 ], [ %13, %11 ], [ %16, %14 ], [ %19, %17 ]
ret i32 %35
}