#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 */
unsigned long long strtol(char *, char **, int);
unsigned long long argtol(char *s) {
  char *p;
  unsigned long long n = strtol(s, &p, 10), f = 1;
  switch (*p) {
  case 'K':
    f = 1000;
    break;
  case 'M':
    f = 1000000;
    break;
  case 'G':
    f = 1000000000;
    break;
  case 'k':
    f = (1u << 10);
    break;
  case 'm':
    f = (1u << 20);
    break;
  case 'g':
    f = (1u << 30);
    break;
  case 'b':
    return 1u << n;
  default:
    f = 1000000;
  }
  return n * f;
}


x86 assembly (clang, -O0):
<argtol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x26,%eax
ja     11cd <argtol+0xbd>
mov    -0x30(%rbp),%rax
lea    0xea2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x3e8,-0x28(%rbp)
jmp    11d5 <argtol+0xc5>
movq   $0xf4240,-0x28(%rbp)
jmp    11d5 <argtol+0xc5>
movq   $0x3b9aca00,-0x28(%rbp)
3b
jmp    11d5 <argtol+0xc5>
movq   $0x400,-0x28(%rbp)
jmp    11d5 <argtol+0xc5>
movq   $0x100000,-0x28(%rbp)
jmp    11d5 <argtol+0xc5>
movq   $0x40000000,-0x28(%rbp)
40
jmp    11d5 <argtol+0xc5>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%eax
mov    %rax,-0x8(%rbp)
jmp    11e2 <argtol+0xd2>
movq   $0xf4240,-0x28(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argtol>:
push   %rax
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    (%rsp),%rcx
movsbl (%rcx),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     1142 <argtol+0x32>
mov    $0x3e8,%edx
lea    0xec7(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
mov    $0xf4240,%edx
jmp    116e <argtol+0x5e>
mov    $0x3b9aca00,%edx
jmp    116e <argtol+0x5e>
mov    $0x1,%edx
mov    %eax,%ecx
shl    %cl,%edx
jmp    1172 <argtol+0x62>
mov    $0x400,%edx
jmp    116e <argtol+0x5e>
mov    $0x100000,%edx
jmp    116e <argtol+0x5e>
mov    $0x40000000,%edx
imul   %rax,%rdx
mov    %rdx,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @argtol(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strtol(i8* %7, i8** %4, i32 10)
store i64 %8, i64* %5
store i64 1, i64* %6
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %23 [
i32 75, label %12
i32 77, label %13
i32 71, label %14
i32 107, label %15
i32 109, label %16
i32 103, label %17
i32 98, label %18
]
12: ; preds = %1
store i64 1000, i64* %6
br label %24
13: ; preds = %1
store i64 1000000, i64* %6
br label %24
14: ; preds = %1
store i64 1000000000, i64* %6
br label %24
15: ; preds = %1
store i64 1024, i64* %6
br label %24
16: ; preds = %1
store i64 1048576, i64* %6
br label %24
17: ; preds = %1
store i64 1073741824, i64* %6
br label %24
18: ; preds = %1
%19 = load i64, i64* %5
%20 = trunc i64 %19 to i32
%21 = shl i32 1, %20
%22 = zext i32 %21 to i64
store i64 %22, i64* %2
br label %28
23: ; preds = %1
store i64 1000000, i64* %6
br label %24
24: ; preds = %23, %17, %16, %15, %14, %13, %12
%25 = load i64, i64* %5
%26 = load i64, i64* %6
%27 = mul i64 %25, %26
store i64 %27, i64* %2
br label %28
28: ; preds = %24, %18
%29 = load i64, i64* %2
ret i64 %29
}

LLVM IR (-O2):
define i64 @argtol(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %17 [
i32 75, label %18
i32 77, label %8
i32 71, label %9
i32 107, label %10
i32 109, label %11
i32 103, label %12
i32 98, label %13
]
8: ; preds = %1
br label %18
9: ; preds = %1
br label %18
10: ; preds = %1
br label %18
11: ; preds = %1
br label %18
12: ; preds = %1
br label %18
13: ; preds = %1
%14 = trunc i64 %4 to i32
%15 = shl nuw i32 1, %14
%16 = zext i32 %15 to i64
br label %21
17: ; preds = %1
br label %18
18: ; preds = %1, %17, %12, %11, %10, %9, %8
%19 = phi i64 [ 1000000, %17 ], [ 1073741824, %12 ], [ 1048576, %11 ], [ 1024, %10 ], [ 1000000000, %9 ], [ 1000000, %8 ], [ 1000, %1 ]
%20 = mul i64 %19, %4
br label %21
21: ; preds = %18, %13
%22 = phi i64 [ %20, %18 ], [ %16, %13 ]
ret i64 %22
}