#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__ addGuessedChars(char, char *);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char getCharFromUser();
int /*<<< orphan*/ isCharInWord(char, char *, char *, unsigned int);
int /*<<< orphan*/ printStatus(unsigned int, char *, char *);
unsigned int strlen(char *);
scalar_t__ strncmp(char *, char *, unsigned int);
int playGame(char *randomWord, unsigned int triesLeft) {
  unsigned int counter;
  unsigned int stringLength = strlen(randomWord);
  char *guessedChars = calloc(25, sizeof(char));
  char wordInUnderscores[stringLength];
  for (counter = 0; counter < stringLength; counter++)
    wordInUnderscores[counter] = '_';
  wordInUnderscores[counter] = '\0';
  printStatus(triesLeft, wordInUnderscores, guessedChars);
  while (triesLeft > 0) {
    char guess = getCharFromUser();
    if (!isCharInWord(guess, randomWord, wordInUnderscores, stringLength) &&
        addGuessedChars(guess, guessedChars))
      triesLeft--;
    if (strncmp(randomWord, wordInUnderscores, stringLength) == 0) {
      free(guessedChars);
      return 0;
    }
    printStatus(triesLeft, wordInUnderscores, guessedChars);
  }
  free(guessedChars);
  return 1;
}


x86 assembly (clang, -O0):
<playGame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x19,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1200 <playGame+0x80>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%ecx
movb   $0x5f,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11db <playGame+0x5b>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%eax
movb   $0x0,(%rsi,%rax,1)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rdx
call   1050 <printStatus@plt>
cmpl   $0x0,-0x14(%rbp)
jbe    12b7 <playGame+0x137>
mov    $0x0,%al
call   10a0 <getCharFromUser@plt>
mov    -0x48(%rbp),%rdx
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
movsbl %al,%edi
call   1080 <isCharInWord@plt>
cmp    $0x0,%eax
jne    126c <playGame+0xec>
mov    -0x39(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1090 <addGuessedChars@plt>
cmp    $0x0,%rax
je     126c <playGame+0xec>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12a2 <playGame+0x122>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    12ce <playGame+0x14e>
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rdx
call   1050 <printStatus@plt>
jmp    1217 <playGame+0x97>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<playGame>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r15
call   1060 <strlen@plt>
mov    %eax,%r12d
mov    $0x19,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    %r12d,%r13d
mov    %rsp,%r14
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
test   %r12d,%r12d
je     11ec <playGame+0x5c>
mov    %r14,%rdi
mov    $0x5f,%esi
mov    %r13,%rdx
call   1070 <memset@plt>
mov    %r13,%rax
jmp    11ee <playGame+0x5e>
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
jmp    1213 <playGame+0x83>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1261 <playGame+0xd1>
mov    %ebx,%edi
mov    %r14,%rsi
mov    -0x30(%rbp),%rdx
call   1050 <printStatus@plt>
test   %ebx,%ebx
je     125a <playGame+0xca>
xor    %eax,%eax
call   10b0 <getCharFromUser@plt>
movsbl %al,%r12d
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
call   1090 <isCharInWord@plt>
test   %eax,%eax
jne    1200 <playGame+0x70>
mov    %r12d,%edi
mov    -0x30(%rbp),%rsi
call   10a0 <addGuessedChars@plt>
cmp    $0x1,%rax
adc    $0xffffffff,%ebx
jmp    1200 <playGame+0x70>
mov    $0x1,%ebx
jmp    1263 <playGame+0xd3>
xor    %ebx,%ebx
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @playGame(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
%15 = call i8* @calloc(i32 25, i32 1)
store i8* %15, i8** %8
%16 = load i32, i32* %7
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %9
%19 = alloca i8, i64 %17
store i64 %17, i64* %10
store i32 0, i32* %6
br label %20
20: ; preds = %28, %2
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %19, i64 %26
store i8 95, i8* %27
br label %28
28: ; preds = %24
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %20
31: ; preds = %20
%32 = load i32, i32* %6
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %19, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %5
%36 = load i8*, i8** %8
%37 = call i32 @printStatus(i32 %35, i8* %19, i8* %36)
br label %38
38: ; preds = %64, %31
%39 = load i32, i32* %5
%40 = icmp ugt i32 %39, 0
br i1 %40, label %41, label %68
41: ; preds = %38
%42 = call signext i8 (...) @getCharFromUser()
store i8 %42, i8* %11
%43 = load i8, i8* %11
%44 = load i8*, i8** %4
%45 = load i32, i32* %7
%46 = call i32 @isCharInWord(i8 signext %43, i8* %44, i8* %19, i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %56, label %48
48: ; preds = %41
%49 = load i8, i8* %11
%50 = load i8*, i8** %8
%51 = call i64 @addGuessedChars(i8 signext %49, i8* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32, i32* %5
%55 = add i32 %54, -1
store i32 %55, i32* %5
br label %56
56: ; preds = %53, %48, %41
%57 = load i8*, i8** %4
%58 = load i32, i32* %7
%59 = call i64 @strncmp(i8* %57, i8* %19, i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %8
%63 = call i32 @free(i8* %62)
store i32 0, i32* %3
store i32 1, i32* %12
br label %71
64: ; preds = %56
%65 = load i32, i32* %5
%66 = load i8*, i8** %8
%67 = call i32 @printStatus(i32 %65, i8* %19, i8* %66)
br label %38
68: ; preds = %38
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
store i32 1, i32* %3
store i32 1, i32* %12
br label %71
71: ; preds = %68, %61
%72 = load i8*, i8** %9
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
define i32 @playGame(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call dereferenceable_or_null(25) i8* @calloc(i32 25, i32 1)
%5 = zext i32 %3 to i64
%6 = alloca i8, i64 %5
%7 = icmp eq i32 %3, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = zext i32 %3 to i64
br label %10
10: ; preds = %8, %2
%11 = phi i64 [ 0, %2 ], [ %9, %8 ]
%12 = getelementptr inbounds i8, i8* %6, i64 %11
store i8 0, i8* %12
%13 = call i32 @printStatus(i32 %1, i8* %6, i8* %4)
%14 = icmp eq i32 %1, 0
br i1 %14, label %32, label %15
15: ; preds = %10, %29
%16 = phi i32 [ %26, %29 ], [ %1, %10 ]
%17 = call signext i8 (...) @getCharFromUser()
%18 = call i32 @isCharInWord(i8 signext %17, i8* %0, i8* %6, i32 %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = call i64 @addGuessedChars(i8 signext %17, i8* %4)
%22 = icmp ne i64 %21, 0
%23 = sext i1 %22 to i32
%24 = add i32 %16, %23
br label %25
25: ; preds = %20, %15
%26 = phi i32 [ %16, %15 ], [ %24, %20 ]
%27 = call i64 @strncmp(i8* %0, i8* %6, i32 %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i32 @printStatus(i32 %26, i8* %6, i8* %4)
%31 = icmp eq i32 %26, 0
br i1 %31, label %32, label %15
32: ; preds = %29, %25, %10
%33 = phi i32 [ 1, %10 ], [ 0, %25 ], [ 1, %29 ]
%34 = call i32 @free(i8* %4)
ret i32 %33
}