#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 long atoi(char const *);
scalar_t__ isalpha(char const);
int /*<<< orphan*/ isdigit(char const);
int strlen(char const *);
int sizetoint(const char *arg) {
  int len = strlen(arg);
  int i;
  long long mult = 1;
  if (len && isalpha(arg[len - 1])) {
    switch (arg[len - 1]) {
    case 'k':
    case 'K':
      mult = 1024;
      break;
    case 'm':
    case 'M':
      mult = (1024 * 1024);
      break;
    case 'g':
    case 'G':
      mult = (1024 * (1024 * 1024));
      break;
    default:
      return (-1);
    }
    for (i = 0; i < len - 1; i++)
      if (!isdigit(arg[i]))
        return (-1);
  }
  return (mult * atoi(arg));
}


x86 assembly (clang, -O0):
<sizetoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movq   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     128a <sizetoint+0x14a>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     128a <sizetoint+0x14a>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
sub    $0x47,%eax
je     121b <sizetoint+0xdb>
jmp    11ac <sizetoint+0x6c>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     1201 <sizetoint+0xc1>
jmp    11bd <sizetoint+0x7d>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     120e <sizetoint+0xce>
jmp    11ce <sizetoint+0x8e>
mov    -0x24(%rbp),%eax
sub    $0x67,%eax
je     121b <sizetoint+0xdb>
jmp    11df <sizetoint+0x9f>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     1201 <sizetoint+0xc1>
jmp    11f0 <sizetoint+0xb0>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
je     120e <sizetoint+0xce>
jmp    1228 <sizetoint+0xe8>
movq   $0x400,-0x20(%rbp)
jmp    1234 <sizetoint+0xf4>
movq   $0x100000,-0x20(%rbp)
jmp    1234 <sizetoint+0xf4>
movq   $0x40000000,-0x20(%rbp)
40
jmp    1234 <sizetoint+0xf4>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <sizetoint+0x169>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1285 <sizetoint+0x145>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1272 <sizetoint+0x132>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <sizetoint+0x169>
jmp    1277 <sizetoint+0x137>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123b <sizetoint+0xfb>
jmp    128a <sizetoint+0x14a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
imul   %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sizetoint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    $0x1,%r15d
test   %eax,%eax
je     1208 <sizetoint+0xc8>
mov    %eax,%ebp
movslq %eax,%r12
movsbl -0x1(%r13,%r12,1),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1208 <sizetoint+0xc8>
add    $0xffffffffffffffff,%r12
movsbl 0x0(%r13,%r12,1),%eax
mov    $0xffffffff,%r14d
add    $0xffffffb9,%eax
cmp    $0x26,%eax
ja     1217 <sizetoint+0xd7>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     11d9 <sizetoint+0x99>
mov    $0x400,%r15d
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     11d2 <sizetoint+0x92>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    1217 <sizetoint+0xd7>
mov    $0x100000,%r15d
cmp    $0x2,%ebp
jge    11e4 <sizetoint+0xa4>
jmp    1208 <sizetoint+0xc8>
mov    $0x40000000,%r15d
cmp    $0x2,%ebp
jl     1208 <sizetoint+0xc8>
mov    %r12d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl 0x0(%r13,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1217 <sizetoint+0xd7>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11f0 <sizetoint+0xb0>
mov    %r13,%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
imul   %r15d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sizetoint(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i64 1, i64* %6
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %52
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = call i64 @isalpha(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %52
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %31 [
i32 107, label %28
i32 75, label %28
i32 109, label %29
i32 77, label %29
i32 103, label %30
i32 71, label %30
]
28: ; preds = %20, %20
store i64 1024, i64* %6
br label %32
29: ; preds = %20, %20
store i64 1048576, i64* %6
br label %32
30: ; preds = %20, %20
store i64 1073741824, i64* %6
br label %32
31: ; preds = %20
store i32 -1, i32* %2
br label %58
32: ; preds = %30, %29, %28
store i32 0, i32* %5
br label %33
33: ; preds = %48, %32
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %51
38: ; preds = %33
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = call i32 @isdigit(i8 signext %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %38
store i32 -1, i32* %2
br label %58
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %33
51: ; preds = %33
br label %52
52: ; preds = %51, %11, %1
%53 = load i64, i64* %6
%54 = load i8*, i8** %3
%55 = call i64 @atoi(i8* %54)
%56 = mul nsw i64 %53, %55
%57 = trunc i64 %56 to i32
store i32 %57, i32* %2
br label %58
58: ; preds = %52, %46, %31
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
define i32 @sizetoint(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %30, label %4
4: ; preds = %1
%5 = add nsw i32 %2, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i64 @isalpha(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %4
%12 = load i8, i8* %7
%13 = sext i8 %12 to i32
switch i32 %13, label %35 [
i32 107, label %16
i32 75, label %16
i32 109, label %14
i32 77, label %14
i32 103, label %15
i32 71, label %15
]
14: ; preds = %11, %11
br label %16
15: ; preds = %11, %11
br label %16
16: ; preds = %11, %11, %15, %14
%17 = phi i64 [ 1073741824, %15 ], [ 1048576, %14 ], [ 1024, %11 ], [ 1024, %11 ]
%18 = icmp sgt i32 %2, 1
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = zext i32 %5 to i64
br label %23
21: ; preds = %23
%22 = icmp eq i64 %29, %20
br i1 %22, label %30, label %23
23: ; preds = %19, %21
%24 = phi i64 [ 0, %19 ], [ %29, %21 ]
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = tail call i32 @isdigit(i8 signext %26)
%28 = icmp eq i32 %27, 0
%29 = add nuw nsw i64 %24, 1
br i1 %28, label %35, label %21
30: ; preds = %21, %16, %4, %1
%31 = phi i64 [ 1, %4 ], [ 1, %1 ], [ %17, %16 ], [ %17, %21 ]
%32 = tail call i64 @atoi(i8* %0)
%33 = mul nsw i64 %32, %31
%34 = trunc i64 %33 to i32
br label %35
35: ; preds = %23, %11, %30
%36 = phi i32 [ %34, %30 ], [ -1, %11 ], [ -1, %23 ]
ret i32 %36
}