#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*/ clear_screen();
int /*<<< orphan*/ position(char **, int *, char);
int /*<<< orphan*/ print_maze(char **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ validate_position(char **, int, int);
void read_player(char maze[23][30], int player[3], char controle) {
  int linha, coluna;
  do {
    if (controle == '3') {
      printf("Qual a posição do GHOST? (x,y)\n");
    } else {
      printf("Qual a posicao do pacman (x,y) \n");
    }
    printf("x: ");
    scanf("%d", &coluna);
    printf("y: ");
    scanf("%d", &linha);
  } while (!validate_position(maze, linha, coluna));
  player[0] = linha;
  player[1] = coluna;
  player[2] = controle;
  position(maze, player, controle);
  clear_screen();
  print_maze(maze);
  do {
    linha = player[0];
    coluna = player[1];
    if (controle == '3') {
      printf("Qual a direção do ghost ?  = 1-Down , 2-Right, 3-Up, 4-Left = ");
    } else {
      printf("Qual a direção do pacman? = 1-Down , 2-Right, 3-Up, 4-Left = ");
    }
    scanf("%d", &player[2]);
    switch (player[2]) {
    case 1:
      linha = linha + 1;
      break;
    case 2:
      coluna = coluna + 1;
      break;
    case 3:
      linha = linha - 1;
      break;
    case 4:
      coluna = coluna - 1;
      break;
    }
  } while (!validate_position(maze, linha, coluna) || player[2] > 4 ||
           player[2] < 1);
}


x86 assembly (clang, -O0):
<read_player>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x33,%eax
jne    1193 <read_player+0x33>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    119f <read_player+0x3f>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <validate_position@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1175 <read_player+0x15>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
movsbl -0x11(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsbl -0x11(%rbp),%edx
call   1040 <position@plt>
mov    $0x0,%al
call   1060 <clear_screen@plt>
mov    -0x8(%rbp),%rdi
call   1080 <print_maze@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x33,%eax
jne    1266 <read_player+0x106>
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
jmp    1272 <read_player+0x112>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    0xdd6(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     12e6 <read_player+0x186>
mov    -0x28(%rbp),%rax
lea    0xd56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12e6 <read_player+0x186>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e6 <read_player+0x186>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12e6 <read_player+0x186>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12eb <read_player+0x18b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <validate_position@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     132b <read_player+0x1cb>
mov    -0x10(%rbp),%rcx
mov    $0x1,%al
cmpl   $0x4,0x8(%rcx)
mov    %al,-0x29(%rbp)
jg     132b <read_player+0x1cb>
mov    -0x10(%rbp),%rax
cmpl   $0x1,0x8(%rax)
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1235 <read_player+0xd5>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_player>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,0x14(%rsp)
cmp    $0x33,%dl
lea    0xf2a(%rip),%rax
lea    0xf03(%rip),%rbp
cmove  %rax,%rbp
lea    0xe70(%rip),%r13
lea    0xe6c(%rip),%r15
lea    0x10(%rsp),%r12
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    %r13,%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r14,%rdi
call   1080 <validate_position@plt>
test   %eax,%eax
je     11b0 <read_player+0x40>
mov    0x14(%rsp),%ebp
movsbl %bpl,%edx
mov    0x10(%rsp),%eax
mov    %eax,(%rbx)
mov    0xc(%rsp),%eax
mov    %eax,0x4(%rbx)
lea    0x8(%rbx),%r15
mov    %edx,0x8(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <position@plt>
xor    %eax,%eax
call   1070 <clear_screen@plt>
mov    %r14,%rdi
call   1090 <print_maze@plt>
cmp    $0x33,%bpl
lea    0xde2(%rip),%rax
lea    0xe1c(%rip),%rbp
cmove  %rax,%rbp
lea    0xdc9(%rip),%r12
lea    0xdae(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x4(%rbx),%eax
mov    %eax,0xc(%rsp)
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0x8(%rbx),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     12d0 <read_player+0x160>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
addl   $0x1,0x10(%rsp)
jmp    12d0 <read_player+0x160>
nopl   0x0(%rax)
addl   $0x1,0xc(%rsp)
jmp    12d0 <read_player+0x160>
nopw   0x0(%rax,%rax,1)
addl   $0xffffffff,0x10(%rsp)
jmp    12d0 <read_player+0x160>
nopw   0x0(%rax,%rax,1)
addl   $0xffffffff,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r14,%rdi
call   1080 <validate_position@plt>
test   %eax,%eax
je     1260 <read_player+0xf0>
mov    (%r15),%eax
add    $0xfffffffb,%eax
cmp    $0xfffffffc,%eax
jb     1260 <read_player+0xf0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Qual a posi\C3\A7\C3\A3o do GHOST? (x,y)\0A\00"
@.str.1 = [33 x i8] c"Qual a posicao do pacman (x,y) \0A\00"
@.str.2 = [4 x i8] c"x: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"y: \00"
@.str.5 = [65 x i8] c"Qual a dire\C3\A7\C3\A3o do ghost ? = 1-Down , 2-Right, 3-Up, 4-Left = \00"
@.str.6 = [64 x i8] c"Qual a dire\C3\A7\C3\A3o do pacman? = 1-Down , 2-Right, 3-Up, 4-Left = \00"
define void @read_player([30 x i8]* %0, i32* %1, i8 signext %2) {
%4 = alloca [30 x i8]*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store [30 x i8]* %0, [30 x i8]** %4
store i32* %1, i32** %5
store i8 %2, i8* %6
br label %9
9: ; preds = %22, %3
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 51
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %17
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
br label %22
22: ; preds = %17
%23 = load [30 x i8]*, [30 x i8]** %4
%24 = bitcast [30 x i8]* %23 to i8**
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @validate_position(i8** %24, i32 %25, i32 %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %9, label %30
30: ; preds = %22
%31 = load i32, i32* %7
%32 = load i32*, i32** %5
%33 = getelementptr inbounds i32, i32* %32, i64 0
store i32 %31, i32* %33
%34 = load i32, i32* %8
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i64 1
store i32 %34, i32* %36
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
%39 = load i32*, i32** %5
%40 = getelementptr inbounds i32, i32* %39, i64 2
store i32 %38, i32* %40
%41 = load [30 x i8]*, [30 x i8]** %4
%42 = bitcast [30 x i8]* %41 to i8**
%43 = load i32*, i32** %5
%44 = load i8, i8* %6
%45 = call i32 @position(i8** %42, i32* %43, i8 signext %44)
%46 = call i32 (...) @clear_screen()
%47 = load [30 x i8]*, [30 x i8]** %4
%48 = bitcast [30 x i8]* %47 to i8**
%49 = call i32 @print_maze(i8** %48)
br label %50
50: ; preds = %101, %30
%51 = load i32*, i32** %5
%52 = getelementptr inbounds i32, i32* %51, i64 0
%53 = load i32, i32* %52
store i32 %53, i32* %7
%54 = load i32*, i32** %5
%55 = getelementptr inbounds i32, i32* %54, i64 1
%56 = load i32, i32* %55
store i32 %56, i32* %8
%57 = load i8, i8* %6
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 51
br i1 %59, label %60, label %62
60: ; preds = %50
%61 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
br label %64
62: ; preds = %50
%63 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %62, %60
%65 = load i32*, i32** %5
%66 = getelementptr inbounds i32, i32* %65, i64 2
%67 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %66)
%68 = load i32*, i32** %5
%69 = getelementptr inbounds i32, i32* %68, i64 2
%70 = load i32, i32* %69
switch i32 %70, label %83 [
i32 1, label %71
i32 2, label %74
i32 3, label %77
i32 4, label %80
]
71: ; preds = %64
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %83
74: ; preds = %64
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %83
77: ; preds = %64
%78 = load i32, i32* %7
%79 = sub nsw i32 %78, 1
store i32 %79, i32* %7
br label %83
80: ; preds = %64
%81 = load i32, i32* %8
%82 = sub nsw i32 %81, 1
store i32 %82, i32* %8
br label %83
83: ; preds = %64, %80, %77, %74, %71
br label %84
84: ; preds = %83
%85 = load [30 x i8]*, [30 x i8]** %4
%86 = bitcast [30 x i8]* %85 to i8**
%87 = load i32, i32* %7
%88 = load i32, i32* %8
%89 = call i32 @validate_position(i8** %86, i32 %87, i32 %88)
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %84
%92 = load i32*, i32** %5
%93 = getelementptr inbounds i32, i32* %92, i64 2
%94 = load i32, i32* %93
%95 = icmp sgt i32 %94, 4
br i1 %95, label %101, label %96
96: ; preds = %91
%97 = load i32*, i32** %5
%98 = getelementptr inbounds i32, i32* %97, i64 2
%99 = load i32, i32* %98
%100 = icmp slt i32 %99, 1
br label %101
101: ; preds = %96, %91, %84
%102 = phi i1 [ true, %91 ], [ true, %84 ], [ %100, %96 ]
br i1 %102, label %50, label %103
103: ; preds = %101
ret void
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"x: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"y: \00"
@.str.5 = [65 x i8] c"Qual a dire\C3\A7\C3\A3o do ghost ? = 1-Down , 2-Right, 3-Up, 4-Left = \00"
@.str.6 = [64 x i8] c"Qual a dire\C3\A7\C3\A3o do pacman? = 1-Down , 2-Right, 3-Up, 4-Left = \00"
@str = [32 x i8] c"Qual a posicao do pacman (x,y) \00"
@str.7 = [33 x i8] c"Qual a posi\C3\A7\C3\A3o do GHOST? (x,y)\00"
define void @read_player([30 x i8]* %0, i32* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = icmp eq i8 %2, 51
%9 = bitcast [30 x i8]* %0 to i8**
%10 = select i1 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0)
br label %11
11: ; preds = %11, %3
%12 = call i32 @puts(i8* dereferenceable(1) %10)
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = call i32 @validate_position(i8** %9, i32 %17, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %11, label %21
21: ; preds = %11
%22 = sext i8 %2 to i32
%23 = load i32, i32* %4
store i32 %23, i32* %1
%24 = load i32, i32* %5
%25 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %24, i32* %25
%26 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %22, i32* %26
%27 = call i32 @position(i8** %9, i32* %1, i8 signext %2)
%28 = call i32 (...) @clear_screen()
%29 = call i32 @print_maze(i8** %9)
%30 = select i1 %8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0)
br label %31
31: ; preds = %58, %21
%32 = load i32, i32* %1
store i32 %32, i32* %4
%33 = load i32, i32* %25
store i32 %33, i32* %5
%34 = call i32 @printf(i8* dereferenceable(1) %30)
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %26)
%36 = load i32, i32* %26
switch i32 %36, label %49 [
i32 1, label %37
i32 2, label %40
i32 3, label %43
i32 4, label %46
]
37: ; preds = %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %49
40: ; preds = %31
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %49
43: ; preds = %31
%44 = load i32, i32* %4
%45 = add nsw i32 %44, -1
store i32 %45, i32* %4
br label %49
46: ; preds = %31
%47 = load i32, i32* %5
%48 = add nsw i32 %47, -1
store i32 %48, i32* %5
br label %49
49: ; preds = %37, %40, %43, %46, %31
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = call i32 @validate_position(i8** %9, i32 %50, i32 %51)
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %49
%55 = load i32, i32* %26
%56 = add i32 %55, -5
%57 = icmp ult i32 %56, -4
br i1 %57, label %58, label %59
58: ; preds = %54, %49
br label %31
59: ; preds = %54
ret void
}