#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 asctol(char *);
int /*<<< orphan*/ isdigit(int);
int strlen(char *);
int /*<<< orphan*/ usage(int);
long get_size_k(char *s) {
  int c;
  long n;
  c = s[strlen(s) - 1];
  n = asctol(s);
  if (c == 'M' || c == 'm')
    n *= 1024L;
  else if (!isdigit(c))
    usage(1);
  return n * 1024;
}


x86 assembly (clang, -O0):
<get_size_k>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <asctol@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x4d,-0xc(%rbp)
je     1191 <get_size_k+0x51>
cmpl   $0x6d,-0xc(%rbp)
jne    11a2 <get_size_k+0x62>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    11c2 <get_size_k+0x82>
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11bd <get_size_k+0x7d>
mov    $0x1,%edi
call   1060 <usage@plt>
jmp    11c2 <get_size_k+0x82>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_size_k>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%ebp
mov    %rbx,%rdi
call   1040 <asctol@plt>
mov    %rax,%rbx
mov    %ebp,%eax
and    $0xdf,%al
cmp    $0x4d,%al
jne    115b <get_size_k+0x2b>
shl    $0xa,%rbx
jmp    116d <get_size_k+0x3d>
add    $0xffffffd0,%ebp
cmp    $0xa,%ebp
jb     116d <get_size_k+0x3d>
mov    $0x1,%edi
call   1050 <usage@plt>
shl    $0xa,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @get_size_k(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %5, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %3
%13 = load i8*, i8** %2
%14 = call i64 @asctol(i8* %13)
store i64 %14, i64* %4
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 77
br i1 %16, label %20, label %17
17: ; preds = %1
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 109
br i1 %19, label %20, label %23
20: ; preds = %17, %1
%21 = load i64, i64* %4
%22 = mul nsw i64 %21, 1024
store i64 %22, i64* %4
br label %30
23: ; preds = %17
%24 = load i32, i32* %3
%25 = call i32 @isdigit(i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @usage(i32 1)
br label %29
29: ; preds = %27, %23
br label %30
30: ; preds = %29, %20
%31 = load i64, i64* %4
%32 = mul nsw i64 %31, 1024
ret i64 %32
}

LLVM IR (-O2):
define i64 @get_size_k(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = tail call i64 @asctol(i8* %0)
%8 = and i8 %6, -33
%9 = icmp eq i8 %8, 77
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = shl nsw i64 %7, 10
br label %18
12: ; preds = %1
%13 = sext i8 %6 to i32
%14 = add nsw i32 %13, -48
%15 = icmp ult i32 %14, 10
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @usage(i32 1)
br label %18
18: ; preds = %12, %16, %10
%19 = phi i64 [ %11, %10 ], [ %7, %12 ], [ %7, %16 ]
%20 = shl nsw i64 %19, 10
ret i64 %20
}