#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 */
int sscanf(char const *, char *, long *, char *);
long get_num(const char *str) {
  long n;
  char c;
  int ret = sscanf(str, "%ld%c", &n, &c);
  if (ret < 1 || n < 0)
    return -1;
  if (ret == 2)
    switch (c) {
    case 'b':
    case 'B':
    case '\n':
      break;
    case 'k':
    case 'K':
      n = n << 10;
      break;
    case 'm':
    case 'M':
      n = n << 20;
      break;
    case 'g':
    case 'G':
      n = n << 30;
      break;
    default:
      return -1;
    }
  return n;
}


x86 assembly (clang, -O0):
<get_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed9(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x19(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jl     114c <get_num+0x3c>
cmpq   $0x0,-0x18(%rbp)
jge    1159 <get_num+0x49>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1252 <get_num+0x142>
cmpl   $0x2,-0x20(%rbp)
jne    124a <get_num+0x13a>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xa,%eax
je     1200 <get_num+0xf0>
jmp    1178 <get_num+0x68>
mov    -0x24(%rbp),%eax
sub    $0x42,%eax
je     1200 <get_num+0xf0>
jmp    1189 <get_num+0x79>
mov    -0x24(%rbp),%eax
sub    $0x47,%eax
je     1227 <get_num+0x117>
jmp    119a <get_num+0x8a>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     1205 <get_num+0xf5>
jmp    11ab <get_num+0x9b>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     1216 <get_num+0x106>
jmp    11bc <get_num+0xac>
mov    -0x24(%rbp),%eax
sub    $0x62,%eax
je     1200 <get_num+0xf0>
jmp    11cd <get_num+0xbd>
mov    -0x24(%rbp),%eax
sub    $0x67,%eax
je     1227 <get_num+0x117>
jmp    11de <get_num+0xce>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     1205 <get_num+0xf5>
jmp    11ef <get_num+0xdf>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
je     1216 <get_num+0x106>
jmp    1238 <get_num+0x128>
jmp    1245 <get_num+0x135>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <get_num+0x135>
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <get_num+0x135>
mov    -0x18(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <get_num+0x135>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1252 <get_num+0x142>
jmp    124a <get_num+0x13a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num>:
sub    $0x18,%rsp
lea    0xf95(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xf(%rsp),%rcx
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffffffffffff,%rax
test   %ecx,%ecx
jle    117d <get_num+0x6d>
mov    0x10(%rsp),%rdx
test   %rdx,%rdx
js     117d <get_num+0x6d>
cmp    $0x2,%ecx
jne    117a <get_num+0x6a>
movsbl 0xf(%rsp),%esi
lea    -0x42(%rsi),%ecx
cmp    $0x2b,%ecx
ja     1175 <get_num+0x65>
lea    0xea6(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
shl    $0x1e,%rdx
jmp    117a <get_num+0x6a>
shl    $0xa,%rdx
jmp    117a <get_num+0x6a>
shl    $0x14,%rdx
jmp    117a <get_num+0x6a>
cmp    $0xa,%esi
jne    117d <get_num+0x6d>
mov    %rdx,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%ld%c\00"
define i64 @get_num(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 i32 @sscanf(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %4, i8* %5)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i64, i64* %4
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %1
store i64 -1, i64* %2
br label %35
15: ; preds = %11
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
switch i32 %20, label %31 [
i32 98, label %21
i32 66, label %21
i32 10, label %21
i32 107, label %22
i32 75, label %22
i32 109, label %25
i32 77, label %25
i32 103, label %28
i32 71, label %28
]
21: ; preds = %18, %18, %18
br label %32
22: ; preds = %18, %18
%23 = load i64, i64* %4
%24 = shl i64 %23, 10
store i64 %24, i64* %4
br label %32
25: ; preds = %18, %18
%26 = load i64, i64* %4
%27 = shl i64 %26, 20
store i64 %27, i64* %4
br label %32
28: ; preds = %18, %18
%29 = load i64, i64* %4
%30 = shl i64 %29, 30
store i64 %30, i64* %4
br label %32
31: ; preds = %18
store i64 -1, i64* %2
br label %35
32: ; preds = %28, %25, %22, %21
br label %33
33: ; preds = %32, %15
%34 = load i64, i64* %4
store i64 %34, i64* %2
br label %35
35: ; preds = %33, %31, %14
%36 = load i64, i64* %2
ret i64 %36
}

LLVM IR (-O2):
@.str = [6 x i8] c"%ld%c\00"
define i64 @get_num(i8* nocapture %0) {
%2 = alloca i64
%3 = alloca i8
%4 = bitcast i64* %2 to i8*
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %2, i8* %3)
%6 = icmp slt i32 %5, 1
%7 = load i64, i64* %2
%8 = icmp slt i64 %7, 0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %23, label %10
10: ; preds = %1
%11 = icmp eq i32 %5, 2
br i1 %11, label %12, label %21
12: ; preds = %10
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
switch i32 %14, label %23 [
i32 98, label %21
i32 66, label %21
i32 10, label %21
i32 107, label %15
i32 75, label %15
i32 109, label %17
i32 77, label %17
i32 103, label %19
i32 71, label %19
]
15: ; preds = %12, %12
%16 = shl i64 %7, 10
br label %21
17: ; preds = %12, %12
%18 = shl i64 %7, 20
br label %21
19: ; preds = %12, %12
%20 = shl i64 %7, 30
br label %21
21: ; preds = %15, %17, %19, %12, %12, %12, %10
%22 = phi i64 [ %16, %15 ], [ %18, %17 ], [ %20, %19 ], [ %7, %12 ], [ %7, %12 ], [ %7, %12 ], [ %7, %10 ]
br label %23
23: ; preds = %12, %1, %21
%24 = phi i64 [ %22, %21 ], [ -1, %1 ], [ -1, %12 ]
ret i64 %24
}