// File: giovifazi[P]knossos-bloodbath/Map.cpp
// Function: Map::delete_map(bool)
void Map::delete_map(bool garbage)
{
   if (garbage)
   {
      // Creo due iteratori per la mappa
      listaY *itery = NULL, *itery_prec = NULL;
      listaX *iterx = NULL, *iterx_prec = NULL;

      // Sposto itery fino all' ultimo nodo listaY della mappa e itery_prec al
      // penultimo
      for (int i = 0; i < height; i++)
      {
         //print_raw();
         itery = origin;
         itery_prec = itery;

         while (itery->down != NULL)
         {
            itery_prec = itery;
            itery = itery->down;
         }

         // Sposto iterx fino all' ultimo nodo listaX della mappa e iterx_prec
         // al penultimo
         for (int k = 0; k < width; k++)
         {
            //print_raw();
            iterx = itery->h;
            iterx_prec = iterx;

            while (iterx->next != NULL)
            {
               iterx_prec = iterx;
               iterx = iterx->next;
            }

            // Controllo se rimane un solo nodo nella riga piu in basso
            if (iterx != iterx_prec)
            {
               // Cancello il nodo più in basso a dx della mappa e rinizio il ciclo
               delete iterx;
               iterx_prec->next = NULL;
            }
            else
            {
               // Se rimane un solo nodo colonna non reimposto a NULL itery_prec
               if (itery_prec != itery)
                  itery_prec->down = NULL;
               
               // Se rimane un nodo riga cancello pure il puntatore colonna
               delete itery->h;           // Cancello ultimo nodo riga
               delete itery;              // Cancello il nodo colonna piu in basso
            }
         }       
      }
   }
      
   // Reinizializza il tutto
   origin = new listaY;
   origin->down = NULL;

   origin->h = new listaX;
   origin->h->next = NULL;
   origin->h->val = 0;

   width = 1;
   height = 1;

   mostUp = 0;
   mostLeft = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
testb $0x1, -0x9(%rbp)
je 0x45d1
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x50(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0xc(%rcx), %eax
jge 0x45cf
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x44df
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x44c0
movl $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x45bf
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x4529
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x450a
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x455c
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x454f
movq -0x58(%rbp), %rdi
movl $0x18, %esi
callq 0x21c0
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
jmp 0x45af
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x4571
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x4591
movq -0x60(%rbp), %rdi
movl $0x18, %esi
callq 0x21c0
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x45ad
movq -0x68(%rbp), %rdi
movl $0x10, %esi
callq 0x21c0
jmp 0x45af
jmp 0x45b1
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x44e6
jmp 0x45c1
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x449d
jmp 0x45d1
movl $0x10, %edi
callq 0x21b0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq (%rax), %rax
movq $0x0, (%rax)
movl $0x18, %edi
callq 0x21b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0x5140
jmp 0x460a
movq -0x50(%rbp), %rax
movq -0x70(%rbp), %rdx
movq (%rax), %rcx
movq %rdx, 0x8(%rcx)
movq (%rax), %rcx
movq 0x8(%rcx), %rcx
movq $0x0, (%rcx)
movq (%rax), %rcx
movq 0x8(%rcx), %rcx
movl $0x0, 0x8(%rcx)
movl $0x1, 0x8(%rax)
movl $0x1, 0xc(%rax)
movl $0x0, 0x14(%rax)
movl $0x0, 0x10(%rax)
addq $0x70, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x18, %esi
callq 0x21c0
movq -0x40(%rbp), %rdi
callq 0x2320
nopw (%rax,%rax)