#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 strtoll(char *, char **, int /*<<< orphan*/);
int tolower(char);
long long cvtnum(char *s) {
  long long i;
  char *sp;
  int c;
  i = strtoll(s, &sp, 0);
  if (i == 0 && sp == s)
    return -1LL;
  if (*sp == '\0')
    return i;
  if (sp[1] != '\0')
    return -1LL;
  c = tolower(*sp);
  switch (c) {
  default:
    return i;
  case 'k':
    return ((long long)(i) << 10);
  case 'm':
    return ((long long)(i) << 20);
  case 'g':
    return ((long long)(i) << 30);
  case 't':
    return ((long long)(i) << 40);
  case 'p':
    return ((long long)(i) << 50);
  case 'e':
    return ((long long)(i) << 60);
  }
  return -1LL;
}


x86 assembly (clang, -O0):
<cvtnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1165 <cvtnum+0x45>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1165 <cvtnum+0x45>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1246 <cvtnum+0x126>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1182 <cvtnum+0x62>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11a0 <cvtnum+0x80>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1246 <cvtnum+0x126>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xf,%eax
ja     11d8 <cvtnum+0xb8>
mov    -0x30(%rbp),%rax
lea    0xe31(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x18(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x18(%rbp),%rax
shl    $0x28,%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x18(%rbp),%rax
shl    $0x32,%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <cvtnum+0x126>
mov    -0x18(%rbp),%rax
shl    $0x3c,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvtnum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,%r14
mov    (%rsp),%rcx
mov    $0xffffffffffffffff,%rax
test   %r14,%r14
jne    1149 <cvtnum+0x29>
cmp    %rbx,%rcx
je     119d <cvtnum+0x7d>
mov    (%rcx),%dl
test   %dl,%dl
je     119a <cvtnum+0x7a>
cmpb   $0x0,0x1(%rcx)
jne    119d <cvtnum+0x7d>
movsbl %dl,%edi
call   1040 <tolower@plt>
add    $0xffffff9b,%eax
cmp    $0xf,%eax
ja     119a <cvtnum+0x7a>
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    %r14,%rax
jmp    *%rdx
shl    $0x3c,%r14
jmp    119a <cvtnum+0x7a>
shl    $0x1e,%r14
jmp    119a <cvtnum+0x7a>
shl    $0xa,%r14
jmp    119a <cvtnum+0x7a>
shl    $0x14,%r14
jmp    119a <cvtnum+0x7a>
shl    $0x32,%r14
jmp    119a <cvtnum+0x7a>
shl    $0x28,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @cvtnum(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strtoll(i8* %7, i8** %5, i32 0)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = icmp eq i8* %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i64 -1, i64* %2
br label %55
16: ; preds = %11, %1
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i64, i64* %4
store i64 %22, i64* %2
br label %55
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i64 -1, i64* %2
br label %55
30: ; preds = %23
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = call i32 @tolower(i8 signext %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
switch i32 %34, label %35 [
i32 107, label %37
i32 109, label %40
i32 103, label %43
i32 116, label %46
i32 112, label %49
i32 101, label %52
]
35: ; preds = %30
%36 = load i64, i64* %4
store i64 %36, i64* %2
br label %55
37: ; preds = %30
%38 = load i64, i64* %4
%39 = shl i64 %38, 10
store i64 %39, i64* %2
br label %55
40: ; preds = %30
%41 = load i64, i64* %4
%42 = shl i64 %41, 20
store i64 %42, i64* %2
br label %55
43: ; preds = %30
%44 = load i64, i64* %4
%45 = shl i64 %44, 30
store i64 %45, i64* %2
br label %55
46: ; preds = %30
%47 = load i64, i64* %4
%48 = shl i64 %47, 40
store i64 %48, i64* %2
br label %55
49: ; preds = %30
%50 = load i64, i64* %4
%51 = shl i64 %50, 50
store i64 %51, i64* %2
br label %55
52: ; preds = %30
%53 = load i64, i64* %4
%54 = shl i64 %53, 60
store i64 %54, i64* %2
br label %55
55: ; preds = %52, %49, %46, %43, %40, %37, %35, %29, %21, %15
%56 = load i64, i64* %2
ret i64 %56
}

LLVM IR (-O2):
define i64 @cvtnum(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoll(i8* %0, i8** %2, i32 0)
%5 = icmp eq i64 %4, 0
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, %0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %30, label %9
9: ; preds = %1
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = tail call i32 @tolower(i8 signext %10)
switch i32 %17, label %30 [
i32 107, label %18
i32 109, label %20
i32 103, label %22
i32 116, label %24
i32 112, label %26
i32 101, label %28
]
18: ; preds = %16
%19 = shl i64 %4, 10
br label %30
20: ; preds = %16
%21 = shl i64 %4, 20
br label %30
22: ; preds = %16
%23 = shl i64 %4, 30
br label %30
24: ; preds = %16
%25 = shl i64 %4, 40
br label %30
26: ; preds = %16
%27 = shl i64 %4, 50
br label %30
28: ; preds = %16
%29 = shl i64 %4, 60
br label %30
30: ; preds = %16, %12, %9, %1, %28, %26, %24, %22, %20, %18
%31 = phi i64 [ %29, %28 ], [ %27, %26 ], [ %25, %24 ], [ %23, %22 ], [ %21, %20 ], [ %19, %18 ], [ -1, %1 ], [ %4, %9 ], [ -1, %12 ], [ %4, %16 ]
ret i64 %31
}