#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 sscanf(char *, char *, int *, char *, char *);
int convert_size(char *str) {
  int number = 0;
  char err_c = 0;
  char last_sym = 0;
  int ret_code = 0;
  ret_code = sscanf(str, "%d%c%c", &number, &last_sym, &err_c);
  if (err_c != '\0' || ret_code == 0 || number < 0) {
    return -1;
  }
  switch (last_sym) {
  case '\0':
    return number;
  case 'K':
    return 1024 * number;
  case 'M':
    return 1024 * 1024 * number;
  case 'G':
    return 1024 * 1024 * 1024 * number;
  default:
    return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<convert_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movb   $0x0,-0x16(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec3(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x16(%rbp),%rcx
lea    -0x15(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    1172 <convert_size+0x62>
cmpl   $0x0,-0x1c(%rbp)
je     1172 <convert_size+0x62>
cmpl   $0x0,-0x14(%rbp)
jge    117e <convert_size+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <convert_size+0xf1>
movsbl -0x16(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     11c5 <convert_size+0xb5>
jmp    1192 <convert_size+0x82>
mov    -0x20(%rbp),%eax
sub    $0x47,%eax
je     11ec <convert_size+0xdc>
jmp    11a3 <convert_size+0x93>
mov    -0x20(%rbp),%eax
sub    $0x4b,%eax
je     11d0 <convert_size+0xc0>
jmp    11b4 <convert_size+0xa4>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     11de <convert_size+0xce>
jmp    11fa <convert_size+0xea>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <convert_size+0xf1>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <convert_size+0xf1>
mov    -0x14(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <convert_size+0xf1>
mov    -0x14(%rbp),%eax
shl    $0x1e,%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <convert_size+0xf1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_size>:
push   %rax
movl   $0x0,0x4(%rsp)
movb   $0x0,0x3(%rsp)
movb   $0x0,0x2(%rsp)
lea    0xed6(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x2(%rsp),%rcx
lea    0x3(%rsp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     117f <convert_size+0x6f>
cmpb   $0x0,0x3(%rsp)
jne    117f <convert_size+0x6f>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
js     117f <convert_size+0x6f>
movsbl 0x2(%rsp),%edx
cmp    $0x4a,%edx
jg     1170 <convert_size+0x60>
test   %edx,%edx
je     1184 <convert_size+0x74>
cmp    $0x47,%edx
jne    117f <convert_size+0x6f>
shl    $0x1e,%ecx
jmp    1184 <convert_size+0x74>
cmp    $0x4d,%edx
je     1181 <convert_size+0x71>
cmp    $0x4b,%edx
jne    117f <convert_size+0x6f>
shl    $0xa,%ecx
jmp    1184 <convert_size+0x74>
pop    %rcx
ret
shl    $0x14,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d%c%c\00"
define i32 @convert_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i8 0, i8* %5
store i8 0, i8* %6
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %6, i8* %5)
store i32 %9, i32* %7
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %1
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16, %13, %1
store i32 -1, i32* %2
br label %35
20: ; preds = %16
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
switch i32 %22, label %34 [
i32 0, label %23
i32 75, label %25
i32 77, label %28
i32 71, label %31
]
23: ; preds = %20
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %35
25: ; preds = %20
%26 = load i32, i32* %4
%27 = mul nsw i32 1024, %26
store i32 %27, i32* %2
br label %35
28: ; preds = %20
%29 = load i32, i32* %4
%30 = mul nsw i32 1048576, %29
store i32 %30, i32* %2
br label %35
31: ; preds = %20
%32 = load i32, i32* %4
%33 = mul nsw i32 1073741824, %32
store i32 %33, i32* %2
br label %35
34: ; preds = %20
store i32 -1, i32* %2
br label %35
35: ; preds = %34, %31, %28, %25, %23, %19
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d%c%c\00"
define i32 @convert_size(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
store i8 0, i8* %3
store i8 0, i8* %4
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %4, i8* %3)
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, 0
%9 = icmp eq i32 %6, 0
%10 = or i1 %9, %8
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %24, label %14
14: ; preds = %1
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
switch i32 %16, label %23 [
i32 0, label %24
i32 75, label %17
i32 77, label %19
i32 71, label %21
]
17: ; preds = %14
%18 = shl nsw i32 %11, 10
br label %24
19: ; preds = %14
%20 = shl nsw i32 %11, 20
br label %24
21: ; preds = %14
%22 = shl nsw i32 %11, 30
br label %24
23: ; preds = %14
br label %24
24: ; preds = %14, %1, %23, %21, %19, %17
%25 = phi i32 [ -1, %23 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ -1, %1 ], [ %11, %14 ]
ret i32 %25
}