#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*/ getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  char cmd[32], cityName[32];
  char code;
  int miles = 0, result = 0;
  char term[2] = "#\0";
  char endline[2] = "0\0";
  while (1) {
    scanf("%s", &cmd[0]);
    if (!strcmp(cmd, term))
      break;
    else if (!strcmp(cmd, endline)) {
      getchar();
      printf("%d\n", result);
      result = 0;
    } else {
      scanf("%s %d %c", &cityName[0], &miles, &code);
      getchar();
      switch (code) {
      case 'F':
        result += miles * 2;
        break;
      case 'B':
        result = result + miles + (miles + 1) / 2;
        break;
      case 'Y':
        if (miles <= 500)
          result += 500;
        else
          result += miles;
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    0xe9c(%rip),%ax
mov    %ax,-0x5e(%rbp)
mov    0xe93(%rip),%ax
mov    %ax,-0x60(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x5e(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a0 <main+0x60>
jmp    12a5 <main+0x165>
lea    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11d8 <main+0x98>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x5c(%rbp),%esi
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x5c(%rbp)
jmp    129b <main+0x15b>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x65(%rbp)
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x51(%rbp),%rcx
call   1060 <scanf@plt>
mov    -0x65(%rbp),%al
call   1050 <getchar@plt>
movsbl -0x51(%rbp),%eax
mov    %eax,-0x64(%rbp)
sub    $0x42,%eax
je     1245 <main+0x105>
jmp    1212 <main+0xd2>
mov    -0x64(%rbp),%eax
sub    $0x46,%eax
je     1234 <main+0xf4>
jmp    1223 <main+0xe3>
mov    -0x64(%rbp),%eax
sub    $0x59,%eax
je     126b <main+0x12b>
jmp    1296 <main+0x156>
mov    -0x58(%rbp),%eax
shl    $0x1,%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1296 <main+0x156>
mov    -0x5c(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x5c(%rbp)
jmp    1296 <main+0x156>
cmpl   $0x1f4,-0x58(%rbp)
jg     1288 <main+0x148>
mov    -0x5c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x5c(%rbp)
jmp    1291 <main+0x151>
mov    -0x58(%rbp),%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1296 <main+0x156>
jmp    129b <main+0x15b>
jmp    12a0 <main+0x160>
jmp    1173 <main+0x33>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movl   $0x0,0x1c(%rsp)
lea    0xeb3(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xeae(%rip),%r12
lea    0x40(%rsp),%r13
lea    0x1c(%rsp),%rbp
lea    0xf(%rsp),%r15
xor    %eax,%eax
mov    %rax,0x10(%rsp)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movzwl 0x20(%rsp),%eax
cmp    $0x23,%ax
je     125d <main+0x12d>
cmp    $0x30,%ax
je     1240 <main+0x110>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl 0xf(%rsp),%eax
cmp    $0x42,%eax
je     11e0 <main+0xb0>
cmp    $0x59,%eax
je     1210 <main+0xe0>
cmp    $0x46,%eax
jne    1170 <main+0x40>
mov    0x1c(%rsp),%eax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,2),%ecx
mov    %rcx,0x10(%rsp)
jmp    1170 <main+0x40>
nopw   0x0(%rax,%rax,1)
mov    0x1c(%rsp),%eax
mov    0x10(%rsp),%rdx
add    %eax,%edx
mov    %eax,%ecx
add    $0x1,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
add    $0x1,%eax
sar    %eax
add    %edx,%eax
jmp    116a <main+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x1c(%rsp),%eax
cmp    $0x1f4,%eax
jg     122a <main+0xfa>
mov    0x10(%rsp),%rax
add    $0x1f4,%eax
jmp    116a <main+0x3a>
add    0x10(%rsp),%eax
jmp    116a <main+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
lea    0xdb5(%rip),%rdi
mov    0x10(%rsp),%rsi
call   1030 <printf@plt>
jmp    1168 <main+0x38>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.term = [2 x i8] c"#\00"
@__const.main.endline = [2 x i8] c"0\00"
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [9 x i8] c"%s %d %c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8]
%8 = alloca [2 x i8]
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%9 = bitcast [2 x i8]* %7 to i8*
%10 = bitcast [2 x i8]* %8 to i8*
br label %11
11: ; preds = %0, %60
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%16 = call i32 @strcmp(i8* %14, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %11
br label %61
19: ; preds = %11
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%22 = call i32 @strcmp(i8* %20, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = call i32 (...) @getchar()
%26 = load i32, i32* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i32 0, i32* %6
br label %59
28: ; preds = %19
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%30 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32* %5, i8* %4)
%31 = call i32 (...) @getchar()
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
switch i32 %33, label %58 [
i32 70, label %34
i32 66, label %39
i32 89, label %47
]
34: ; preds = %28
%35 = load i32, i32* %5
%36 = mul nsw i32 %35, 2
%37 = load i32, i32* %6
%38 = add nsw i32 %37, %36
store i32 %38, i32* %6
br label %58
39: ; preds = %28
%40 = load i32, i32* %6
%41 = load i32, i32* %5
%42 = add nsw i32 %40, %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
%45 = sdiv i32 %44, 2
%46 = add nsw i32 %42, %45
store i32 %46, i32* %6
br label %58
47: ; preds = %28
%48 = load i32, i32* %5
%49 = icmp sle i32 %48, 500
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 500
store i32 %52, i32* %6
br label %57
53: ; preds = %47
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = add nsw i32 %55, %54
store i32 %56, i32* %6
br label %57
57: ; preds = %53, %50
br label %58
58: ; preds = %28, %57, %39, %34
br label %59
59: ; preds = %58, %24
br label %60
60: ; preds = %59
br label %11
61: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [9 x i8] c"%s %d %c\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = bitcast [32 x i8]* %1 to i16*
br label %9
9: ; preds = %37, %0
%10 = phi i32 [ 0, %0 ], [ %38, %37 ]
br label %11
11: ; preds = %9, %17
%12 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%13 = load i16, i16* %8
switch i16 %13, label %17 [
i16 35, label %41
i16 48, label %14
]
14: ; preds = %11
%15 = call i32 (...) @getchar()
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %37
17: ; preds = %11
%18 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32* %4, i8* %3)
%19 = call i32 (...) @getchar()
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
switch i32 %21, label %11 [
i32 70, label %22
i32 66, label %26
i32 89, label %32
]
22: ; preds = %17
%23 = load i32, i32* %4
%24 = shl nsw i32 %23, 1
%25 = add nsw i32 %24, %10
br label %37
26: ; preds = %17
%27 = load i32, i32* %4
%28 = add nsw i32 %27, %10
%29 = add nsw i32 %27, 1
%30 = sdiv i32 %29, 2
%31 = add nsw i32 %28, %30
br label %37
32: ; preds = %17
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 501
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = add nsw i32 %10, 500
br label %37
37: ; preds = %35, %39, %26, %22, %14
%38 = phi i32 [ 0, %14 ], [ %25, %22 ], [ %31, %26 ], [ %40, %39 ], [ %36, %35 ]
br label %9
39: ; preds = %32
%40 = add nsw i32 %33, %10
br label %37
41: ; preds = %11
ret i32 0
}