// File: /workspace/github_cpp_makefile_star2_O1/joao18araujo[P]pierluigi/src/second_species_counterpoint.cpp
// Function: SecondSpeciesCounterpoint::analyse_and_add_interval(bool, bool, std::vector<Interval, std::allocator<Interval>>&, Note, Note, Interval, Song*)
void SecondSpeciesCounterpoint::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_or_passing = true;
  if(interval.is_dissonant()){
    is_valid_or_passing = (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);
    is_valid_or_passing = (melodic_interval.ascendant() == previous_melodic_interval.ascendant())
                          && (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_or_passing)
    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 0x238c0
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 0x9beede3(%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 0x237c9
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x237e4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x540(%rsp), %rdi
cmpq %r14, %rdi
je 0x23801
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 0x23832
movq 0x520(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x500(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23853
movq 0x500(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x4b0(%rsp), %rdi
callq 0xb51e
movq 0xd0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2387d
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x598(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2389e
movq 0x598(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x578(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x239fc
movq 0x578(%rsp), %rsi
jmp 0x239f4
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 0x23982
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2399d
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0x239ba
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x490(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x239db
movq 0x490(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x470(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x239fc
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 0x23a5f
movq 0x3e0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x3c0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23a80
movq 0x3c0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x438(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23aa1
movq 0x438(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x418(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23ac2
movq 0x418(%rsp), %rsi
incq %rsi
callq 0x5360
cmpb $0x1, 0x18c(%rsp)
jne 0x23f3f
movq %rbx, %rdi
callq 0x15566
testb %al, %al
je 0x23af1
leaq 0x190(%rsp), %rdi
callq 0x15566
testb %al, %al
jne 0x23f3f
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 0x23b59
movq 0x330(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x310(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23b7a
movq 0x310(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x388(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23b9b
movq 0x388(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x368(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23bbc
movq 0x368(%rsp), %rsi
incq %rsi
callq 0x5360
movq %rbx, %rdi
callq 0x15566
testb %al, %al
je 0x23c78
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x174d5(%rip), %rsi     # 0x3b0b2
leaq 0x174d0(%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 0x23c40
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1749b(%rip), %rsi     # 0x3b0b5
leaq 0x17496(%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 0x23c60
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23c60
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x23ec5
movq 0x20(%rsp), %rsi
jmp 0x23ebd
leaq 0x190(%rsp), %rdi
callq 0x15566
movb $0x1, %r14b
testb %al, %al
je 0x23ec5
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 0x23d0e
movq 0x280(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x260(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23d2f
movq 0x260(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x2d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23d50
movq 0x2d8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x2b8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23d71
movq 0x2b8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x98(%rsp), %rdi
callq 0x15b78
movl %eax, %r13d
leaq 0x68(%rsp), %rdi
callq 0x15b78
xorb %al, %r13b
je 0x23d9a
xorl %eax, %eax
xorl %r14d, %r14d
jmp 0x23e23
leaq 0x128(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x17304(%rip), %rsi     # 0x3b0b2
leaq 0x172ff(%rip), %rdx     # 0x3b0b4
leaq 0x118(%rsp), %rdi
callq 0xb62c
leaq 0x98(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x15334
testb %al, %al
je 0x23de2
movb $0x1, %r14b
xorl %eax, %eax
jmp 0x23e23
leaq 0x108(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x172c0(%rip), %rsi     # 0x3b0b5
leaq 0x172bb(%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 0x23e48
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23e48
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5360
testb %r13b, %r13b
jne 0x23e6e
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23e6e
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23e8f
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23eaa
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23ec5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5360
cmpb $0x0, 0xc(%rsp)
jne 0x23edd
movl 0x98(%rsp), %eax
cmpl $0x5, %eax
jl 0x23edd
cmpl $0x8, %eax
jne 0x23f01
leaq 0x98(%rsp), %rdi
callq 0x15b78
cmpb 0x8(%rsp), %al
jne 0x23f01
movq (%rsp), %rax
cmpb $0x0, 0x54(%rax)
je 0x23f01
testb %r14b, %r14b
jne 0x23f13
jmp 0x23f1e
leaq 0x1f0(%rsp), %rdi
callq 0x1c186
testb %al, %r14b
je 0x23f1e
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xb262
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23f3f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x1a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23f60
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x228(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23f81
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x208(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23fa2
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x170(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23fc3
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x23fe4
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 0x2401d
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x2401d
jmp 0x2401a
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0x24088
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x24088
jmp 0x24085
movq %rax, %rbx
leaq 0x248(%rsp), %rdi
callq 0xb116
jmp 0x24053
movq %rax, %rbx
leaq 0x2a0(%rsp), %rdi
callq 0xb116
jmp 0x240a9
movq %rax, %rbx
jmp 0x240a9
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x240c0
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x240c0
jmp 0x240bd
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x240a9
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x10(%rsp), %rdi
callq 0xb116
jmp 0x24164
jmp 0x24161
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x24164
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x24164
jmp 0x24161
movq %rax, %rbx
leaq 0x2f8(%rsp), %rdi
callq 0xb116
jmp 0x240f7
movq %rax, %rbx
leaq 0x350(%rsp), %rdi
callq 0xb116
jmp 0x2418a
jmp 0x24187
movq %rax, %rbx
jmp 0x241e8
movq %rax, %rbx
movq %r12, %rdi
callq 0xb116
jmp 0x24123
movq %rax, %rbx
leaq 0x4b0(%rsp), %rdi
callq 0xb51e
jmp 0x241f5
movq %rax, %rbx
jmp 0x24231
movq %rax, %rbx
jmp 0x241f5
movq %rax, %rbx
jmp 0x2424e
movq %rax, %rbx
jmp 0x2421a
jmp 0x2425d
jmp 0x2425d
jmp 0x24161
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2418a
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x2418a
movq %rax, %rbx
leaq 0x1a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24260
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x24260
movq %rax, %rbx
leaq 0x3a8(%rsp), %rdi
callq 0xb116
jmp 0x241c9
movq %rax, %rbx
leaq 0x400(%rsp), %rdi
jmp 0x24256
jmp 0x2425d
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 0x2421a
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x560(%rsp), %rdi
jmp 0x24256
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xb116
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2424e
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0x458(%rsp), %rdi
callq 0xb116
jmp 0x24260
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0xb116
leaq 0x138(%rsp), %rdi
callq 0xb116
movq %rbx, %rdi
callq 0x55e0
movq %rax, %rbx
jmp 0x2426d
nop