#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*/ move(char **, int *, int *, int, int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readin(char **, int *, int *);
int scanf(char *, char *);
int /*<<< orphan*/ showpuzzle(char **);
int main() {
  int x, y, T = 0;
  char puzzle[5][5], command, flag;
  while (scanf("%c", &puzzle[0][0]), puzzle[0][0] != 'Z') {
    if (T)
      printf("\n");
    printf("Puzzle #%d:\n", ++T);
    if (puzzle[0][0] == ' ')
      x = y = 0;
    readin(puzzle, &x, &y);
    flag = 1;
    while (scanf("%c", &command), command != '0') {
      if (flag) {
        switch (command) {
        case 'A':
          move(puzzle, &x, &y, -1, 0, &flag);
          break;
        case 'B':
          move(puzzle, &x, &y, 1, 0, &flag);
          break;
        case 'L':
          move(puzzle, &x, &y, 0, -1, &flag);
          break;
        case 'R':
          move(puzzle, &x, &y, 0, 1, &flag);
          break;
        case '\n':
          break;
        default:
          flag = 0;
        }
      }
    }
    getchar();
    if (flag)
      showpuzzle(puzzle);
    else
      printf("This puzzle has no final configuration.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1060 <scanf@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x5a,%eax
je     133f <main+0x1df>
cmpl   $0x0,-0x10(%rbp)
je     11ab <main+0x4b>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x20,%eax
jne    11dd <main+0x7d>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1070 <readin@plt>
movb   $0x1,-0x32(%rbp)
lea    0xe07(%rip),%rdi
lea    -0x31(%rbp),%rsi
call   1060 <scanf@plt>
movsbl -0x31(%rbp),%eax
cmp    $0x30,%eax
je     130d <main+0x1ad>
cmpb   $0x0,-0x32(%rbp)
je     1308 <main+0x1a8>
movsbl -0x31(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0xa,%eax
je     12fa <main+0x19a>
jmp    122e <main+0xce>
mov    -0x38(%rbp),%eax
sub    $0x41,%eax
je     1272 <main+0x112>
jmp    123f <main+0xdf>
mov    -0x38(%rbp),%eax
sub    $0x42,%eax
je     1294 <main+0x134>
jmp    1250 <main+0xf0>
mov    -0x38(%rbp),%eax
sub    $0x4c,%eax
je     12b6 <main+0x156>
jmp    1261 <main+0x101>
mov    -0x38(%rbp),%eax
sub    $0x52,%eax
je     12d8 <main+0x178>
jmp    12ff <main+0x19f>
lea    -0x30(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
lea    -0x32(%rbp),%r9
call   1080 <move@plt>
jmp    1303 <main+0x1a3>
lea    -0x30(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x1,%ecx
xor    %r8d,%r8d
lea    -0x32(%rbp),%r9
call   1080 <move@plt>
jmp    1303 <main+0x1a3>
lea    -0x30(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
lea    -0x32(%rbp),%r9
call   1080 <move@plt>
jmp    1303 <main+0x1a3>
lea    -0x30(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
lea    -0x32(%rbp),%r9
call   1080 <move@plt>
jmp    1303 <main+0x1a3>
jmp    1303 <main+0x1a3>
movb   $0x0,-0x32(%rbp)
jmp    1308 <main+0x1a8>
jmp    11f2 <main+0x92>
mov    $0x0,%al
call   1040 <getchar@plt>
cmpb   $0x0,-0x32(%rbp)
je     132c <main+0x1cc>
lea    -0x30(%rbp),%rdi
call   1050 <showpuzzle@plt>
jmp    133a <main+0x1da>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1176 <main+0x16>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeb3(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <scanf@plt>
cmpb   $0x5a,0x10(%rsp)
jne    11b7 <main+0x37>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%r12
lea    0xe80(%rip),%rbx
lea    0x7(%rsp),%rbp
lea    0xe2c(%rip),%r15
xor    %r14d,%r14d
jmp    11fe <main+0x7e>
nopl   0x0(%rax)
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <scanf@plt>
cmpb   $0x5a,0x10(%rsp)
je     11a6 <main+0x26>
test   %r14d,%r14d
je     120d <main+0x8d>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
lea    0xe33(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x20,0x10(%rsp)
jne    1239 <main+0xb9>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
call   1090 <readin@plt>
movb   $0x1,0x6(%rsp)
jmp    126d <main+0xed>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
lea    0x6(%rsp),%r9
call   10a0 <move@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <scanf@plt>
movzbl 0x7(%rsp),%eax
cmp    $0x30,%al
je     12f0 <main+0x170>
cmpb   $0x0,0x6(%rsp)
je     126d <main+0xed>
movsbl %al,%eax
lea    -0x41(%rax),%ecx
cmp    $0x11,%ecx
ja     12ae <main+0x12e>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
mov    $0x1,%ecx
jmp    1260 <main+0xe0>
cmp    $0xa,%eax
je     126d <main+0xed>
movb   $0x0,0x6(%rsp)
jmp    126d <main+0xed>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
mov    $0xffffffff,%r8d
jmp    1263 <main+0xe3>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
jmp    1263 <main+0xe3>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmpb   $0x0,0x6(%rsp)
je     11e0 <main+0x60>
mov    %r13,%rdi
call   1070 <showpuzzle@plt>
jmp    11ec <main+0x6c>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [13 x i8] c"Puzzle #%d:\0A\00"
@.str.3 = [41 x i8] c"This puzzle has no final configuration.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x [5 x i8]]
%6 = alloca i8
%7 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %4
br label %8
8: ; preds = %77, %0
%9 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 90
br i1 %16, label %17, label %78
17: ; preds = %8
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %26, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %31, label %32
31: ; preds = %22
store i32 0, i32* %3
store i32 0, i32* %2
br label %32
32: ; preds = %31, %22
%33 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%34 = bitcast [5 x i8]* %33 to i8**
%35 = call i32 @readin(i8** %34, i32* %2, i32* %3)
store i8 1, i8* %7
br label %36
36: ; preds = %66, %32
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%38 = load i8, i8* %6
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 48
br i1 %40, label %41, label %67
41: ; preds = %36
%42 = load i8, i8* %7
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %66
44: ; preds = %41
%45 = load i8, i8* %6
%46 = sext i8 %45 to i32
switch i32 %46, label %64 [
i32 65, label %47
i32 66, label %51
i32 76, label %55
i32 82, label %59
i32 10, label %63
]
47: ; preds = %44
%48 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%49 = bitcast [5 x i8]* %48 to i8**
%50 = call i32 @move(i8** %49, i32* %2, i32* %3, i32 -1, i32 0, i8* %7)
br label %65
51: ; preds = %44
%52 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%53 = bitcast [5 x i8]* %52 to i8**
%54 = call i32 @move(i8** %53, i32* %2, i32* %3, i32 1, i32 0, i8* %7)
br label %65
55: ; preds = %44
%56 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%57 = bitcast [5 x i8]* %56 to i8**
%58 = call i32 @move(i8** %57, i32* %2, i32* %3, i32 0, i32 -1, i8* %7)
br label %65
59: ; preds = %44
%60 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%61 = bitcast [5 x i8]* %60 to i8**
%62 = call i32 @move(i8** %61, i32* %2, i32* %3, i32 0, i32 1, i8* %7)
br label %65
63: ; preds = %44
br label %65
64: ; preds = %44
store i8 0, i8* %7
br label %65
65: ; preds = %64, %63, %59, %55, %51, %47
br label %66
66: ; preds = %65, %41
br label %36
67: ; preds = %36
%68 = call i32 (...) @getchar()
%69 = load i8, i8* %7
%70 = icmp ne i8 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 0
%73 = bitcast [5 x i8]* %72 to i8**
%74 = call i32 @showpuzzle(i8** %73)
br label %77
75: ; preds = %67
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
br label %8
78: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.2 = [13 x i8] c"Puzzle #%d:\0A\00"
@str = [40 x i8] c"This puzzle has no final configuration.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x [5 x i8]]
%4 = alloca i8
%5 = alloca i8
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %3, i64 0, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8, i8* %8
%11 = icmp eq i8 %10, 90
br i1 %11, label %61, label %12
12: ; preds = %0
%13 = bitcast [5 x [5 x i8]]* %3 to i8**
br label %14
14: ; preds = %12, %57
%15 = phi i32 [ 0, %12 ], [ %20, %57 ]
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @putchar(i32 10)
br label %19
19: ; preds = %17, %14
%20 = add nuw nsw i32 %15, 1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i8, i8* %8
%23 = icmp eq i8 %22, 32
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %2
store i32 0, i32* %1
br label %25
25: ; preds = %24, %19
%26 = call i32 @readin(i8** %13, i32* %1, i32* %2)
store i8 1, i8* %5
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%28 = load i8, i8* %4
%29 = icmp eq i8 %28, 48
br i1 %29, label %49, label %30
30: ; preds = %25, %45
%31 = phi i8 [ %47, %45 ], [ %28, %25 ]
%32 = load i8, i8* %5
%33 = icmp eq i8 %32, 0
br i1 %33, label %45, label %34
34: ; preds = %30
%35 = sext i8 %31 to i32
switch i32 %35, label %44 [
i32 65, label %36
i32 66, label %38
i32 76, label %40
i32 82, label %42
i32 10, label %45
]
36: ; preds = %34
%37 = call i32 @move(i8** %13, i32* %1, i32* %2, i32 -1, i32 0, i8* %5)
br label %45
38: ; preds = %34
%39 = call i32 @move(i8** %13, i32* %1, i32* %2, i32 1, i32 0, i8* %5)
br label %45
40: ; preds = %34
%41 = call i32 @move(i8** %13, i32* %1, i32* %2, i32 0, i32 -1, i8* %5)
br label %45
42: ; preds = %34
%43 = call i32 @move(i8** %13, i32* %1, i32* %2, i32 0, i32 1, i8* %5)
br label %45
44: ; preds = %34
store i8 0, i8* %5
br label %45
45: ; preds = %36, %38, %40, %42, %34, %44, %30
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%47 = load i8, i8* %4
%48 = icmp eq i8 %47, 48
br i1 %48, label %49, label %30
49: ; preds = %45, %25
%50 = call i32 (...) @getchar()
%51 = load i8, i8* %5
%52 = icmp eq i8 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = call i32 @showpuzzle(i8** %13)
br label %57
55: ; preds = %49
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %57
57: ; preds = %55, %53
%58 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%59 = load i8, i8* %8
%60 = icmp eq i8 %59, 90
br i1 %60, label %61, label %14
61: ; preds = %57, %0
ret i32 0
}