// File: /workspace/github_cpp_makefile_star2_O2/arisKoutsou[P]oopproj/./src/game_utils.cpp
// Function: handleBattleCase()
void handleBattleCase(void) {
  createMonsters();
  int rounds = 1;
  clearScreen();
  while (true) {    
    int livingsPlayed = 0;
    size_t heroIndex = 0U;
    size_t prevHero = 0U;
    bool heroesTurn = true;

    cout << endl << "ROUND " << rounds;
    while (monsters.size() != 0 && livingsPlayed != (monsters.size() + heroesAlive())) {
      if (heroesTurn) {
	while (heroes[heroIndex]->getHealthPower() == 0) ++heroIndex;
        heroes[heroIndex]->battle(monsters);
	if (quitGame) return;
	prevHero = heroIndex;
	heroIndex = (heroIndex + 1) % heroes.size();
	if (prevHero != heroIndex) clearScreen();
	heroesTurn = false;        
      } else {
	size_t monsterIndex = rng.fromMintoMax(0, monsters.size() - 1);
        list<Monster*> :: const_iterator it = monsters.begin();
        while (monsterIndex-- != 0) ++it;
        size_t heroToAttackIndex;
        do {
          heroToAttackIndex = rng.fromMintoMax(0, heroes.size() - 1);
        } while (heroes[heroToAttackIndex]->getHealthPower() == 0);
        (*it)->attack(heroes[heroToAttackIndex]);
        heroesTurn = true;
      }
      ++livingsPlayed;
    }
    if (heroesWon()) {
      claimRewards();
      break;
    } else if (monstersWon()) {
      receivePenalty();
      break;
    }
    regenerateStats();
    updatePotionsAndNerfs();
    ++rounds;
  }
  restoreHeroes();
  cleanupMonsters();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x7b63
callq 0x7951
pushq $0x1
popq %rbx
movq 0x19601(%rip), %rdi     # 0x20fc0
leaq 0xdeb2(%rip), %r14      # 0x15878
leaq 0x19943(%rip), %r12     # 0x21310
callq 0x4120
movq %rax, %rdi
movq %r14, %rsi
callq 0x4250
movq %rax, %rdi
movl %ebx, 0x4(%rsp)
movl %ebx, %esi
callq 0x4400
movb $0x1, %r14b
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x19925(%rip), %rbx     # 0x21320
testq %rbx, %rbx
je 0x7b30
callq 0x7f14
cltq
addq %rax, %rbx
cmpq %r15, %rbx
je 0x7afa
testb $0x1, %r14b
je 0x7a88
movq 0x1985c(%rip), %rax     # 0x21280
movq (%rax,%r13,8), %rdi
callq 0x12a58
incq %r13
testl %eax, %eax
je 0x7a1d
movq 0x19845(%rip), %rax     # 0x21280
movq -0x8(%rax,%r13,8), %rdi
movq %r12, %rsi
callq 0x114c8
cmpb $0x0, 0x1980a(%rip)     # 0x21259
jne 0x7b4d
movq 0x1982c(%rip), %rcx     # 0x21288
subq 0x1981d(%rip), %rcx     # 0x21280
leaq -0x1(%r13), %rsi
sarq $0x3, %rcx
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq %rsi, %r13
cmpq %rdx, %rsi
je 0x7aee
movq %rdx, %rbp
callq 0x7951
movq %rbp, %r13
jmp 0x7aee
movl 0x19892(%rip), %esi     # 0x21320
decl %esi
xorl %edi, %edi
callq 0x4b2c
cltq
incq %rax
movq %r12, %rbp
movq (%rbp), %rbp
decq %rax
jne 0x7a9f
movq 0x197d9(%rip), %rsi     # 0x21288
subq 0x197ca(%rip), %rsi     # 0x21280
shrq $0x3, %rsi
decl %esi
xorl %edi, %edi
callq 0x4b2c
movslq %eax, %rbx
movq 0x197b3(%rip), %rax     # 0x21280
movq (%rax,%rbx,8), %rdi
callq 0x12a58
testl %eax, %eax
je 0x7aa8
movq 0x10(%rbp), %rdi
movq 0x1979b(%rip), %rax     # 0x21280
movq (%rax,%rbx,8), %rsi
callq 0x12f5a
xorb $0x1, %r14b
incq %r15
jmp 0x79f4
cmpq $0x0, 0x1981e(%rip)     # 0x21320
je 0x7b30
callq 0x809c
testb %al, %al
jne 0x7b5c
callq 0x8129
callq 0x82ee
movl 0x4(%rsp), %ebx
incl %ebx
movq 0x1949c(%rip), %rdi     # 0x20fc0
leaq 0xdd4d(%rip), %r14      # 0x15878
jmp 0x79cd
callq 0x7f61
callq 0x8341
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8392
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x80e2
jmp 0x7b35