// File: /workspace/github_cpp_makefile_star2_O3/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 0x90d6
callq 0x8e5f
movl $0x1, %ebx
movq 0x1c0c5(%rip), %r14     # 0x24fc0
leaq 0x12986(%rip), %r15     # 0x1b888
leaq 0x1c417(%rip), %r12     # 0x25320
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %r13
movl $0x6, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x42f0
movq %r13, %rdi
movl %ebx, 0x4(%rsp)
movl %ebx, %esi
callq 0x4420
movq 0x1c3d8(%rip), %rbp     # 0x25330
testq %rbp, %rbp
je 0x90a3
movb $0x1, %r15b
xorl %r14d, %r14d
xorl %r13d, %r13d
callq 0x95bb
cltq
addq %rbp, %rax
cmpq %r14, %rax
je 0x906d
testb $0x1, %r15b
je 0x8fee
movq 0x1c306(%rip), %rax     # 0x25290
movq (%rax,%r13,8), %rdi
callq 0x186f0
incq %r13
testl %eax, %eax
je 0x8f83
movq 0x1c2ef(%rip), %rax     # 0x25290
movq -0x8(%rax,%r13,8), %rdi
movq %r12, %rsi
callq 0x1682c
cmpb $0x0, 0x1c2b4(%rip)     # 0x25269
jne 0x90c0
movq 0x1c2d6(%rip), %rcx     # 0x25298
subq 0x1c2c7(%rip), %rcx     # 0x25290
leaq -0x1(%r13), %rsi
sarq $0x3, %rcx
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq %rsi, %r13
cmpq %rdx, %rsi
je 0x9054
movq %rdx, %rbp
callq 0x8e5f
movq %rbp, %r13
jmp 0x9054
movl 0x1c33c(%rip), %esi     # 0x25330
decl %esi
xorl %edi, %edi
callq 0x4df6
cltq
incq %rax
movq %r12, %rbp
movq (%rbp), %rbp
decq %rax
jne 0x9005
movq 0x1c283(%rip), %rsi     # 0x25298
subq 0x1c274(%rip), %rsi     # 0x25290
shrq $0x3, %rsi
decl %esi
xorl %edi, %edi
callq 0x4df6
movslq %eax, %rbx
movq 0x1c25d(%rip), %rax     # 0x25290
movq (%rax,%rbx,8), %rdi
callq 0x186f0
testl %eax, %eax
je 0x900e
movq 0x10(%rbp), %rdi
movq 0x1c245(%rip), %rax     # 0x25290
movq (%rax,%rbx,8), %rsi
callq 0x18d1a
xorb $0x1, %r15b
incq %r14
movq 0x1c2ce(%rip), %rbp     # 0x25330
testq %rbp, %rbp
jne 0x8f6a
jmp 0x90a3
cmpq $0x0, 0x1c2bb(%rip)     # 0x25330
je 0x90a3
callq 0x9773
testb %al, %al
jne 0x90cf
callq 0x982c
callq 0x9a09
movl 0x4(%rsp), %ebx
incl %ebx
movq 0x1bf29(%rip), %r14     # 0x24fc0
leaq 0x127ea(%rip), %r15     # 0x1b888
jmp 0x8f09
callq 0x961a
callq 0x9a6e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9acd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x97d3
jmp 0x90a8