#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned long long strtol(char const *, char **, int /*<<< orphan*/);
unsigned long long m_strtol(const char *s) {
  char *e = (char *)s;
  unsigned long long r;
  r = strtol(s, &e, 0);
  switch (*e) {
  case 0:
    return r;
  case 's':
  case 'S':
    return r << 9;
  case 'K':
  case 'k':
    return r << 10;
  case 'M':
  case 'm':
    return r << 20;
  case 'G':
  case 'g':
    return r << 30;
  default:
    fprintf(stderr, "%s is not a valid number\n", s);
    exit(20);
  }
}


x86 assembly (clang, -O0):
<m_strtol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     11f6 <m_strtol+0xc6>
jmp    116e <m_strtol+0x3e>
mov    -0x24(%rbp),%eax
sub    $0x47,%eax
je     1236 <m_strtol+0x106>
jmp    117f <m_strtol+0x4f>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     1214 <m_strtol+0xe4>
jmp    1190 <m_strtol+0x60>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     1225 <m_strtol+0xf5>
jmp    11a1 <m_strtol+0x71>
mov    -0x24(%rbp),%eax
sub    $0x53,%eax
je     1203 <m_strtol+0xd3>
jmp    11b2 <m_strtol+0x82>
mov    -0x24(%rbp),%eax
sub    $0x67,%eax
je     1236 <m_strtol+0x106>
jmp    11c3 <m_strtol+0x93>
mov    -0x24(%rbp),%eax
sub    $0x6b,%eax
je     1214 <m_strtol+0xe4>
jmp    11d4 <m_strtol+0xa4>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
je     1225 <m_strtol+0xf5>
jmp    11e5 <m_strtol+0xb5>
mov    -0x24(%rbp),%eax
sub    $0x73,%eax
je     1203 <m_strtol+0xd3>
jmp    1247 <m_strtol+0x117>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126a <m_strtol+0x13a>
mov    -0x20(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x8(%rbp)
jmp    126a <m_strtol+0x13a>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    126a <m_strtol+0x13a>
mov    -0x20(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x8(%rbp)
jmp    126a <m_strtol+0x13a>
mov    -0x20(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x8(%rbp)
jmp    126a <m_strtol+0x13a>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xda5(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x14,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_strtol>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
movsbl (%rcx),%ecx
lea    -0x47(%rcx),%edx
cmp    $0x2c,%edx
ja     1181 <m_strtol+0x51>
lea    0xea0(%rip),%rcx
movslq (%rcx,%rdx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
shl    $0x1e,%rax
jmp    1185 <m_strtol+0x55>
shl    $0xa,%rax
jmp    1185 <m_strtol+0x55>
shl    $0x14,%rax
jmp    1185 <m_strtol+0x55>
shl    $0x9,%rax
jmp    1185 <m_strtol+0x55>
test   %ecx,%ecx
jne    118b <m_strtol+0x5b>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xf19(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x14,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"%s is not a valid number\0A\00"
define i64 @m_strtol(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strtol(i8* %7, i8** %4, i32 0)
store i64 %8, i64* %5
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %26 [
i32 0, label %12
i32 115, label %14
i32 83, label %14
i32 75, label %17
i32 107, label %17
i32 77, label %20
i32 109, label %20
i32 71, label %23
i32 103, label %23
]
12: ; preds = %1
%13 = load i64, i64* %5
store i64 %13, i64* %2
br label %31
14: ; preds = %1, %1
%15 = load i64, i64* %5
%16 = shl i64 %15, 9
store i64 %16, i64* %2
br label %31
17: ; preds = %1, %1
%18 = load i64, i64* %5
%19 = shl i64 %18, 10
store i64 %19, i64* %2
br label %31
20: ; preds = %1, %1
%21 = load i64, i64* %5
%22 = shl i64 %21, 20
store i64 %22, i64* %2
br label %31
23: ; preds = %1, %1
%24 = load i64, i64* %5
%25 = shl i64 %24, 30
store i64 %25, i64* %2
br label %31
26: ; preds = %1
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 20)
unreachable
31: ; preds = %23, %20, %17, %14, %12
%32 = load i64, i64* %2
ret i64 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"%s is not a valid number\0A\00"
define i64 @m_strtol(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* %0, i8** %2
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %16 [
i32 0, label %20
i32 115, label %8
i32 83, label %8
i32 75, label %10
i32 107, label %10
i32 77, label %12
i32 109, label %12
i32 71, label %14
i32 103, label %14
]
8: ; preds = %1, %1
%9 = shl i64 %4, 9
br label %20
10: ; preds = %1, %1
%11 = shl i64 %4, 10
br label %20
12: ; preds = %1, %1
%13 = shl i64 %4, 20
br label %20
14: ; preds = %1, %1
%15 = shl i64 %4, 30
br label %20
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = tail call i32 @exit(i32 20)
unreachable
20: ; preds = %1, %14, %12, %10, %8
%21 = phi i64 [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %4, %1 ]
ret i64 %21
}