#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int main() {
  int num_cases, i, count;
  int key_press[26] = {1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
                       2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4};
  char line[128], *ptr;
  fgets(line, 128, stdin);
  sscanf(line, "%d\n", &num_cases);
  for (i = 1; i <= num_cases; i++) {
    fgets(line, 128, stdin);
    count = 0;
    for (ptr = &line[0]; *ptr != '\n'; ptr++) {
      switch (*ptr) {
      case ' ':
        count++;
        break;
      default:
        count += key_press[*ptr - 'a'];
        break;
      }
    }
    printf("Case #%d: %d\n", i, count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x68,%edx
call   1050 <memcpy@plt>
lea    -0x100(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
lea    -0x100(%rbp),%rdi
lea    0xee3(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1060 <sscanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1266 <main+0x126>
lea    -0x100(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x10(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1246 <main+0x106>
mov    -0x108(%rbp),%rax
mov    (%rax),%al
sub    $0x20,%al
jne    1211 <main+0xd1>
jmp    1203 <main+0xc3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122a <main+0xea>
mov    -0x108(%rbp),%rax
movsbl (%rax),%eax
sub    $0x61,%eax
cltq
mov    -0x80(%rbp,%rax,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    122f <main+0xef>
mov    -0x108(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x108(%rbp)
jmp    11da <main+0x9a>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119f <main+0x5f>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    0x2ea1(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
lea    0xf0e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1050 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11f3 <main+0xc3>
mov    $0x1,%r13d
lea    0xee3(%rip),%r15
lea    0xe74(%rip),%rbx
jmp    11a9 <main+0x79>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
lea    0x1(%r13),%eax
cmp    0xc(%rsp),%r13d
mov    %eax,%r13d
jge    11f3 <main+0xc3>
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
xor    %edx,%edx
mov    %r14,%rax
jmp    11d7 <main+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%edx
add    $0x1,%rax
movsbq (%rax),%rcx
cmp    $0x20,%rcx
je     11d0 <main+0xa0>
cmp    $0xa,%cl
je     1190 <main+0x60>
add    -0x184(%rbx,%rcx,4),%edx
add    $0x1,%rax
jmp    11d7 <main+0xa7>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.main.key_press = [26 x i32] [i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 4, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 4]
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [14 x i8] c"Case #%d: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 128, i32 %5)
%7 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %34, label %10
10: ; preds = %0, %29
%11 = phi i32 [ %31, %29 ], [ 1, %0 ]
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %4, i32 128, i32 %12)
br label %14
14: ; preds = %26, %10
%15 = phi i32 [ 0, %10 ], [ %27, %26 ]
%16 = phi i8* [ %4, %10 ], [ %28, %26 ]
%17 = load i8, i8* %16
switch i8 %17, label %20 [
i8 10, label %29
i8 32, label %18
]
18: ; preds = %14
%19 = add nsw i32 %15, 1
br label %26
20: ; preds = %14
%21 = sext i8 %17 to i64
%22 = add nsw i64 %21, -97
%23 = getelementptr inbounds [26 x i32], [26 x i32]* @__const.main.key_press, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %15
br label %26
26: ; preds = %18, %20
%27 = phi i32 [ %19, %18 ], [ %25, %20 ]
%28 = getelementptr inbounds i8, i8* %16, i64 1
br label %14
29: ; preds = %14
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %15)
%31 = add nuw nsw i32 %11, 1
%32 = load i32, i32* %1
%33 = icmp slt i32 %11, %32
br i1 %33, label %10, label %34
34: ; preds = %29, %0
ret i32 0
}