#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 */
scalar_t__ isdigit(char);
long getnum(char *cp) {
  long value;
  if (!isdigit(*cp))
    return -1;
  value = 0;
  while (isdigit(*cp))
    value = value * 10 + *cp++ - '0';
  switch (*cp++) {
  case 'k':
    value *= 1024;
    break;
  case 'b':
    value *= 512;
    break;
  case 'w':
    value *= 2;
    break;
  case '\0':
    return value;
  default:
    return -1;
  }
  if (*cp)
    return -1;
  return value;
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    113f <getnum+0x2f>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1249 <getnum+0x139>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1185 <getnum+0x75>
imul   $0xa,-0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbq (%rcx),%rcx
add    %rcx,%rax
sub    $0x30,%rax
mov    %rax,-0x18(%rbp)
jmp    1147 <getnum+0x37>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     120d <getnum+0xfd>
jmp    11a7 <getnum+0x97>
mov    -0x1c(%rbp),%eax
sub    $0x62,%eax
je     11eb <getnum+0xdb>
jmp    11b8 <getnum+0xa8>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     11da <getnum+0xca>
jmp    11c9 <getnum+0xb9>
mov    -0x1c(%rbp),%eax
sub    $0x77,%eax
je     11fc <getnum+0xec>
jmp    121a <getnum+0x10a>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1227 <getnum+0x117>
mov    -0x18(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x18(%rbp)
jmp    1227 <getnum+0x117>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1227 <getnum+0x117>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <getnum+0x139>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1249 <getnum+0x139>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1241 <getnum+0x131>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1249 <getnum+0x139>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
mov    $0xffffffffffffffff,%r14
test   %rax,%rax
je     11a8 <getnum+0x98>
movsbl (%r15),%edi
call   1030 <isdigit@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1165 <getnum+0x55>
mov    %r15,%rcx
nop
lea    (%rbx,%rbx,4),%rax
lea    0x1(%rcx),%r15
movsbq (%rcx),%rdx
lea    (%rdx,%rax,2),%rbx
add    $0xffffffffffffffd0,%rbx
movsbl 0x1(%rcx),%edi
call   1030 <isdigit@plt>
mov    %r15,%rcx
test   %rax,%rax
jne    1140 <getnum+0x30>
movsbl (%r15),%eax
cmp    $0x6a,%eax
jg     117e <getnum+0x6e>
test   %eax,%eax
je     118f <getnum+0x7f>
cmp    $0x62,%eax
jne    11a8 <getnum+0x98>
mov    $0x9,%ecx
jmp    1199 <getnum+0x89>
cmp    $0x6b,%eax
je     1194 <getnum+0x84>
cmp    $0x77,%eax
jne    11a8 <getnum+0x98>
mov    $0x1,%ecx
jmp    1199 <getnum+0x89>
mov    %rbx,%r14
jmp    11a8 <getnum+0x98>
mov    $0xa,%ecx
shl    %cl,%rbx
xor    %eax,%eax
cmp    0x1(%r15),%al
sbb    %r14,%r14
or     %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @getnum(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = call i64 @isdigit(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i64 -1, i64* %2
br label %49
10: ; preds = %1
store i64 0, i64* %4
br label %11
11: ; preds = %16, %10
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = load i64, i64* %4
%18 = mul nsw i64 %17, 10
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %19
%22 = sext i8 %21 to i64
%23 = add nsw i64 %18, %22
%24 = sub nsw i64 %23, 48
store i64 %24, i64* %4
br label %11
25: ; preds = %11
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
switch i32 %29, label %41 [
i32 107, label %30
i32 98, label %33
i32 119, label %36
i32 0, label %39
]
30: ; preds = %25
%31 = load i64, i64* %4
%32 = mul nsw i64 %31, 1024
store i64 %32, i64* %4
br label %42
33: ; preds = %25
%34 = load i64, i64* %4
%35 = mul nsw i64 %34, 512
store i64 %35, i64* %4
br label %42
36: ; preds = %25
%37 = load i64, i64* %4
%38 = mul nsw i64 %37, 2
store i64 %38, i64* %4
br label %42
39: ; preds = %25
%40 = load i64, i64* %4
store i64 %40, i64* %2
br label %49
41: ; preds = %25
store i64 -1, i64* %2
br label %49
42: ; preds = %36, %33, %30
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i64 -1, i64* %2
br label %49
47: ; preds = %42
%48 = load i64, i64* %4
store i64 %48, i64* %2
br label %49
49: ; preds = %47, %46, %41, %39, %9
%50 = load i64, i64* %2
ret i64 %50
}

LLVM IR (-O2):
define i64 @getnum(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @isdigit(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %36, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = tail call i64 @isdigit(i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %5, %9
%10 = phi i64 [ %17, %9 ], [ 0, %5 ]
%11 = phi i8* [ %13, %9 ], [ %0, %5 ]
%12 = mul nsw i64 %10, 10
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = load i8, i8* %11
%15 = sext i8 %14 to i64
%16 = add i64 %12, -48
%17 = add i64 %16, %15
%18 = load i8, i8* %13
%19 = tail call i64 @isdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %9, %5
%22 = phi i8* [ %0, %5 ], [ %13, %9 ]
%23 = phi i64 [ 0, %5 ], [ %17, %9 ]
%24 = getelementptr inbounds i8, i8* %22, i64 1
%25 = load i8, i8* %22
%26 = sext i8 %25 to i32
switch i32 %26, label %29 [
i32 107, label %30
i32 98, label %27
i32 119, label %28
i32 0, label %36
]
27: ; preds = %21
br label %30
28: ; preds = %21
br label %30
29: ; preds = %21
br label %36
30: ; preds = %21, %28, %27
%31 = phi i64 [ 1, %28 ], [ 9, %27 ], [ 10, %21 ]
%32 = shl nsw i64 %23, %31
%33 = load i8, i8* %24
%34 = icmp eq i8 %33, 0
%35 = select i1 %34, i64 %32, i64 -1
br label %36
36: ; preds = %30, %21, %1, %29
%37 = phi i64 [ -1, %29 ], [ -1, %1 ], [ %23, %21 ], [ %35, %30 ]
ret i64 %37
}