#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *, int);
void solve_part_1() {
  char direction;
  int current_button = 5;
  while ((direction = getchar()) != EOF) {
    switch (direction) {
    case 'U':
      if (current_button - 3 >= 1) {
        current_button -= 3;
      }
      break;
    case 'L':
      if (current_button % 3 != 1) {
        current_button--;
      }
      break;
    case 'D':
      if (current_button + 3 <= 9) {
        current_button += 3;
      }
      break;
    case 'R':
      if (current_button % 3 != 0) {
        current_button++;
      }
      break;
    default:
      printf("%d", current_button);
      break;
    }
  }
  printf("%d\n", current_button);
}


x86 assembly (clang, -O0):
<solve_part_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x5,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2ea5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     120a <solve_part_1+0xea>
movsbl -0x1(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x11,%eax
ja     11f6 <solve_part_1+0xd6>
mov    -0x10(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
cmp    $0x1,%eax
jl     1190 <solve_part_1+0x70>
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x8(%rbp)
jmp    1205 <solve_part_1+0xe5>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
je     11b2 <solve_part_1+0x92>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1205 <solve_part_1+0xe5>
mov    -0x8(%rbp),%eax
add    $0x3,%eax
cmp    $0x9,%eax
jg     11cf <solve_part_1+0xaf>
mov    -0x8(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x8(%rbp)
jmp    1205 <solve_part_1+0xe5>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11f1 <solve_part_1+0xd1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1205 <solve_part_1+0xe5>
mov    -0x8(%rbp),%esi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <solve_part_1+0xf>
mov    -0x8(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve_part_1>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb2(%rip),%r15
mov    $0x5,%ebx
cmp    (%r15),%al
jne    1159 <solve_part_1+0x39>
lea    0xf04(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
mov    $0x5,%ebx
lea    0xee3(%rip),%r14
lea    0xe94(%rip),%r12
jmp    118c <solve_part_1+0x6c>
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r15),%al
je     1140 <solve_part_1+0x20>
movsbl %al,%eax
add    $0xffffffbc,%eax
cmp    $0x11,%eax
ja     1170 <solve_part_1+0x50>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0x3(%rbx),%eax
cmp    $0x7,%ebx
cmovge %ebx,%eax
mov    %eax,%ebx
jmp    1180 <solve_part_1+0x60>
nopl   (%rax)
movslq %ebx,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %ebx,%ecx
sub    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
sub    %eax,%ebx
jmp    1180 <solve_part_1+0x60>
nopw   0x0(%rax,%rax,1)
imul   $0xaaaaaaab,%ebx,%eax
add    $0x2aaaaaaa,%eax
cmp    $0x55555555,%eax
sbb    $0xffffffff,%ebx
jmp    1180 <solve_part_1+0x60>
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x3(%rbx),%eax
cmp    $0x4,%ebx
cmovl  %ebx,%eax
mov    %eax,%ebx
jmp    1180 <solve_part_1+0x60>

LLVM IR (-O0):
@EOF = global i8 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @solve_part_1() {
%1 = alloca i8
%2 = alloca i32
store i32 5, i32* %2
br label %3
3: ; preds = %47, %0
%4 = call signext i8 (...) @getchar()
store i8 %4, i8* %1
%5 = sext i8 %4 to i32
%6 = load i8, i8* @EOF
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %5, %7
br i1 %8, label %9, label %48
9: ; preds = %3
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
switch i32 %11, label %44 [
i32 85, label %12
i32 76, label %20
i32 68, label %28
i32 82, label %36
]
12: ; preds = %9
%13 = load i32, i32* %2
%14 = sub nsw i32 %13, 3
%15 = icmp sge i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %2
%18 = sub nsw i32 %17, 3
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %12
br label %47
20: ; preds = %9
%21 = load i32, i32* %2
%22 = srem i32 %21, 3
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %2
%26 = add nsw i32 %25, -1
store i32 %26, i32* %2
br label %27
27: ; preds = %24, %20
br label %47
28: ; preds = %9
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 3
%31 = icmp sle i32 %30, 9
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 3
store i32 %34, i32* %2
br label %35
35: ; preds = %32, %28
br label %47
36: ; preds = %9
%37 = load i32, i32* %2
%38 = srem i32 %37, 3
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %43
43: ; preds = %40, %36
br label %47
44: ; preds = %9
%45 = load i32, i32* %2
%46 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %43, %35, %27, %19
br label %3
48: ; preds = %3
%49 = load i32, i32* %2
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %49)
ret void
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @solve_part_1() {
%1 = tail call signext i8 (...) @getchar()
%2 = load i8, i8* @EOF
%3 = icmp eq i8 %1, %2
br i1 %3, label %33, label %4
4: ; preds = %0, %28
%5 = phi i8 [ %30, %28 ], [ %1, %0 ]
%6 = phi i32 [ %29, %28 ], [ 5, %0 ]
%7 = sext i8 %5 to i32
switch i32 %7, label %26 [
i32 85, label %8
i32 76, label %12
i32 68, label %17
i32 82, label %21
]
8: ; preds = %4
%9 = icmp sgt i32 %6, 3
%10 = add nsw i32 %6, -3
%11 = select i1 %9, i32 %10, i32 %6
br label %28
12: ; preds = %4
%13 = srem i32 %6, 3
%14 = icmp ne i32 %13, 1
%15 = sext i1 %14 to i32
%16 = add nsw i32 %6, %15
br label %28
17: ; preds = %4
%18 = icmp slt i32 %6, 7
%19 = add nsw i32 %6, 3
%20 = select i1 %18, i32 %19, i32 %6
br label %28
21: ; preds = %4
%22 = srem i32 %6, 3
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
%25 = add nsw i32 %6, %24
br label %28
26: ; preds = %4
%27 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %28
28: ; preds = %21, %17, %12, %8, %26
%29 = phi i32 [ %6, %26 ], [ %11, %8 ], [ %16, %12 ], [ %20, %17 ], [ %25, %21 ]
%30 = tail call signext i8 (...) @getchar()
%31 = load i8, i8* @EOF
%32 = icmp eq i8 %30, %31
br i1 %32, label %33, label %4
33: ; preds = %28, %0
%34 = phi i32 [ 5, %0 ], [ %29, %28 ]
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
ret void
}