#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*/ next_move(int, int, char **, int, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  int pos[2], i, m, n;
  char board[50][50], line[50];
  scanf("%d", &pos[0]);
  scanf("%d", &pos[1]);
  scanf("%d %d", &m, &n);
  for (i = 0; i < m; i++) {
    scanf("%s[^\\n]%*c", line);
    strncpy(board[i], line, n);
  }
  next_move(pos[0], pos[1], board, m, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0xc(%rbp),%rsi
add    $0x4,%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe8f(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d7 <main+0xa7>
lea    -0xa20(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x10(%rbp),%rax
lea    -0x9e0(%rbp),%rdi
imul   $0x32,%rax,%rax
add    %rax,%rdi
lea    -0xa20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <main+0x57>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x9e0(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <next_move@plt>
xor    %eax,%eax
add    $0xa20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa18,%rsp
lea    0xebe(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe96(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    11cd <main+0x9d>
lea    0x50(%rsp),%r12
lea    0xe79(%rip),%r14
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%rsp),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rcx
add    $0x32,%r12
cmp    %rcx,%rbx
jl     11a0 <main+0x70>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
mov    (%rsp),%r8d
lea    0x50(%rsp),%rdx
call   1040 <next_move@plt>
xor    %eax,%eax
add    $0xa18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [11 x i8] c"%s[^\\n]%*c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [50 x [50 x i8]]
%7 = alloca [50 x i8]
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %10)
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
store i32 0, i32* %3
br label %13
13: ; preds = %27, %0
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [50 x [50 x i8]], [50 x [50 x i8]]* %6, i64 0, i64 %21
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %22, i64 0, i64 0
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @strncpy(i8* %23, i8* %24, i32 %25)
br label %27
27: ; preds = %17
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %13
30: ; preds = %13
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds [50 x [50 x i8]], [50 x [50 x i8]]* %6, i64 0, i64 0
%36 = bitcast [50 x i8]* %35 to i8**
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 @next_move(i32 %32, i32 %34, i8** %36, i32 %37, i32 %38)
ret i32 0
}

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