#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 */
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *);
float sqrt(float);
void next_move(int posr, int posc, char board[50][50], int m, int n) {
  int i, j, k, l, nexx, nexy;
  float dis, min = 100000;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (board[i][j] == 'd') {
        dis = sqrt((float)(pow(posr - i, 2) + pow(posc - j, 2)));
        if (dis < min) {
          min = dis;
          nexx = i;
          nexy = j;
        }
      }
    }
  }
  if (min == 0) {
    printf("CLEAN\n");
    board[nexx][nexy] = '-';
  } else if (nexy > posc)
    printf("RIGHT\n");
  else if (nexx > posr)
    printf("DOWN\n");
  else if (nexx < posr)
    printf("UP\n");
  else if (nexy < posc)
    printf("LEFT\n");
}


x86 assembly (clang, -O0):
<next_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movss  0xeaf(%rip),%xmm0
movss  %xmm0,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122d <next_move+0xfd>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121a <next_move+0xea>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x32,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x64,%eax
jne    1207 <next_move+0xd7>
mov    -0x4(%rbp),%edi
sub    -0x1c(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
sub    -0x20(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
cvtsi2ss %rax,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm1
movss  -0x38(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1202 <next_move+0xd2>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1207 <next_move+0xd7>
jmp    120c <next_move+0xdc>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <next_move+0x40>
jmp    121f <next_move+0xef>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <next_move+0x2d>
movss  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    126c <next_move+0x13c>
jp     126c <next_move+0x13c>
lea    0xdb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0x32,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    12ef <next_move+0x1bf>
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1289 <next_move+0x159>
lea    0xd8c(%rip),%rdi
call   1030 <printf@plt>
jmp    12ea <next_move+0x1ba>
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    12a6 <next_move+0x176>
lea    0xd76(%rip),%rdi
call   1030 <printf@plt>
jmp    12e5 <next_move+0x1b5>
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12c3 <next_move+0x193>
lea    0xd5f(%rip),%rdi
call   1030 <printf@plt>
jmp    12e0 <next_move+0x1b0>
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12db <next_move+0x1ab>
lea    0xd46(%rip),%rdi
call   1030 <printf@plt>
jmp    12e0 <next_move+0x1b0>
jmp    12e5 <next_move+0x1b5>
jmp    12ea <next_move+0x1ba>
jmp    12ef <next_move+0x1bf>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_move>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,0x4(%rsp)
mov    %edi,0xc(%rsp)
test   %ecx,%ecx
jle    126f <next_move+0x13f>
mov    %ecx,%eax
mov    %rax,0x30(%rsp)
mov    %r8d,%r13d
movss  0xea0(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rdx,%r12
mov    %r8d,0x24(%rsp)
jmp    11a5 <next_move+0x75>
nopl   0x0(%rax)
mov    0x18(%rsp),%rcx
add    $0x1,%rcx
add    $0x32,%r12
mov    %rcx,%rax
mov    %rcx,0x18(%rsp)
cmp    0x30(%rsp),%rcx
mov    0x24(%rsp),%r8d
je     1239 <next_move+0x109>
test   %r8d,%r8d
jle    1180 <next_move+0x50>
mov    0xc(%rsp),%ebp
sub    0x18(%rsp),%ebp
mov    0x4(%rsp),%ebx
xor    %r15d,%r15d
jmp    11cc <next_move+0x9c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0xffffffff,%ebx
cmp    %r15,%r13
je     1180 <next_move+0x50>
cmpb   $0x64,(%r12,%r15,1)
jne    11c0 <next_move+0x90>
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
add    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0xe04(%rip),%xmm0
jb     1210 <next_move+0xe0>
sqrtss %xmm0,%xmm0
jmp    1215 <next_move+0xe5>
nopl   0x0(%rax,%rax,1)
call   1050 <sqrt@plt>
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    11c0 <next_move+0x90>
mov    0x18(%rsp),%rax
mov    %eax,0x10(%rsp)
mov    %r15d,%eax
mov    %r15d,0x14(%rsp)
movss  %xmm0,0x8(%rsp)
jmp    11c0 <next_move+0x90>
xorps  %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jne    127e <next_move+0x14e>
jp     127e <next_move+0x14e>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
movslq 0x10(%rsp),%rax
movslq 0x14(%rsp),%rcx
imul   $0x32,%rax,%rax
mov    0x28(%rsp),%rdx
add    %rax,%rdx
movb   $0x2d,(%rcx,%rdx,1)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x14(%rsp),%eax
cmp    0x4(%rsp),%eax
jle    1291 <next_move+0x161>
lea    0xd86(%rip),%rdi
jmp    12bc <next_move+0x18c>
mov    0x10(%rsp),%ecx
cmp    0xc(%rsp),%ecx
jle    12a4 <next_move+0x174>
lea    0xd6e(%rip),%rdi
jmp    12bc <next_move+0x18c>
jge    12af <next_move+0x17f>
lea    0xd60(%rip),%rdi
jmp    12bc <next_move+0x18c>
cmp    0x4(%rsp),%eax
jge    126f <next_move+0x13f>
lea    0xd4c(%rip),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"CLEAN\0A\00"
@.str.1 = [7 x i8] c"RIGHT\0A\00"
@.str.2 = [6 x i8] c"DOWN\0A\00"
@.str.3 = [4 x i8] c"UP\0A\00"
@.str.4 = [6 x i8] c"LEFT\0A\00"
define void @next_move(i32 %0, i32 %1, [50 x i8]* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca [50 x i8]*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca float
%18 = alloca float
store i32 %0, i32* %6
store i32 %1, i32* %7
store [50 x i8]* %2, [50 x i8]** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store float 1.000000e+05, float* %18
store i32 0, i32* %11
br label %19
19: ; preds = %64, %5
%20 = load i32, i32* %11
%21 = load i32, i32* %9
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %67
23: ; preds = %19
store i32 0, i32* %12
br label %24
24: ; preds = %60, %23
%25 = load i32, i32* %12
%26 = load i32, i32* %10
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %63
28: ; preds = %24
%29 = load [50 x i8]*, [50 x i8]** %8
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %29, i64 %31
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %32, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 100
br i1 %38, label %39, label %59
39: ; preds = %28
%40 = load i32, i32* %6
%41 = load i32, i32* %11
%42 = sub nsw i32 %40, %41
%43 = call i64 @pow(i32 %42, i32 2)
%44 = load i32, i32* %7
%45 = load i32, i32* %12
%46 = sub nsw i32 %44, %45
%47 = call i64 @pow(i32 %46, i32 2)
%48 = add nsw i64 %43, %47
%49 = sitofp i64 %48 to float
%50 = call float @sqrt(float %49)
store float %50, float* %17
%51 = load float, float* %17
%52 = load float, float* %18
%53 = fcmp olt float %51, %52
br i1 %53, label %54, label %58
54: ; preds = %39
%55 = load float, float* %17
store float %55, float* %18
%56 = load i32, i32* %11
store i32 %56, i32* %15
%57 = load i32, i32* %12
store i32 %57, i32* %16
br label %58
58: ; preds = %54, %39
br label %59
59: ; preds = %58, %28
br label %60
60: ; preds = %59
%61 = load i32, i32* %12
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
br label %24
63: ; preds = %24
br label %64
64: ; preds = %63
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 1
store i32 %66, i32* %11
br label %19
67: ; preds = %19
%68 = load float, float* %18
%69 = fcmp oeq float %68, 0.000000e+00
br i1 %69, label %70, label %79
70: ; preds = %67
%71 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%72 = load [50 x i8]*, [50 x i8]** %8
%73 = load i32, i32* %15
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [50 x i8], [50 x i8]* %72, i64 %74
%76 = load i32, i32* %16
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [50 x i8], [50 x i8]* %75, i64 0, i64 %77
store i8 45, i8* %78
br label %107
79: ; preds = %67
%80 = load i32, i32* %16
%81 = load i32, i32* %7
%82 = icmp sgt i32 %80, %81
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %106
85: ; preds = %79
%86 = load i32, i32* %15
%87 = load i32, i32* %6
%88 = icmp sgt i32 %86, %87
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %105
91: ; preds = %85
%92 = load i32, i32* %15
%93 = load i32, i32* %6
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %104
97: ; preds = %91
%98 = load i32, i32* %16
%99 = load i32, i32* %7
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %103
103: ; preds = %101, %97
br label %104
104: ; preds = %103, %95
br label %105
105: ; preds = %104, %89
br label %106
106: ; preds = %105, %83
br label %107
107: ; preds = %106, %70
ret void
}

LLVM IR (-O2):
@str = [5 x i8] c"LEFT\00"
@str.5 = [3 x i8] c"UP\00"
@str.6 = [5 x i8] c"DOWN\00"
@str.7 = [6 x i8] c"RIGHT\00"
@str.8 = [6 x i8] c"CLEAN\00"
define void @next_move(i32 %0, i32 %1, [50 x i8]* nocapture %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %72
7: ; preds = %5
%8 = icmp sgt i32 %4, 0
%9 = zext i32 %3 to i64
%10 = zext i32 %4 to i64
br label %11
11: ; preds = %7, %43
%12 = phi i64 [ 0, %7 ], [ %47, %43 ]
%13 = phi float [ 1.000000e+05, %7 ], [ %46, %43 ]
%14 = phi i32 [ undef, %7 ], [ %45, %43 ]
%15 = phi i32 [ undef, %7 ], [ %44, %43 ]
br i1 %8, label %16, label %43
16: ; preds = %11
%17 = trunc i64 %12 to i32
%18 = sub nsw i32 %0, %17
br label %19
19: ; preds = %16, %37
%20 = phi i64 [ 0, %16 ], [ %41, %37 ]
%21 = phi float [ %13, %16 ], [ %40, %37 ]
%22 = phi i32 [ %14, %16 ], [ %39, %37 ]
%23 = phi i32 [ %15, %16 ], [ %38, %37 ]
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 %12, i64 %20
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 100
br i1 %26, label %27, label %37
27: ; preds = %19
%28 = tail call i64 @pow(i32 %18, i32 2)
%29 = trunc i64 %20 to i32
%30 = sub nsw i32 %1, %29
%31 = tail call i64 @pow(i32 %30, i32 2)
%32 = add nsw i64 %31, %28
%33 = sitofp i64 %32 to float
%34 = tail call float @sqrt(float %33)
%35 = fcmp olt float %34, %21
br i1 %35, label %36, label %37
36: ; preds = %27
br label %37
37: ; preds = %19, %36, %27
%38 = phi i32 [ %17, %36 ], [ %23, %27 ], [ %23, %19 ]
%39 = phi i32 [ %29, %36 ], [ %22, %27 ], [ %22, %19 ]
%40 = phi float [ %34, %36 ], [ %21, %27 ], [ %21, %19 ]
%41 = add nuw nsw i64 %20, 1
%42 = icmp eq i64 %41, %10
br i1 %42, label %43, label %19
43: ; preds = %37, %11
%44 = phi i32 [ %15, %11 ], [ %38, %37 ]
%45 = phi i32 [ %14, %11 ], [ %39, %37 ]
%46 = phi float [ %13, %11 ], [ %40, %37 ]
%47 = add nuw nsw i64 %12, 1
%48 = icmp eq i64 %47, %9
br i1 %48, label %49, label %11
49: ; preds = %43
%50 = fcmp oeq float %46, 0.000000e+00
br i1 %50, label %51, label %56
51: ; preds = %49
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
%53 = sext i32 %44 to i64
%54 = sext i32 %45 to i64
%55 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 %53, i64 %54
store i8 45, i8* %55
br label %72
56: ; preds = %49
%57 = icmp sgt i32 %45, %1
br i1 %57, label %58, label %60
58: ; preds = %56
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0))
br label %72
60: ; preds = %56
%61 = icmp sgt i32 %44, %0
br i1 %61, label %62, label %64
62: ; preds = %60
%63 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
br label %72
64: ; preds = %60
%65 = icmp slt i32 %44, %0
br i1 %65, label %66, label %68
66: ; preds = %64
%67 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
br label %72
68: ; preds = %64
%69 = icmp slt i32 %45, %1
br i1 %69, label %70, label %72
70: ; preds = %68
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %72
72: ; preds = %5, %58, %66, %70, %68, %62, %51
ret void
}