#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*/ printf(char *, char const *, char);
int apply_size_suffix(int val, char suffix, const char *errmsg) {
  switch (suffix) {
  case 'K':
    return val * 1024;
  case 'M':
    return val * 1024 * 1024;
  default:
    printf("%s: Unknown suffix '%c'\n", errmsg, suffix);
    return -1;
  }
}


x86 assembly (clang, -O0):
<apply_size_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x4b,%eax
je     114b <apply_size_suffix+0x3b>
jmp    113a <apply_size_suffix+0x2a>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     1159 <apply_size_suffix+0x49>
jmp    116a <apply_size_suffix+0x5a>
mov    -0x8(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <apply_size_suffix+0x75>
mov    -0x8(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <apply_size_suffix+0x75>
mov    -0x18(%rbp),%rsi
lea    0xe8b(%rip),%rdi
movsbl -0x9(%rbp),%edx
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_size_suffix>:
mov    %edi,%eax
cmp    $0x4d,%esi
je     1120 <apply_size_suffix+0x10>
cmp    $0x4b,%esi
jne    1124 <apply_size_suffix+0x14>
shl    $0xa,%eax
ret
shl    $0x14,%eax
ret
push   %rax
movsbl %sil,%eax
lea    0xed0(%rip),%rdi
mov    %rdx,%rsi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"%s: Unknown suffix '%c'\0A\00"
define i32 @apply_size_suffix(i32 %0, i8 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8* %2, i8** %7
%8 = load i8, i8* %6
%9 = sext i8 %8 to i32
switch i32 %9, label %17 [
i32 75, label %10
i32 77, label %13
]
10: ; preds = %3
%11 = load i32, i32* %5
%12 = mul nsw i32 %11, 1024
store i32 %12, i32* %4
br label %21
13: ; preds = %3
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 1024
%16 = mul nsw i32 %15, 1024
store i32 %16, i32* %4
br label %21
17: ; preds = %3
%18 = load i8*, i8** %7
%19 = load i8, i8* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18, i8 signext %19)
store i32 -1, i32* %4
br label %21
21: ; preds = %17, %13, %10
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@.str = [25 x i8] c"%s: Unknown suffix '%c'\0A\00"
define i32 @apply_size_suffix(i32 %0, i8 signext %1, i8* %2) {
%4 = sext i8 %1 to i32
switch i32 %4, label %9 [
i32 75, label %5
i32 77, label %7
]
5: ; preds = %3
%6 = shl nsw i32 %0, 10
br label %11
7: ; preds = %3
%8 = shl nsw i32 %0, 20
br label %11
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %2, i8 signext %1)
br label %11
11: ; preds = %9, %7, %5
%12 = phi i32 [ -1, %9 ], [ %8, %7 ], [ %6, %5 ]
ret i32 %12
}