#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*/ desenhar(char **);
int /*<<< orphan*/ menu();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ system(char *);
scalar_t__ vitoria(char **, char);
void jogar(char v[3][3]) {
  int x, y;
  char ch = 'o';
  int njogadas = 0;
  while (1) {
    system("cls");
    desenhar(v);
    printf("insira a linha");
    scanf("%d", &x);
    printf("insira a coluna");
    scanf("%d", &y);
    if (x > 3 || y > 3 || x < 1 || y < 1) {
      printf("\n\n valores invalidos\n\n");
      continue;
    }
    x--;
    y--;
    if (v[x][y] == ' ') {
      if (njogadas % 2 == 0)
        ch = 'o';
      else
        ch = 'x';
      v[x][y] = ch;
      njogadas++;
      if (vitoria(v, ch)) {
        printf("ganhou o jogador '%c'", ch);
        break;
      }
    } else
      printf("posicao ocupada\n");
    if (njogadas == 9) {
      printf("\n\nempate\n\n");
      break;
    }
  }
  desenhar(v);
  menu();
}


x86 assembly (clang, -O0):
<jogar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x6f,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe82(%rip),%rdi
call   1050 <system@plt>
mov    -0x8(%rbp),%rdi
call   1070 <desenhar@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe72(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe54(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <scanf@plt>
cmpl   $0x3,-0xc(%rbp)
jg     11f0 <jogar+0x90>
cmpl   $0x3,-0x10(%rbp)
jg     11f0 <jogar+0x90>
cmpl   $0x1,-0xc(%rbp)
jl     11f0 <jogar+0x90>
cmpl   $0x1,-0x10(%rbp)
jge    1203 <jogar+0xa3>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1177 <jogar+0x17>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    12ab <jogar+0x14b>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1252 <jogar+0xf2>
movb   $0x6f,-0x11(%rbp)
jmp    1256 <jogar+0xf6>
movb   $0x78,-0x11(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <vitoria@plt>
cmp    $0x0,%rax
je     12a6 <jogar+0x146>
movsbl -0x11(%rbp),%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12db <jogar+0x17b>
jmp    12b9 <jogar+0x159>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x9,-0x18(%rbp)
jne    12d6 <jogar+0x176>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12db <jogar+0x17b>
jmp    1177 <jogar+0x17>
mov    -0x8(%rbp),%rdi
call   1070 <desenhar@plt>
mov    $0x0,%al
call   1040 <menu@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jogar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
lea    0xe8b(%rip),%rbx
lea    0x10(%rsp),%r13
lea    0xe82(%rip),%rbp
lea    0xc(%rsp),%r14
lea    0xeb6(%rip),%r15
xor    %eax,%eax
jmp    11c9 <jogar+0x59>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
cmp    $0x9,%eax
je     1291 <jogar+0x121>
mov    %eax,0x8(%rsp)
jmp    11d8 <jogar+0x68>
nop
mov    %r15,%rdi
call   1030 <puts@plt>
lea    0xe21(%rip),%rdi
call   1060 <system@plt>
mov    %r12,%rdi
call   1080 <desenhar@plt>
lea    0xe11(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
mov    0x10(%rsp),%eax
test   %eax,%eax
jle    11d0 <jogar+0x60>
cmp    $0x3,%eax
jg     11d0 <jogar+0x60>
mov    0xc(%rsp),%ecx
cmp    $0x3,%ecx
jg     11d0 <jogar+0x60>
test   %ecx,%ecx
jle    11d0 <jogar+0x60>
add    $0xffffffff,%eax
mov    %eax,0x10(%rsp)
add    $0xffffffff,%ecx
mov    %ecx,0xc(%rsp)
lea    (%rax,%rax,2),%rax
add    %r12,%rax
cmpb   $0x20,(%rcx,%rax,1)
jne    11b0 <jogar+0x40>
add    %rcx,%rax
xor    %ecx,%ecx
mov    0x8(%rsp),%edx
and    $0x1,%edx
setne  %cl
lea    (%rcx,%rcx,8),%ecx
add    $0x6f,%ecx
mov    %ecx,0x14(%rsp)
mov    %cl,(%rax)
lea    (%rdx,%rdx,8),%esi
add    $0x6f,%esi
mov    %r12,%rdi
call   1040 <vitoria@plt>
test   %rax,%rax
jne    129f <jogar+0x12f>
mov    0x8(%rsp),%eax
add    $0x1,%eax
cmp    $0x9,%eax
jne    11c9 <jogar+0x59>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
jmp    12b2 <jogar+0x142>
movzbl 0x14(%rsp),%esi
lea    0xd7b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1080 <desenhar@plt>
xor    %eax,%eax
call   1050 <menu@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cls\00"
@.str.1 = [15 x i8] c"insira a linha\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [16 x i8] c"insira a coluna\00"
@.str.4 = [23 x i8] c"\0A\0A valores invalidos\0A\0A\00"
@.str.5 = [22 x i8] c"ganhou o jogador '%c'\00"
@.str.6 = [17 x i8] c"posicao ocupada\0A\00"
@.str.7 = [11 x i8] c"\0A\0Aempate\0A\0A\00"
define void @jogar([3 x i8]* %0) {
%2 = alloca [3 x i8]*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store [3 x i8]* %0, [3 x i8]** %2
store i8 111, i8* %5
store i32 0, i32* %6
br label %7
7: ; preds = %1, %27, %78
%8 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = load [3 x i8]*, [3 x i8]** %2
%10 = bitcast [3 x i8]* %9 to i8**
%11 = call i32 @desenhar(i8** %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 3
br i1 %17, label %27, label %18
18: ; preds = %7
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 3
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 1
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %24, %21, %18, %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %7
29: ; preds = %24
%30 = load i32, i32* %3
%31 = add nsw i32 %30, -1
store i32 %31, i32* %3
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
%34 = load [3 x i8]*, [3 x i8]** %2
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %34, i64 %36
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %37, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 32
br i1 %43, label %44, label %71
44: ; preds = %29
%45 = load i32, i32* %6
%46 = srem i32 %45, 2
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
store i8 111, i8* %5
br label %50
49: ; preds = %44
store i8 120, i8* %5
br label %50
50: ; preds = %49, %48
%51 = load i8, i8* %5
%52 = load [3 x i8]*, [3 x i8]** %2
%53 = load i32, i32* %3
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [3 x i8], [3 x i8]* %52, i64 %54
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [3 x i8], [3 x i8]* %55, i64 0, i64 %57
store i8 %51, i8* %58
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
%61 = load [3 x i8]*, [3 x i8]** %2
%62 = bitcast [3 x i8]* %61 to i8**
%63 = load i8, i8* %5
%64 = call i64 @vitoria(i8** %62, i8 signext %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %50
%67 = load i8, i8* %5
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %68)
br label %79
70: ; preds = %50
br label %73
71: ; preds = %29
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %71, %70
%74 = load i32, i32* %6
%75 = icmp eq i32 %74, 9
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %79
78: ; preds = %73
br label %7
79: ; preds = %76, %66
%80 = load [3 x i8]*, [3 x i8]** %2
%81 = bitcast [3 x i8]* %80 to i8**
%82 = call i32 @desenhar(i8** %81)
%83 = call i32 (...) @menu()
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
@.str.1 = [15 x i8] c"insira a linha\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [16 x i8] c"insira a coluna\00"
@.str.5 = [22 x i8] c"ganhou o jogador '%c'\00"
@str = [16 x i8] c"posicao ocupada\00"
@str.8 = [10 x i8] c"\0A\0Aempate\0A\00"
@str.9 = [22 x i8] c"\0A\0A valores invalidos\0A\00"
define void @jogar([3 x i8]* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast [3 x i8]* %0 to i8**
br label %7
7: ; preds = %47, %1
%8 = phi i32 [ %48, %47 ], [ 0, %1 ]
br label %9
9: ; preds = %7, %25
%10 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @desenhar(i8** %6)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 3
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 3
%20 = select i1 %17, i1 true, i1 %19
%21 = icmp slt i32 %16, 1
%22 = or i1 %21, %20
%23 = icmp slt i32 %18, 1
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %25, label %27
25: ; preds = %9
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
br label %9
27: ; preds = %9
%28 = add nsw i32 %16, -1
store i32 %28, i32* %2
%29 = add nsw i32 %18, -1
store i32 %29, i32* %3
%30 = zext i32 %28 to i64
%31 = zext i32 %29 to i64
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 %30, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 32
br i1 %34, label %35, label %45
35: ; preds = %27
%36 = and i32 %8, 1
%37 = icmp eq i32 %36, 0
%38 = select i1 %37, i8 111, i8 120
store i8 %38, i8* %32
%39 = add nsw i32 %8, 1
%40 = call i64 @vitoria(i8** %6, i8 signext %38)
%41 = icmp eq i64 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %35
%43 = zext i8 %38 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %52
45: ; preds = %27
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %35, %45
%48 = phi i32 [ %39, %35 ], [ %8, %45 ]
%49 = icmp eq i32 %48, 9
br i1 %49, label %50, label %7
50: ; preds = %47
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
br label %52
52: ; preds = %50, %42
%53 = call i32 @desenhar(i8** %6)
%54 = call i32 (...) @menu()
ret void
}