#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 atol(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
scalar_t__ isalpha(char const);
int /*<<< orphan*/ stderr;
int strlen(char const *);
long argscale(const char *arg, const char *tag) {
  long value = 0;
  const char *cp = arg + strlen(arg) - 1;
  value = atol(arg);
  if (isalpha(*cp)) {
    switch (*cp) {
    case 'k':
    case 'K':
      value *= 1024;
      break;
    case 'm':
    case 'M':
      value *= (1024 * 1024);
      break;
    default:
      value = 0;
      break;
    }
  }
  if (value == 0) {
    fprintf(stderr, "Illegal %s \"%s\", ignored\n", tag, arg);
  }
  return value;
}


x86 assembly (clang, -O0):
<argscale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <atol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11fc <argscale+0xbc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffb5,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x22,%eax
ja     11ef <argscale+0xaf>
mov    -0x30(%rbp),%rax
lea    0xe3c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    11f7 <argscale+0xb7>
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
jmp    11f7 <argscale+0xb7>
movq   $0x0,-0x18(%rbp)
jmp    11fc <argscale+0xbc>
cmpq   $0x0,-0x18(%rbp)
jne    1224 <argscale+0xe4>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argscale>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%rbx
mov    %r15,%rdi
call   1060 <atol@plt>
mov    %rax,%r12
movsbl -0x1(%r15,%rbx,1),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1193 <argscale+0x53>
movsbl -0x1(%r15,%rbx,1),%eax
add    $0xffffffb5,%eax
cmp    $0x22,%eax
ja     1198 <argscale+0x58>
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
shl    $0xa,%r12
test   %r12,%r12
jne    11b6 <argscale+0x76>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xee4(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <fprintf@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
shl    $0x14,%r12
test   %r12,%r12
jne    11b6 <argscale+0x76>
jmp    1198 <argscale+0x58>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Illegal %s \22%s\22, ignored\0A\00"
define i64 @argscale(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %5
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8* %12, i8** %6
%13 = load i8*, i8** %3
%14 = call i64 @atol(i8* %13)
store i64 %14, i64* %5
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = call i64 @isalpha(i8 signext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %29 [
i32 107, label %23
i32 75, label %23
i32 109, label %26
i32 77, label %26
]
23: ; preds = %19, %19
%24 = load i64, i64* %5
%25 = mul nsw i64 %24, 1024
store i64 %25, i64* %5
br label %30
26: ; preds = %19, %19
%27 = load i64, i64* %5
%28 = mul nsw i64 %27, 1048576
store i64 %28, i64* %5
br label %30
29: ; preds = %19
store i64 0, i64* %5
br label %30
30: ; preds = %29, %26, %23
br label %31
31: ; preds = %30, %2
%32 = load i64, i64* %5
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %4
%37 = load i8*, i8** %3
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %37)
br label %39
39: ; preds = %34, %31
%40 = load i64, i64* %5
ret i64 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Illegal %s \22%s\22, ignored\0A\00"
define i64 @argscale(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = tail call i64 @atol(i8* %0)
%8 = load i8, i8* %6
%9 = tail call i64 @isalpha(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = load i8, i8* %6
%13 = sext i8 %12 to i32
switch i32 %13, label %21 [
i32 107, label %14
i32 75, label %14
i32 109, label %16
i32 77, label %16
]
14: ; preds = %11, %11
%15 = shl nsw i64 %7, 10
br label %18
16: ; preds = %11, %11
%17 = shl nsw i64 %7, 20
br label %18
18: ; preds = %14, %16, %2
%19 = phi i64 [ %17, %16 ], [ %15, %14 ], [ %7, %2 ]
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %11, %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %24
24: ; preds = %21, %18
%25 = phi i64 [ 0, %21 ], [ %19, %18 ]
ret i64 %25
}