#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) {
  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     123e <cvtnum+0x11e>
mov    -0x30(%rbp),%rax
lea    0xe31(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
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)
jmp    1246 <cvtnum+0x126>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvtnum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rax
mov    $0xffffffffffffffff,%r14
test   %r15,%r15
jne    1151 <cvtnum+0x31>
cmp    %rbx,%rax
je     11a2 <cvtnum+0x82>
mov    (%rax),%cl
test   %cl,%cl
je     119f <cvtnum+0x7f>
cmpb   $0x0,0x1(%rax)
jne    11a2 <cvtnum+0x82>
movsbl %cl,%edi
call   1040 <tolower@plt>
add    $0xffffff9b,%eax
cmp    $0xf,%eax
ja     11a2 <cvtnum+0x82>
lea    0xe8c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
shl    $0x3c,%r15
jmp    119f <cvtnum+0x7f>
shl    $0x1e,%r15
jmp    119f <cvtnum+0x7f>
shl    $0xa,%r15
jmp    119f <cvtnum+0x7f>
shl    $0x14,%r15
jmp    119f <cvtnum+0x7f>
shl    $0x32,%r15
jmp    119f <cvtnum+0x7f>
shl    $0x28,%r15
mov    %r15,%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 %54
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 %54
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 %54
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 %53 [
i32 107, label %35
i32 109, label %38
i32 103, label %41
i32 116, label %44
i32 112, label %47
i32 101, label %50
]
35: ; preds = %30
%36 = load i64, i64* %4
%37 = shl i64 %36, 10
store i64 %37, i64* %2
br label %54
38: ; preds = %30
%39 = load i64, i64* %4
%40 = shl i64 %39, 20
store i64 %40, i64* %2
br label %54
41: ; preds = %30
%42 = load i64, i64* %4
%43 = shl i64 %42, 30
store i64 %43, i64* %2
br label %54
44: ; preds = %30
%45 = load i64, i64* %4
%46 = shl i64 %45, 40
store i64 %46, i64* %2
br label %54
47: ; preds = %30
%48 = load i64, i64* %4
%49 = shl i64 %48, 50
store i64 %49, i64* %2
br label %54
50: ; preds = %30
%51 = load i64, i64* %4
%52 = shl i64 %51, 60
store i64 %52, i64* %2
br label %54
53: ; preds = %30
store i64 -1, i64* %2
br label %54
54: ; preds = %53, %50, %47, %44, %41, %38, %35, %29, %21, %15
%55 = load i64, i64* %2
ret i64 %55
}

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 ], [ -1, %16 ]
ret i64 %31
}