// File: 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
movq %rsp, %rbp
subq $0x780, %rsp            # imm = 0x780
movq %r9, -0x718(%rbp)
movq %r8, -0x710(%rbp)
movq %rcx, -0x708(%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 0x2d1da
movq -0x718(%rbp), %rdi
callq 0x1c270
movb %al, -0x719(%rbp)
jmp 0x2d1ee
movb -0x719(%rbp), %al
testb $0x1, %al
jne 0x2d1fd
jmp 0x2d35e
movq -0x710(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x22ce0
jmp 0x2d212
movq -0x718(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0xfdb0
jmp 0x2d227
leaq 0x9c1e3ba(%rip), %rax   # 0x9c4b5e8
movq (%rax), %rsi
addq $0x18, %rsi
leaq -0x278(%rbp), %rdi
callq 0x10110
jmp 0x2d243
leaq -0x140(%rbp), %rdi
leaq -0x198(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
leaq -0x278(%rbp), %rcx
callq 0x27790
jmp 0x2d266
leaq -0x80(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xfe00
jmp 0x2d278
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 0x2d43f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dd05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dcf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d34d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d341
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d335
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 0x2dcf9
movq -0x710(%rbp), %rsi
leaq -0x328(%rbp), %rdi
callq 0x22ce0
jmp 0x2d373
movq -0x718(%rbp), %rsi
leaq -0x358(%rbp), %rdi
callq 0xfdb0
jmp 0x2d388
leaq -0x2d0(%rbp), %rdi
leaq -0x328(%rbp), %rsi
leaq -0x358(%rbp), %rdx
callq 0x1c440
jmp 0x2d3a4
leaq -0x80(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0xfe00
jmp 0x2d3b6
leaq -0x2d0(%rbp), %rdi
callq 0xfd80
leaq -0x358(%rbp), %rdi
callq 0xfc90
leaq -0x328(%rbp), %rdi
callq 0xfd80
jmp 0x2d43f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d42e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d422
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 0x2dcf9
movq -0x708(%rbp), %rsi
leaq -0x3e0(%rbp), %rdi
callq 0x22ce0
jmp 0x2d454
leaq -0x438(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22ce0
jmp 0x2d469
leaq -0x388(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
leaq -0x438(%rbp), %rdx
callq 0x1bf30
jmp 0x2d485
leaq -0x438(%rbp), %rdi
callq 0xfd80
leaq -0x3e0(%rbp), %rdi
callq 0xfd80
testb $0x1, -0x2c(%rbp)
je 0x2d4e6
movq -0x718(%rbp), %rdi
callq 0x1c210
movb %al, -0x71a(%rbp)
jmp 0x2d4b7
movb -0x71a(%rbp), %al
testb $0x1, %al
jne 0x2d4c6
jmp 0x2d54f
leaq -0x388(%rbp), %rdi
callq 0x1c210
movb %al, -0x71b(%rbp)
jmp 0x2d4da
movb -0x71b(%rbp), %al
testb $0x1, %al
jne 0x2d4e6
jmp 0x2d54f
movl $0x1, -0x43c(%rbp)
jmp 0x2dcb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d527
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 0x2dcf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dced
leaq -0x4c8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22ce0
jmp 0x2d564
leaq -0x520(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x22ce0
jmp 0x2d576
leaq -0x470(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
leaq -0x520(%rbp), %rdx
callq 0x1bf30
jmp 0x2d592
leaq -0x520(%rbp), %rdi
callq 0xfd80
leaq -0x4c8(%rbp), %rdi
callq 0xfd80
movq -0x718(%rbp), %rdi
movb $0x1, -0x521(%rbp)
callq 0x1c210
movb %al, -0x71c(%rbp)
jmp 0x2d5c5
movb -0x71c(%rbp), %al
testb $0x1, %al
jne 0x2d5d4
jmp 0x2d7f7
leaq -0x549(%rbp), %rdi
movq %rdi, -0x728(%rbp)
callq 0x6830
movq -0x728(%rbp), %rdx
movb $0x0, -0x572(%rbp)
movb $0x0, -0x573(%rbp)
leaq 0x32a93(%rip), %rsi     # 0x60096
leaq -0x548(%rbp), %rdi
callq 0xfb20
jmp 0x2d611
leaq -0x470(%rbp), %rdi
leaq -0x548(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x729(%rbp)
jmp 0x2d62c
movb -0x729(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x72a(%rbp)
jne 0x2d6a7
jmp 0x2d641
leaq -0x571(%rbp), %rdi
movq %rdi, -0x738(%rbp)
callq 0x6830
movq -0x738(%rbp), %rdx
movb $0x1, -0x572(%rbp)
leaq 0x32a30(%rip), %rsi     # 0x60099
leaq -0x570(%rbp), %rdi
callq 0xfb20
jmp 0x2d677
movb $0x1, -0x573(%rbp)
leaq -0x470(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x739(%rbp)
jmp 0x2d699
movb -0x739(%rbp), %al
movb %al, -0x72a(%rbp)
jmp 0x2d6a7
movb -0x72a(%rbp), %al
andb $0x1, %al
movb %al, -0x521(%rbp)
testb $0x1, -0x573(%rbp)
jne 0x2d6c0
jmp 0x2d6cc
leaq -0x570(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x572(%rbp)
jne 0x2d6d7
jmp 0x2d6e3
leaq -0x571(%rbp), %rdi
callq 0x64f0
leaq -0x548(%rbp), %rdi
callq 0x62d0
leaq -0x549(%rbp), %rdi
callq 0x64f0
jmp 0x2dbda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d732
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 0x2dced
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dce1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d7e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2d7c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
testb $0x1, -0x573(%rbp)
jne 0x2d7b3
jmp 0x2d7bf
leaq -0x570(%rbp), %rdi
callq 0x62d0
jmp 0x2d7c1
testb $0x1, -0x572(%rbp)
jne 0x2d7cc
jmp 0x2d7d8
leaq -0x571(%rbp), %rdi
callq 0x64f0
jmp 0x2d7da
leaq -0x548(%rbp), %rdi
callq 0x62d0
leaq -0x549(%rbp), %rdi
callq 0x64f0
jmp 0x2dce1
leaq -0x388(%rbp), %rdi
callq 0x1c210
movb %al, -0x73a(%rbp)
jmp 0x2d80b
movb -0x73a(%rbp), %al
testb $0x1, %al
jne 0x2d81a
jmp 0x2dbd8
movq 0x10(%rbp), %rdi
movq %rdi, -0x748(%rbp)
callq 0x2dd20
movl %eax, -0x740(%rbp)
jmp 0x2d832
movq -0x748(%rbp), %rdi
movl -0x740(%rbp), %eax
addl $-0x2, %eax
movl %eax, %esi
callq 0xfd10
movq %rax, %rsi
leaq -0x5d0(%rbp), %rdi
callq 0x22ce0
jmp 0x2d85a
leaq -0x658(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
callq 0x22ce0
jmp 0x2d86f
leaq -0x6b0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22ce0
jmp 0x2d884
leaq -0x600(%rbp), %rdi
leaq -0x658(%rbp), %rsi
leaq -0x6b0(%rbp), %rdx
callq 0x1bf30
jmp 0x2d8a0
leaq -0x6b0(%rbp), %rdi
callq 0xfd80
leaq -0x658(%rbp), %rdi
callq 0xfd80
movb $0x0, -0x6d2(%rbp)
movb $0x0, -0x6d3(%rbp)
movb $0x0, -0x6fa(%rbp)
movb $0x0, -0x6fb(%rbp)
leaq -0x470(%rbp), %rdi
callq 0x1c680
movb %al, -0x749(%rbp)
jmp 0x2d8e8
movb -0x749(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x750(%rbp)
leaq -0x600(%rbp), %rdi
callq 0x1c680
movb %al, -0x74a(%rbp)
jmp 0x2d90e
movl -0x750(%rbp), %ecx
movb -0x74a(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x751(%rbp)
jne 0x2da0e
leaq -0x6d1(%rbp), %rdi
movq %rdi, -0x760(%rbp)
callq 0x6830
movq -0x760(%rbp), %rdx
movb $0x1, -0x6d2(%rbp)
leaq 0x3273f(%rip), %rsi     # 0x60096
leaq -0x6d0(%rbp), %rdi
callq 0xfb20
jmp 0x2d965
movb $0x1, -0x6d3(%rbp)
leaq -0x470(%rbp), %rdi
leaq -0x6d0(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x761(%rbp)
jmp 0x2d987
movb -0x761(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x762(%rbp)
jne 0x2da02
jmp 0x2d99c
leaq -0x6f9(%rbp), %rdi
movq %rdi, -0x770(%rbp)
callq 0x6830
movq -0x770(%rbp), %rdx
movb $0x1, -0x6fa(%rbp)
leaq 0x326d5(%rip), %rsi     # 0x60099
leaq -0x6f8(%rbp), %rdi
callq 0xfb20
jmp 0x2d9d2
movb $0x1, -0x6fb(%rbp)
leaq -0x470(%rbp), %rdi
leaq -0x6f8(%rbp), %rsi
callq 0x1c0b0
movb %al, -0x771(%rbp)
jmp 0x2d9f4
movb -0x771(%rbp), %al
movb %al, -0x762(%rbp)
jmp 0x2da02
movb -0x762(%rbp), %al
movb %al, -0x751(%rbp)
movb -0x751(%rbp), %al
andb $0x1, %al
movb %al, -0x521(%rbp)
testb $0x1, -0x6fb(%rbp)
jne 0x2da27
jmp 0x2da33
leaq -0x6f8(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x6fa(%rbp)
jne 0x2da3e
jmp 0x2da4a
leaq -0x6f9(%rbp), %rdi
callq 0x64f0
testb $0x1, -0x6d3(%rbp)
jne 0x2da55
jmp 0x2da61
leaq -0x6d0(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x6d2(%rbp)
jne 0x2da6c
jmp 0x2da78
leaq -0x6d1(%rbp), %rdi
callq 0x64f0
leaq -0x600(%rbp), %rdi
callq 0xfc90
leaq -0x5d0(%rbp), %rdi
callq 0xfd80
jmp 0x2dbd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dbc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dade
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 0x2dbc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dbbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2dba2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2db89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0x2db70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
testb $0x1, -0x6fb(%rbp)
jne 0x2db62
jmp 0x2db6e
leaq -0x6f8(%rbp), %rdi
callq 0x62d0
jmp 0x2db70
testb $0x1, -0x6fa(%rbp)
jne 0x2db7b
jmp 0x2db87
leaq -0x6f9(%rbp), %rdi
callq 0x64f0
jmp 0x2db89
testb $0x1, -0x6d3(%rbp)
jne 0x2db94
jmp 0x2dba0
leaq -0x6d0(%rbp), %rdi
callq 0x62d0
jmp 0x2dba2
testb $0x1, -0x6d2(%rbp)
jne 0x2dbad
jmp 0x2dbb9
leaq -0x6d1(%rbp), %rdi
callq 0x64f0
jmp 0x2dbbb
leaq -0x600(%rbp), %rdi
callq 0xfc90
leaq -0x5d0(%rbp), %rdi
callq 0xfd80
jmp 0x2dce1
jmp 0x2dbda
movb $0x1, %al
testb $0x1, -0x1(%rbp)
movb %al, -0x772(%rbp)
jne 0x2dc09
movb $0x1, %al
cmpl $0x4, -0x470(%rbp)
movb %al, -0x772(%rbp)
jle 0x2dc09
cmpl $0x8, -0x470(%rbp)
sete %al
movb %al, -0x772(%rbp)
movb -0x772(%rbp), %al
andb $0x1, %al
movb %al, -0x6fc(%rbp)
testb $0x1, -0x6fc(%rbp)
je 0x2dc64
movzbl -0x2(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x778(%rbp)
leaq -0x470(%rbp), %rdi
callq 0x1c680
movb %al, -0x773(%rbp)
jmp 0x2dc41
movl -0x778(%rbp), %eax
movb -0x773(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x2dc64
movq -0x710(%rbp), %rax
testb $0x1, 0x54(%rax)
jne 0x2dc84
leaq -0xd8(%rbp), %rdi
callq 0x23be0
movb %al, -0x779(%rbp)
jmp 0x2dc78
movb -0x779(%rbp), %al
testb $0x1, %al
jne 0x2dc84
jmp 0x2dca1
testb $0x1, -0x521(%rbp)
je 0x2dca1
movq -0x718(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x101f0
jmp 0x2dc9f
jmp 0x2dca1
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 $0x780, %rsp            # imm = 0x780
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
nopw (%rax,%rax)