#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strchr(char *, char);
uint32_t get_size(char *str) {
  uint32_t val = 0;
  if (strchr(str, 'k')) {
    if (sscanf(str, "%u%*c", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return (val * 1024);
  } else if (strchr(str, 'M')) {
    if (sscanf(str, "%u%*c", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return (val * 1024 * 1024);
  } else if (strchr(str, 'G')) {
    int res = sscanf(str, "%uG", &val);
    if (res != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s' (%d)\n", str, res);
      return -1;
    }
    return (val * 1024 * 1024 * 1024);
  } else {
    if (sscanf(str, "%u", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return val;
  }
}


x86 assembly (clang, -O0):
<get_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x6b,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11ad <get_size+0x7d>
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     119f <get_size+0x6f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x10(%rbp),%rdi
mov    $0x4d,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     121a <get_size+0xea>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1209 <get_size+0xd9>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x10(%rbp),%rdi
mov    $0x47,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1291 <get_size+0x161>
mov    -0x10(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     127d <get_size+0x14d>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x10(%rbp),%rdi
lea    0xdad(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     12d5 <get_size+0x1a5>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <get_size+0x1ab>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_size>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
mov    $0x6b,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1178 <get_size+0x48>
lea    0xeaa(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11ff <get_size+0xcf>
mov    0xc(%rsp),%eax
shl    $0xa,%eax
jmp    121e <get_size+0xee>
mov    %rbx,%rdi
mov    $0x4d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11ac <get_size+0x7c>
lea    0xe6f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11ff <get_size+0xcf>
mov    0xc(%rsp),%eax
shl    $0x14,%eax
jmp    121e <get_size+0xee>
mov    %rbx,%rdi
mov    $0x47,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11e0 <get_size+0xb0>
lea    0xe5e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1224 <get_size+0xf4>
mov    0xc(%rsp),%eax
shl    $0x1e,%eax
jmp    121e <get_size+0xee>
lea    0xe62(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11ff <get_size+0xcf>
mov    0xc(%rsp),%eax
jmp    121e <get_size+0xee>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2db5(%rip),%rcx
mov    (%rcx),%edi
lea    0xdf3(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1219 <get_size+0xe9>

LLVM IR (-O0):
@.str = [6 x i8] c"%u%*c\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"ERROR: Incorrect value '%s'\0A\00"
@.str.2 = [4 x i8] c"%uG\00"
@.str.3 = [34 x i8] c"ERROR: Incorrect value '%s' (%d)\0A\00"
@.str.4 = [3 x i8] c"%u\00"
define i32 @get_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = call i64 @strchr(i8* %6, i8 signext 107)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -1, i32* %2
br label %65
17: ; preds = %9
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 1024
store i32 %19, i32* %2
br label %65
20: ; preds = %1
%21 = load i8*, i8** %3
%22 = call i64 @strchr(i8* %21, i8 signext 77)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %3
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 -1, i32* %2
br label %65
32: ; preds = %24
%33 = load i32, i32* %4
%34 = mul nsw i32 %33, 1024
%35 = mul nsw i32 %34, 1024
store i32 %35, i32* %2
br label %65
36: ; preds = %20
%37 = load i8*, i8** %3
%38 = call i64 @strchr(i8* %37, i8 signext 71)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = load i8*, i8** %3
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %4)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %3
%48 = load i32, i32* %5
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %47, i32 %48)
store i32 -1, i32* %2
br label %65
50: ; preds = %40
%51 = load i32, i32* %4
%52 = mul nsw i32 %51, 1024
%53 = mul nsw i32 %52, 1024
%54 = mul nsw i32 %53, 1024
store i32 %54, i32* %2
br label %65
55: ; preds = %36
%56 = load i8*, i8** %3
%57 = call i32 @sscanf(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%58 = icmp ne i32 %57, 1
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %3
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %61)
store i32 -1, i32* %2
br label %65
63: ; preds = %55
%64 = load i32, i32* %4
store i32 %64, i32* %2
br label %65
65: ; preds = %63, %59, %50, %45, %32, %28, %17, %13
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [6 x i8] c"%u%*c\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"ERROR: Incorrect value '%s'\0A\00"
@.str.2 = [4 x i8] c"%uG\00"
@.str.3 = [34 x i8] c"ERROR: Incorrect value '%s' (%d)\0A\00"
@.str.4 = [3 x i8] c"%u\00"
define i32 @get_size(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = tail call i64 @strchr(i8* %0, i8 signext 107)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %47
12: ; preds = %6
%13 = load i32, i32* %2
%14 = shl nsw i32 %13, 10
br label %47
15: ; preds = %1
%16 = tail call i64 @strchr(i8* %0, i8 signext 77)
%17 = icmp eq i64 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %15
%19 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2)
%20 = icmp eq i32 %19, 1
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %47
24: ; preds = %18
%25 = load i32, i32* %2
%26 = shl nsw i32 %25, 20
br label %47
27: ; preds = %15
%28 = tail call i64 @strchr(i8* %0, i8 signext 71)
%29 = icmp eq i64 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %27
%31 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%32 = icmp eq i32 %31, 1
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %31)
br label %47
36: ; preds = %30
%37 = load i32, i32* %2
%38 = shl nsw i32 %37, 30
br label %47
39: ; preds = %27
%40 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%41 = icmp eq i32 %40, 1
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %47
45: ; preds = %39
%46 = load i32, i32* %2
br label %47
47: ; preds = %33, %36, %45, %42, %24, %21, %12, %9
%48 = phi i32 [ -1, %9 ], [ %14, %12 ], [ -1, %21 ], [ %26, %24 ], [ -1, %42 ], [ %46, %45 ], [ -1, %33 ], [ %38, %36 ]
ret i32 %48
}