// File: /workspace/github_cpp_makefile_star2_O1/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 0x908c
callq 0x8e16
movl $0x1, 0x4(%rsp)
leaq 0x1c46b(%rip), %r14     # 0x25320
movq 0x1c104(%rip), %rbx     # 0x24fc0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %r13
movl $0x6, %edx
movq %rax, %rdi
leaq 0x12993(%rip), %rsi     # 0x1b888
callq 0x42f0
movq %r13, %rdi
movl 0x4(%rsp), %esi
callq 0x4420
movq 0x1c423(%rip), %r12     # 0x25330
testq %r12, %r12
je 0x901b
movb $0x1, %bpl
xorl %r15d, %r15d
xorl %r13d, %r13d
callq 0x9571
cltq
addq %r12, %rax
cmpq %r15, %rax
je 0x901b
testb $0x1, %bpl
je 0x8f9d
movq 0x1c351(%rip), %rax     # 0x25290
movq (%rax,%r13,8), %rdi
callq 0x18688
incq %r13
testl %eax, %eax
je 0x8f38
movq 0x1c33a(%rip), %rax     # 0x25290
movq -0x8(%rax,%r13,8), %rdi
movq %r14, %rsi
callq 0x167ce
cmpb $0x0, 0x1c2ff(%rip)     # 0x25269
jne 0x9053
leaq -0x1(%r13), %rcx
movq 0x1c31d(%rip), %rsi     # 0x25298
subq 0x1c30e(%rip), %rsi     # 0x25290
sarq $0x3, %rsi
movq %r13, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r13
cmpq %rdx, %rcx
je 0x9004
callq 0x8e16
jmp 0x9004
movl 0x1c38d(%rip), %esi     # 0x25330
decl %esi
xorl %edi, %edi
callq 0x4dee
cltq
incq %rax
movq %r14, %r12
movq (%r12), %r12
decq %rax
jne 0x8fb4
movq 0x1c2d4(%rip), %rsi     # 0x25298
subq 0x1c2c5(%rip), %rsi     # 0x25290
shrq $0x3, %rsi
decl %esi
xorl %edi, %edi
callq 0x4dee
movslq %eax, %rbx
movq 0x1c2ae(%rip), %rax     # 0x25290
movq (%rax,%rbx,8), %rdi
callq 0x18688
testl %eax, %eax
je 0x8fbd
movq 0x10(%r12), %rdi
movq 0x1c295(%rip), %rax     # 0x25290
movq (%rax,%rbx,8), %rsi
callq 0x18c92
xorb $0x1, %bpl
incq %r15
movq 0x1c31e(%rip), %r12     # 0x25330
testq %r12, %r12
jne 0x8f1f
cmpq $0x0, 0x1c30d(%rip)     # 0x25330
je 0x9035
callq 0x9729
testb %al, %al
je 0x9041
callq 0x9788
jmp 0x903a
callq 0x95d0
movl $0x3, %eax
jmp 0x9058
callq 0x97e1
callq 0x99be
incl 0x4(%rsp)
xorl %eax, %eax
jmp 0x9058
movl $0x1, %eax
testl %eax, %eax
je 0x8eb5
cmpl $0x3, %eax
jne 0x907d
callq 0x9a23
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9a82
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq