#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*/ free(char *);
int /*<<< orphan*/ imprimeForca(int);
scalar_t__ letraNaPalavra(char, char *);
int /*<<< orphan*/ printf(char *, ...);
char *revelaLetras(char, char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ vencedor(char *, char *);
int joga(char *palavra, char *palavra_obfuscada) {
  int numErros = 0;
  for (;;) {
    if (numErros >= 6) {
      break;
    }
    imprimeForca(numErros);
    printf("Que letra quer tentar? ");
    char c;
    scanf(" %c", &c);
    if (letraNaPalavra(c, palavra)) {
      char *novaObfuscada = revelaLetras(c, palavra, palavra_obfuscada);
      free(palavra_obfuscada);
      palavra_obfuscada = novaObfuscada;
      printf("Muito bem! A letra %c está na palavra!\n", c);
      if (vencedor(palavra, palavra_obfuscada)) {
        return numErros;
      }
    } else {
      printf("Letra errada!!\n");
      ++numErros;
    }
    printf("%s\n", palavra_obfuscada);
  }
  return numErros;
}


x86 assembly (clang, -O0):
<joga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jl     1196 <joga+0x26>
jmp    1264 <joga+0xf4>
mov    -0x1c(%rbp),%edi
call   1040 <imprimeForca@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe65(%rip),%rdi
lea    -0x1d(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1d(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1090 <letraNaPalavra@plt>
cmp    $0x0,%rax
je     1236 <joga+0xc6>
mov    -0x1d(%rbp),%al
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movsbl %al,%edi
call   1070 <revelaLetras@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsbl -0x1d(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <vencedor@plt>
cmp    $0x0,%rax
je     1231 <joga+0xc1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126a <joga+0xfa>
jmp    124d <joga+0xdd>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1187 <joga+0x17>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joga>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe80(%rip),%r15
lea    0x7(%rsp),%r12
xor    %ebp,%ebp
jmp    11cc <joga+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   1040 <puts@plt>
cmp    $0x6,%ebp
jge    1244 <joga+0xc4>
mov    %ebp,%edi
call   1050 <imprimeForca@plt>
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
movsbl 0x7(%rsp),%edi
mov    %rbx,%rsi
call   10a0 <letraNaPalavra@plt>
test   %rax,%rax
je     11b0 <joga+0x30>
movsbl 0x7(%rsp),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <revelaLetras@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1030 <free@plt>
movsbl 0x7(%rsp),%esi
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <vencedor@plt>
test   %rax,%rax
jne    1244 <joga+0xc4>
mov    %r13,%r14
jmp    11bf <joga+0x3f>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Que letra quer tentar? \00"
@.str.1 = [4 x i8] c" %c\00"
@.str.2 = [41 x i8] c"Muito bem! A letra %c est\C3\A1 na palavra!\0A\00"
@.str.3 = [16 x i8] c"Letra errada!!\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @joga(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %9
9: ; preds = %44, %2
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 6
br i1 %11, label %12, label %13
12: ; preds = %9
br label %47
13: ; preds = %9
%14 = load i32, i32* %6
%15 = call i32 @imprimeForca(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%18 = load i8, i8* %7
%19 = load i8*, i8** %4
%20 = call i64 @letraNaPalavra(i8 signext %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %13
%23 = load i8, i8* %7
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call i8* @revelaLetras(i8 signext %23, i8* %24, i8* %25)
store i8* %26, i8** %8
%27 = load i8*, i8** %5
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %8
store i8* %29, i8** %5
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = call i64 @vencedor(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %22
%38 = load i32, i32* %6
store i32 %38, i32* %3
br label %49
39: ; preds = %22
br label %44
40: ; preds = %13
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %44
44: ; preds = %40, %39
%45 = load i8*, i8** %5
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %9
47: ; preds = %12
%48 = load i32, i32* %6
store i32 %48, i32* %3
br label %49
49: ; preds = %47, %37
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [24 x i8] c"Que letra quer tentar? \00"
@.str.1 = [4 x i8] c" %c\00"
@.str.2 = [41 x i8] c"Muito bem! A letra %c est\C3\A1 na palavra!\0A\00"
@str = [15 x i8] c"Letra errada!!\00"
define i32 @joga(i8* %0, i8* %1) {
%3 = alloca i8
br label %4
4: ; preds = %2, %26
%5 = phi i32 [ 0, %2 ], [ %28, %26 ]
%6 = phi i8* [ %1, %2 ], [ %27, %26 ]
%7 = call i32 @imprimeForca(i32 %5)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = load i8, i8* %3
%11 = call i64 @letraNaPalavra(i8 signext %10, i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %4
%14 = load i8, i8* %3
%15 = call i8* @revelaLetras(i8 signext %14, i8* %0, i8* %6)
%16 = call i32 @free(i8* %6)
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i64 @vencedor(i8* %0, i8* %15)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %13
br label %31
23: ; preds = %4
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%25 = add nsw i32 %5, 1
br label %26
26: ; preds = %23, %13
%27 = phi i8* [ %15, %13 ], [ %6, %23 ]
%28 = phi i32 [ %5, %13 ], [ %25, %23 ]
%29 = call i32 @puts(i8* dereferenceable(1) %27)
%30 = icmp sgt i32 %28, 5
br i1 %30, label %31, label %4
31: ; preds = %26, %22
%32 = phi i32 [ %5, %22 ], [ %28, %26 ]
ret i32 %32
}