#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 */
long strtol(char const *, char **, int);
long atosize(const char *s) {
  char *end;
  long value = strtol(s, &end, 10);
  if (value <= 0)
    return 0;
  switch (*end) {
  default:
    return 0;
  case '\0':
    break;
  case 'k':
  case 'K':
    value <<= 10;
    break;
  case 'M':
    value <<= 20;
    break;
  }
  return value;
}


x86 assembly (clang, -O0):
<atosize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jg     114a <atosize+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    11cb <atosize+0xbb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     11a1 <atosize+0x91>
jmp    1161 <atosize+0x51>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     11a6 <atosize+0x96>
jmp    1172 <atosize+0x62>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     11b7 <atosize+0xa7>
jmp    1183 <atosize+0x73>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     11a6 <atosize+0x96>
jmp    1194 <atosize+0x84>
movq   $0x0,-0x8(%rbp)
jmp    11cb <atosize+0xbb>
jmp    11c3 <atosize+0xb3>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
jmp    11c3 <atosize+0xb3>
mov    -0x20(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atosize>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
test   %rax,%rax
jle    113c <atosize+0x2c>
mov    (%rsp),%rcx
movsbl (%rcx),%edx
xor    %ecx,%ecx
cmp    $0x4c,%edx
jg     1140 <atosize+0x30>
test   %edx,%edx
je     1154 <atosize+0x44>
cmp    $0x4b,%edx
je     114a <atosize+0x3a>
jmp    1157 <atosize+0x47>
xor    %ecx,%ecx
jmp    1157 <atosize+0x47>
cmp    $0x4d,%edx
je     1150 <atosize+0x40>
cmp    $0x6b,%edx
jne    1157 <atosize+0x47>
shl    $0xa,%rax
jmp    1154 <atosize+0x44>
shl    $0x14,%rax
mov    %rax,%rcx
mov    %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @atosize(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strtol(i8* %6, i8** %4, i32 10)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp sle i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i64 0, i64* %2
br label %25
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %15 [
i32 0, label %16
i32 107, label %17
i32 75, label %17
i32 77, label %20
]
15: ; preds = %11
store i64 0, i64* %2
br label %25
16: ; preds = %11
br label %23
17: ; preds = %11, %11
%18 = load i64, i64* %5
%19 = shl i64 %18, 10
store i64 %19, i64* %5
br label %23
20: ; preds = %11
%21 = load i64, i64* %5
%22 = shl i64 %21, 20
store i64 %22, i64* %5
br label %23
23: ; preds = %20, %17, %16
%24 = load i64, i64* %5
store i64 %24, i64* %2
br label %25
25: ; preds = %23, %15, %10
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
define i64 @atosize(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%5 = icmp slt i64 %4, 1
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %16 [
i32 0, label %14
i32 107, label %10
i32 75, label %10
i32 77, label %12
]
10: ; preds = %6, %6
%11 = shl i64 %4, 10
br label %14
12: ; preds = %6
%13 = shl i64 %4, 20
br label %14
14: ; preds = %12, %10, %6
%15 = phi i64 [ %13, %12 ], [ %11, %10 ], [ %4, %6 ]
br label %16
16: ; preds = %6, %1, %14
%17 = phi i64 [ %15, %14 ], [ 0, %1 ], [ 0, %6 ]
ret i64 %17
}