// File: joao18araujo[P]pierluigi/src/fourth_species_counterpoint.cpp
// Function: FourthSpeciesCounterpoint::analyse_and_add_interval(bool, bool, std::vector<Interval, std::allocator<Interval>>&, Note, Note, Interval, Song*)
void FourthSpeciesCounterpoint::analyse_and_add_interval(bool reverse_movement, bool melodic_ascendant, vector<Interval> & possible_intervals, Note previous_note, Note note, Interval interval, Song * counterpoint){
  Note next_note;
  auto previous_counterpoint_note = counterpoint->notes.back();

  if(interval.is_consonant())
    next_note = Scale::interval_to_note_on_scale(note, interval, song->scale);
  else
    next_note = Interval::interval_to_note(note, interval);

  auto previous_interval = Interval(previous_note, previous_counterpoint_note);

  if(!next_note.valid or (interval.is_dissonant() and previous_interval.is_dissonant())){
    return;
  }

  Interval melodic_interval(previous_counterpoint_note, next_note);

  bool is_valid_passing_or_neighbor = true;
  if(interval.is_dissonant()){
    is_valid_passing_or_neighbor = (melodic_interval == "m2" or melodic_interval == "M2");
  }else if(previous_interval.is_dissonant()){
    auto pre_previous_counterpoint_note = counterpoint->notes[counterpoint->size() - 2];
    Interval previous_melodic_interval(pre_previous_counterpoint_note, previous_counterpoint_note);
    bool passing = melodic_interval.ascendant() == previous_melodic_interval.ascendant();
    bool neighbor = (pre_previous_counterpoint_note == next_note and melodic_interval.ascendant());
    is_valid_passing_or_neighbor = (passing || neighbor) && (melodic_interval == "m2" or melodic_interval == "M2");
  }

  bool can_jump = (reverse_movement or
                  melodic_interval.quantitative <= 4 or
                  melodic_interval.quantitative == 8);

  if(((can_jump and (melodic_ascendant == melodic_interval.ascendant()) and note.valid) or
      previous_counterpoint_note.rest()) and is_valid_passing_or_neighbor)
    possible_intervals.push_back(interval);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x790, %rsp            # imm = 0x790
movq %r9, -0x720(%rbp)
movq %r8, -0x718(%rbp)
movq %rcx, -0x710(%rbp)
movb %sil, %al
movb %dil, %sil
movq 0x10(%rbp), %rdi
andb $0x1, %sil
movb %sil, -0x1(%rbp)
andb $0x1, %al
movb %al, -0x2(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x22dc0
movq 0x10(%rbp), %rdi
callq 0x1b790
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x22ce0
jmp 0x1abda
movq -0x720(%rbp), %rdi
callq 0x1c270
movb %al, -0x721(%rbp)
jmp 0x1abee
movb -0x721(%rbp), %al
testb $0x1, %al
jne 0x1abfd
jmp 0x1ad5e
movq -0x718(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x22ce0
jmp 0x1ac12
movq -0x720(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0xfdb0
jmp 0x1ac27
leaq 0x9c309ba(%rip), %rax   # 0x9c4b5e8
movq (%rax), %rsi
addq $0x18, %rsi
leaq -0x278(%rbp), %rdi
callq 0x10110
jmp 0x1ac43
leaq -0x140(%rbp), %rdi
leaq -0x198(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
leaq -0x278(%rbp), %rcx
callq 0x27790
jmp 0x1ac66
leaq -0x80(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xfe00
jmp 0x1ac78
leaq -0x140(%rbp), %rdi
callq 0xfd80
leaq -0x278(%rbp), %rdi
callq 0x101b0
leaq -0x1c8(%rbp), %rdi
callq 0xfc90
leaq -0x198(%rbp), %rdi
callq 0xfd80
jmp 0x1ae3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b77b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b76f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1ad4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1ad41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1ad35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x140(%rbp), %rdi
callq 0xfd80
leaq -0x278(%rbp), %rdi
callq 0x101b0
leaq -0x1c8(%rbp), %rdi
callq 0xfc90
leaq -0x198(%rbp), %rdi
callq 0xfd80
jmp 0x1b76f
movq -0x718(%rbp), %rsi
leaq -0x328(%rbp), %rdi
callq 0x22ce0
jmp 0x1ad73
movq -0x720(%rbp), %rsi
leaq -0x358(%rbp), %rdi
callq 0xfdb0
jmp 0x1ad88
leaq -0x2d0(%rbp), %rdi
leaq -0x328(%rbp), %rsi
leaq -0x358(%rbp), %rdx
callq 0x1c440
jmp 0x1ada4
leaq -0x80(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0xfe00
jmp 0x1adb6
leaq -0x2d0(%rbp), %rdi
callq 0xfd80
leaq -0x358(%rbp), %rdi
callq 0xfc90
leaq -0x328(%rbp), %rdi
callq 0xfd80
jmp 0x1ae3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1ae2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1ae22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0xfd80
leaq -0x358(%rbp), %rdi
callq 0xfc90
leaq -0x328(%rbp), %rdi
callq 0xfd80
jmp 0x1b76f
movq -0x710(%rbp), %rsi
leaq -0x3e0(%rbp), %rdi
callq 0x22ce0
jmp 0x1ae54
leaq -0x438(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22ce0
jmp 0x1ae69
leaq -0x388(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
leaq -0x438(%rbp), %rdx
callq 0x1bf30
jmp 0x1ae85
leaq -0x438(%rbp), %rdi
callq 0xfd80
leaq -0x3e0(%rbp), %rdi
callq 0xfd80
testb $0x1, -0x2c(%rbp)
je 0x1aee6
movq -0x720(%rbp), %rdi
callq 0x1c210
movb %al, -0x722(%rbp)
jmp 0x1aeb7
movb -0x722(%rbp), %al
testb $0x1, %al
jne 0x1aec6
jmp 0x1af4f
leaq -0x388(%rbp), %rdi
callq 0x1c210
movb %al, -0x723(%rbp)
jmp 0x1aeda
movb -0x723(%rbp), %al
testb $0x1, %al
jne 0x1aee6
jmp 0x1af4f
movl $0x1, -0x43c(%rbp)
jmp 0x1b72d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1af27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x438(%rbp), %rdi
callq 0xfd80
leaq -0x3e0(%rbp), %rdi
callq 0xfd80
jmp 0x1b76f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b763
leaq -0x4c8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22ce0
jmp 0x1af64
leaq -0x520(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x22ce0
jmp 0x1af76
leaq -0x470(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
leaq -0x520(%rbp), %rdx
callq 0x1bf30
jmp 0x1af92
leaq -0x520(%rbp), %rdi
callq 0xfd80
leaq -0x4c8(%rbp), %rdi
callq 0xfd80
movq -0x720(%rbp), %rdi
movb $0x1, -0x521(%rbp)
callq 0x1c210
movb %al, -0x724(%rbp)
jmp 0x1afc5
movb -0x724(%rbp), %al
testb $0x1, %al
jne 0x1afd4
jmp 0x1b1f7
leaq -0x549(%rbp), %rdi
movq %rdi, -0x730(%rbp)
callq 0x6830
movq -0x730(%rbp), %rdx
movb $0x0, -0x572(%rbp)
movb $0x0, -0x573(%rbp)
leaq 0x45093(%rip), %rsi     # 0x60096
leaq -0x548(%rbp), %rdi
callq 0xfb20
jmp 0x1b011
leaq -0x470(%rbp), %rdi
leaq -0x548(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x731(%rbp)
jmp 0x1b02c
movb -0x731(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x732(%rbp)
jne 0x1b0a7
jmp 0x1b041
leaq -0x571(%rbp), %rdi
movq %rdi, -0x740(%rbp)
callq 0x6830
movq -0x740(%rbp), %rdx
movb $0x1, -0x572(%rbp)
leaq 0x45030(%rip), %rsi     # 0x60099
leaq -0x570(%rbp), %rdi
callq 0xfb20
jmp 0x1b077
movb $0x1, -0x573(%rbp)
leaq -0x470(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x741(%rbp)
jmp 0x1b099
movb -0x741(%rbp), %al
movb %al, -0x732(%rbp)
jmp 0x1b0a7
movb -0x732(%rbp), %al
andb $0x1, %al
movb %al, -0x521(%rbp)
testb $0x1, -0x573(%rbp)
jne 0x1b0c0
jmp 0x1b0cc
leaq -0x570(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x572(%rbp)
jne 0x1b0d7
jmp 0x1b0e3
leaq -0x571(%rbp), %rdi
callq 0x64f0
leaq -0x548(%rbp), %rdi
callq 0x62d0
leaq -0x549(%rbp), %rdi
callq 0x64f0
jmp 0x1b650
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b132
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x520(%rbp), %rdi
callq 0xfd80
leaq -0x4c8(%rbp), %rdi
callq 0xfd80
jmp 0x1b763
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b757
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b1e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b1da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b1c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
testb $0x1, -0x573(%rbp)
jne 0x1b1b3
jmp 0x1b1bf
leaq -0x570(%rbp), %rdi
callq 0x62d0
jmp 0x1b1c1
testb $0x1, -0x572(%rbp)
jne 0x1b1cc
jmp 0x1b1d8
leaq -0x571(%rbp), %rdi
callq 0x64f0
jmp 0x1b1da
leaq -0x548(%rbp), %rdi
callq 0x62d0
leaq -0x549(%rbp), %rdi
callq 0x64f0
jmp 0x1b757
leaq -0x388(%rbp), %rdi
callq 0x1c210
movb %al, -0x742(%rbp)
jmp 0x1b20b
movb -0x742(%rbp), %al
testb $0x1, %al
jne 0x1b21a
jmp 0x1b64e
movq 0x10(%rbp), %rdi
movq %rdi, -0x750(%rbp)
callq 0x2dd20
movl %eax, -0x748(%rbp)
jmp 0x1b232
movq -0x750(%rbp), %rdi
movl -0x748(%rbp), %eax
addl $-0x2, %eax
movl %eax, %esi
callq 0xfd10
movq %rax, %rsi
leaq -0x5d0(%rbp), %rdi
callq 0x22ce0
jmp 0x1b25a
leaq -0x658(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
callq 0x22ce0
jmp 0x1b26f
leaq -0x6b0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22ce0
jmp 0x1b284
leaq -0x600(%rbp), %rdi
leaq -0x658(%rbp), %rsi
leaq -0x6b0(%rbp), %rdx
callq 0x1bf30
jmp 0x1b2a0
leaq -0x6b0(%rbp), %rdi
callq 0xfd80
leaq -0x658(%rbp), %rdi
callq 0xfd80
leaq -0x470(%rbp), %rdi
callq 0x1c680
movb %al, -0x751(%rbp)
jmp 0x1b2cc
movb -0x751(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x758(%rbp)
leaq -0x600(%rbp), %rdi
callq 0x1c680
movb %al, -0x752(%rbp)
jmp 0x1b2f2
movl -0x758(%rbp), %eax
movb -0x752(%rbp), %cl
movzbl %cl, %ecx
andl $0x1, %ecx
subl %ecx, %eax
sete -0x6b1(%rbp)
leaq -0x5d0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x23ae0
movb %al, -0x759(%rbp)
jmp 0x1b325
movb -0x759(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x75a(%rbp)
jne 0x1b33a
jmp 0x1b35c
leaq -0x470(%rbp), %rdi
callq 0x1c680
movb %al, -0x75b(%rbp)
jmp 0x1b34e
movb -0x75b(%rbp), %al
movb %al, -0x75a(%rbp)
jmp 0x1b35c
movb -0x75a(%rbp), %al
andb $0x1, %al
movb %al, -0x6b2(%rbp)
movb -0x6b1(%rbp), %al
movb $0x0, -0x6da(%rbp)
movb $0x0, -0x6db(%rbp)
movb $0x0, -0x702(%rbp)
movb $0x0, -0x703(%rbp)
testb $0x1, %al
jne 0x1b3a5
xorl %eax, %eax
testb $0x1, -0x6b2(%rbp)
movb %al, -0x75c(%rbp)
je 0x1b484
leaq -0x6d9(%rbp), %rdi
movq %rdi, -0x768(%rbp)
callq 0x6830
movq -0x768(%rbp), %rdx
movb $0x1, -0x6da(%rbp)
leaq 0x44cc9(%rip), %rsi     # 0x60096
leaq -0x6d8(%rbp), %rdi
callq 0xfb20
jmp 0x1b3db
movb $0x1, -0x6db(%rbp)
leaq -0x470(%rbp), %rdi
leaq -0x6d8(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x769(%rbp)
jmp 0x1b3fd
movb -0x769(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x76a(%rbp)
jne 0x1b478
jmp 0x1b412
leaq -0x701(%rbp), %rdi
movq %rdi, -0x778(%rbp)
callq 0x6830
movq -0x778(%rbp), %rdx
movb $0x1, -0x702(%rbp)
leaq 0x44c5f(%rip), %rsi     # 0x60099
leaq -0x700(%rbp), %rdi
callq 0xfb20
jmp 0x1b448
movb $0x1, -0x703(%rbp)
leaq -0x470(%rbp), %rdi
leaq -0x700(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x779(%rbp)
jmp 0x1b46a
movb -0x779(%rbp), %al
movb %al, -0x76a(%rbp)
jmp 0x1b478
movb -0x76a(%rbp), %al
movb %al, -0x75c(%rbp)
movb -0x75c(%rbp), %al
andb $0x1, %al
movb %al, -0x521(%rbp)
testb $0x1, -0x703(%rbp)
jne 0x1b49d
jmp 0x1b4a9
leaq -0x700(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x702(%rbp)
jne 0x1b4b4
jmp 0x1b4c0
leaq -0x701(%rbp), %rdi
callq 0x64f0
testb $0x1, -0x6db(%rbp)
jne 0x1b4cb
jmp 0x1b4d7
leaq -0x6d8(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x6da(%rbp)
jne 0x1b4e2
jmp 0x1b4ee
leaq -0x6d9(%rbp), %rdi
callq 0x64f0
leaq -0x600(%rbp), %rdi
callq 0xfc90
leaq -0x5d0(%rbp), %rdi
callq 0xfd80
jmp 0x1b64e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b63d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x6b0(%rbp), %rdi
callq 0xfd80
leaq -0x658(%rbp), %rdi
callq 0xfd80
jmp 0x1b63d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b631
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b618
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b5ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x1b5e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
testb $0x1, -0x703(%rbp)
jne 0x1b5d8
jmp 0x1b5e4
leaq -0x700(%rbp), %rdi
callq 0x62d0
jmp 0x1b5e6
testb $0x1, -0x702(%rbp)
jne 0x1b5f1
jmp 0x1b5fd
leaq -0x701(%rbp), %rdi
callq 0x64f0
jmp 0x1b5ff
testb $0x1, -0x6db(%rbp)
jne 0x1b60a
jmp 0x1b616
leaq -0x6d8(%rbp), %rdi
callq 0x62d0
jmp 0x1b618
testb $0x1, -0x6da(%rbp)
jne 0x1b623
jmp 0x1b62f
leaq -0x6d9(%rbp), %rdi
callq 0x64f0
jmp 0x1b631
leaq -0x600(%rbp), %rdi
callq 0xfc90
leaq -0x5d0(%rbp), %rdi
callq 0xfd80
jmp 0x1b757
jmp 0x1b650
movb $0x1, %al
testb $0x1, -0x1(%rbp)
movb %al, -0x77a(%rbp)
jne 0x1b67f
movb $0x1, %al
cmpl $0x4, -0x470(%rbp)
movb %al, -0x77a(%rbp)
jle 0x1b67f
cmpl $0x8, -0x470(%rbp)
sete %al
movb %al, -0x77a(%rbp)
movb -0x77a(%rbp), %al
andb $0x1, %al
movb %al, -0x704(%rbp)
testb $0x1, -0x704(%rbp)
je 0x1b6da
movzbl -0x2(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x780(%rbp)
leaq -0x470(%rbp), %rdi
callq 0x1c680
movb %al, -0x77b(%rbp)
jmp 0x1b6b7
movl -0x780(%rbp), %eax
movb -0x77b(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x1b6da
movq -0x718(%rbp), %rax
testb $0x1, 0x54(%rax)
jne 0x1b6fa
leaq -0xd8(%rbp), %rdi
callq 0x23be0
movb %al, -0x781(%rbp)
jmp 0x1b6ee
movb -0x781(%rbp), %al
testb $0x1, %al
jne 0x1b6fa
jmp 0x1b717
testb $0x1, -0x521(%rbp)
je 0x1b717
movq -0x720(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x101f0
jmp 0x1b715
jmp 0x1b717
leaq -0x470(%rbp), %rdi
callq 0xfc90
movl $0x0, -0x43c(%rbp)
leaq -0x388(%rbp), %rdi
callq 0xfc90
leaq -0xd8(%rbp), %rdi
callq 0xfd80
leaq -0x80(%rbp), %rdi
callq 0xfd80
addq $0x790, %rsp            # imm = 0x790
popq %rbp
retq
leaq -0x470(%rbp), %rdi
callq 0xfc90
leaq -0x388(%rbp), %rdi
callq 0xfc90
leaq -0xd8(%rbp), %rdi
callq 0xfd80
leaq -0x80(%rbp), %rdi
callq 0xfd80
movq -0xe0(%rbp), %rdi
callq 0x6820