// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5b8, %rsp            # imm = 0x5B8
movq %r9, %rbx
movq %r8, (%rsp)
movq %rcx, %r13
movq %rdx, %rbp
movl %esi, 0x8(%rsp)
movl %edi, 0xc(%rsp)
movq 0x5f0(%rsp), %r15
leaq 0x138(%rsp), %rdi
callq 0x1aa88
movq 0x8(%r15), %rsi
addq $-0x58, %rsi
leaq 0x1f0(%rsp), %rdi
callq 0x1a9c6
movq %rbx, %rdi
callq 0x15606
testb %al, %al
je 0x143e2
leaq 0x560(%rsp), %rdi
movq (%rsp), %rsi
callq 0x1a9c6
movl (%rbx), %eax
leaq 0xd0(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
addq %rsi, %rdx
callq 0xb544
movzwl 0x2c(%rbx), %eax
movw %ax, 0xf4(%rsp)
movl 0x28(%rbx), %eax
movl %eax, 0xf0(%rsp)
leaq 0x9bfe2c1(%rip), %rax   # 0x9c124a8
movq (%rax), %r15
leaq 0x18(%r15), %rsi
xorl %eax, %eax
leaq 0x4b0(%rsp), %rdi
movq %rax, (%rdi)
movq 0x20(%r15), %rcx
movq %rcx, 0x8(%rdi)
movq %rax, 0x10(%rdi)
movq 0x30(%r15), %rcx
movq %rcx, 0x18(%rdi)
movups 0x38(%r15), %xmm0
movups %xmm0, 0x20(%rdi)
movq %rax, 0x30(%rdi)
leaq 0x190(%rsp), %rdx
movq %rdi, (%rdx)
callq 0xb2d2
leaq 0x4e8(%rsp), %r12
leaq 0x50(%r15), %rsi
movq %r12, %rdi
callq 0x1a9c6
leaq 0x540(%rsp), %rdi
leaq 0x550(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa8(%r15), %rsi
movq 0xb0(%r15), %rdx
addq %rsi, %rdx
callq 0xb544
leaq 0x10(%rsp), %rdi
leaq 0x560(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
leaq 0x4b0(%rsp), %rcx
callq 0x1de56
leaq 0x18(%rsp), %rsi
movq -0x8(%rsi), %rax
leaq 0x140(%rsp), %rdi
movq %rax, -0x8(%rdi)
callq 0x51e0
leaq 0x160(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x51e0
leaq 0x48(%rsp), %rax
movq 0x16(%rax), %rcx
movq %rcx, 0x186(%rsp)
movq -0x10(%rax), %rdi
movq 0x10(%rax), %rcx
movq %rcx, 0x180(%rsp)
cmpq %rax, %rdi
je 0x142eb
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14306
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x540(%rsp), %rdi
cmpq %r14, %rdi
je 0x14323
movq 0x550(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x520(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq 0x5f0(%rsp), %r15
leaq 0xe0(%rsp), %r14
je 0x14354
movq 0x520(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x500(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14375
movq 0x500(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x4b0(%rsp), %rdi
callq 0xb51e
movq 0xd0(%rsp), %rdi
cmpq %r14, %rdi
je 0x1439f
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x598(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x143c0
movq 0x598(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x578(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1451e
movq 0x578(%rsp), %rsi
jmp 0x14516
leaq 0x458(%rsp), %rdi
movq (%rsp), %rsi
callq 0x1a9c6
movl (%rbx), %eax
leaq 0x1c8(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0x1d8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
addq %rsi, %rdx
callq 0xb544
movzwl 0x2c(%rbx), %eax
leaq 0x1c0(%rsp), %rdx
movw %ax, 0x2c(%rdx)
movl 0x28(%rbx), %eax
movl %eax, 0x28(%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x458(%rsp), %rsi
callq 0x15a46
leaq 0x18(%rsp), %rsi
movq -0x8(%rsi), %rax
leaq 0x140(%rsp), %rdi
movq %rax, -0x8(%rdi)
callq 0x51e0
leaq 0x160(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x51e0
leaq 0x48(%rsp), %rax
movq 0x16(%rax), %rcx
movq %rcx, 0x186(%rsp)
movq -0x10(%rax), %rdi
movq 0x10(%rax), %rcx
movq %rcx, 0x180(%rsp)
cmpq %rax, %rdi
je 0x144a4
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x144bf
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0x144dc
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x490(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x144fd
movq 0x490(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x470(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1451e
movq 0x470(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x400(%rsp), %rdi
movq %r13, %rsi
callq 0x1a9c6
leaq 0x3a8(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x1a9c6
leaq 0x190(%rsp), %rdi
leaq 0x400(%rsp), %rsi
leaq 0x3a8(%rsp), %rdx
callq 0x15216
leaq 0x3e0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14581
movq 0x3e0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x3c0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x145a2
movq 0x3c0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x438(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x145c3
movq 0x438(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x418(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x145e4
movq 0x418(%rsp), %rsi
incq %rsi
callq 0x5360
cmpb $0x1, 0x18c(%rsp)
jne 0x14a93
movq %rbx, %rdi
callq 0x15566
testb %al, %al
je 0x14613
leaq 0x190(%rsp), %rdi
callq 0x15566
testb %al, %al
jne 0x14a93
leaq 0x350(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x1a9c6
leaq 0x2f8(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x1a9c6
leaq 0x98(%rsp), %rdi
leaq 0x350(%rsp), %rsi
leaq 0x2f8(%rsp), %rdx
callq 0x15216
leaq 0x330(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1467b
movq 0x330(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x310(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1469c
movq 0x310(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x388(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x146bd
movq 0x388(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x368(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x146de
movq 0x368(%rsp), %rsi
incq %rsi
callq 0x5360
movq %rbx, %rdi
callq 0x15566
testb %al, %al
je 0x1479a
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x269b3(%rip), %rsi     # 0x3b0b2
leaq 0x269ae(%rip), %rdx     # 0x3b0b4
leaq 0x10(%rsp), %rdi
callq 0xb62c
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x15334
movl %eax, %r13d
movb $0x1, %r14b
testb %al, %al
jne 0x14762
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x26979(%rip), %rsi     # 0x3b0b5
leaq 0x26974(%rip), %rdx     # 0x3b0b7
leaq 0x68(%rsp), %rdi
callq 0xb62c
leaq 0x98(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x15334
movl %eax, %r14d
testb %r13b, %r13b
jne 0x14782
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14782
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x14a19
movq 0x20(%rsp), %rsi
jmp 0x14a11
leaq 0x190(%rsp), %rdi
callq 0x15566
movb $0x1, %r14b
testb %al, %al
je 0x14a19
movq %r15, %rdi
callq 0x24288
addl $-0x2, %eax
imulq $0x58, %rax, %rsi
addq (%r15), %rsi
leaq 0x10(%rsp), %rdi
callq 0x1a9c6
leaq 0x2a0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1a9c6
leaq 0x248(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x1a9c6
leaq 0x68(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
leaq 0x248(%rsp), %rdx
callq 0x15216
leaq 0x280(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14830
movq 0x280(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x260(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14851
movq 0x260(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x2d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14872
movq 0x2d8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x2b8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14893
movq 0x2b8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x98(%rsp), %rdi
callq 0x15b78
movl %eax, %r13d
leaq 0x68(%rsp), %rdi
callq 0x15b78
movl %eax, %r14d
leaq 0x10(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x1c028
testb %al, %al
je 0x148d5
leaq 0x98(%rsp), %rdi
callq 0x15b78
jmp 0x148d7
xorl %eax, %eax
xorb %r14b, %r13b
xorb $0x1, %r13b
orb %al, %r13b
cmpb $0x1, %r13b
jne 0x1492f
leaq 0x128(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x267b7(%rip), %rsi     # 0x3b0b2
leaq 0x267b2(%rip), %rdx     # 0x3b0b4
leaq 0x118(%rsp), %rdi
callq 0xb62c
leaq 0x98(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x15334
testb %al, %al
je 0x14936
movb $0x1, %r14b
xorl %eax, %eax
jmp 0x14977
xorl %eax, %eax
xorl %r14d, %r14d
jmp 0x14977
leaq 0x108(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2676c(%rip), %rsi     # 0x3b0b5
leaq 0x26767(%rip), %rdx     # 0x3b0b7
leaq 0xf8(%rsp), %rdi
callq 0xb62c
leaq 0x98(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x15334
movl %eax, %r14d
movb $0x1, %al
testb %al, %al
je 0x1499c
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1499c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5360
testb %r13b, %r13b
je 0x149c2
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x149c2
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x149e3
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x149fe
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14a19
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5360
cmpb $0x0, 0xc(%rsp)
jne 0x14a31
movl 0x98(%rsp), %eax
cmpl $0x5, %eax
jl 0x14a31
cmpl $0x8, %eax
jne 0x14a55
leaq 0x98(%rsp), %rdi
callq 0x15b78
cmpb 0x8(%rsp), %al
jne 0x14a55
movq (%rsp), %rax
cmpb $0x0, 0x54(%rax)
je 0x14a55
testb %r14b, %r14b
jne 0x14a67
jmp 0x14a72
leaq 0x1f0(%rsp), %rdi
callq 0x1c186
testb %al, %r14b
je 0x14a72
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xb262
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14a93
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x1a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14ab4
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x228(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14ad5
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x208(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14af6
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x170(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14b17
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14b38
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x5360
addq $0x5b8, %rsp            # imm = 0x5B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x14b71
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x14b71
jmp 0x14b6e
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0x14bde
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x14bde
jmp 0x14bdb
movq %rax, %rbx
leaq 0x248(%rsp), %rdi
callq 0xb116
jmp 0x14ba7
movq %rax, %rbx
leaq 0x2a0(%rsp), %rdi
callq 0xb116
jmp 0x14bff
movq %rax, %rbx
jmp 0x14bff
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x14c16
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x14c16
jmp 0x14c13
jmp 0x14bdb
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14bff
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x10(%rsp), %rdi
callq 0xb116
jmp 0x14cba
jmp 0x14cb7
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x14cba
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x14cba
jmp 0x14cb7
movq %rax, %rbx
leaq 0x2f8(%rsp), %rdi
callq 0xb116
jmp 0x14c4d
movq %rax, %rbx
leaq 0x350(%rsp), %rdi
callq 0xb116
jmp 0x14ce0
jmp 0x14cdd
movq %rax, %rbx
jmp 0x14d3e
movq %rax, %rbx
movq %r12, %rdi
callq 0xb116
jmp 0x14c79
movq %rax, %rbx
leaq 0x4b0(%rsp), %rdi
callq 0xb51e
jmp 0x14d4b
movq %rax, %rbx
jmp 0x14d87
movq %rax, %rbx
jmp 0x14d4b
movq %rax, %rbx
jmp 0x14da4
movq %rax, %rbx
jmp 0x14d70
jmp 0x14db3
jmp 0x14db3
jmp 0x14cb7
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14ce0
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x14ce0
movq %rax, %rbx
leaq 0x1a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14db6
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x14db6
movq %rax, %rbx
leaq 0x3a8(%rsp), %rdi
callq 0xb116
jmp 0x14d1f
movq %rax, %rbx
leaq 0x400(%rsp), %rdi
jmp 0x14dac
jmp 0x14db3
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xb116
leaq 0x4b0(%rsp), %rdi
callq 0xb206
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x14d70
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x560(%rsp), %rdi
jmp 0x14dac
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xb116
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0x14da4
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x458(%rsp), %rdi
callq 0xb116
jmp 0x14db6
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0xb116
leaq 0x138(%rsp), %rdi
callq 0xb116
movq %rbx, %rdi
callq 0x55e0
movq %rax, %rbx
jmp 0x14dc3
nop