// File: Wombozo[P]harmony/src/Interval.cpp
// Function: Interval::getNextSorted(Note*)
Note *Interval::getNextSorted(Note *a)
{

    Note *tmp;
    // Get the natural note
    NaturalNote *ntmp = a->getNatural();
    for (int i = 0; i < type - 1; i++)
    {
        ntmp = ntmp->next;
    }
    // Test for altered notes
    SharpNote *stmp;
    FlatNote *ftmp;
    DblSharpNote *sstmp;
    DblFlatNote *fftmp;

    if (getSemiTones() == a->semiToneShift() + ntmp->getNextSTNatural())
    {
        tmp = (Note *)ntmp;
    }
    else if (getSemiTones() == a->semiToneShift() + ntmp->getNextSTNatural() + 1)
    {
        tmp = (Note *)ntmp->sn;
    }
    else if (getSemiTones() == a->semiToneShift() + ntmp->getNextSTNatural() - 1)
    {
        tmp = (Note *)ntmp->fn;
    }
    else if (getSemiTones() == a->semiToneShift() + ntmp->getNextSTNatural() + 2)
    {
        tmp = (Note *)ntmp->sn->sharp;
    }
    else if (getSemiTones() == a->semiToneShift() + ntmp->getNextSTNatural() - 2)
    {
        tmp = (Note *)ntmp->fn->flat;
    }
    else
    {
        throw E_INTERVAL;
    }
    return tmp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %eax
movl 0x20(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xbf78
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x20(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xbf50
movq -0x50(%rbp), %rdi
callq 0xc210
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2d0
movl -0x58(%rbp), %ecx
movl %eax, %edx
movl -0x54(%rbp), %eax
addl %edx, %ecx
cmpl %ecx, %eax
jne 0xbfd8
movq -0x20(%rbp), %rcx
movq %rcx, -0x68(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x60(%rbp)
je 0xbfcb
movq -0x68(%rbp), %rax
movq (%rax), %rcx
addq -0x38(%rcx), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xc1f5
movq -0x50(%rbp), %rdi
callq 0xc210
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2d0
movl -0x70(%rbp), %ecx
movl %eax, %edx
movl -0x6c(%rbp), %eax
addl %edx, %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc03f
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rcx
movq %rcx, -0x80(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x78(%rbp)
je 0xc032
movq -0x80(%rbp), %rax
movq (%rax), %rcx
addq -0x38(%rcx), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xc1f3
movq -0x50(%rbp), %rdi
callq 0xc210
movl %eax, -0x84(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2d0
movl -0x88(%rbp), %ecx
movl %eax, %edx
movl -0x84(%rbp), %eax
addl %edx, %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc0c1
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rcx
movq %rcx, -0x98(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x90(%rbp)
je 0xc0b1
movq -0x98(%rbp), %rax
movq (%rax), %rcx
addq -0x38(%rcx), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xc1f1
movq -0x50(%rbp), %rdi
callq 0xc210
movl %eax, -0x9c(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2d0
movl -0xa0(%rbp), %ecx
movl %eax, %edx
movl -0x9c(%rbp), %eax
addl %edx, %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jne 0xc147
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0xb0(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0xa8(%rbp)
je 0xc137
movq -0xb0(%rbp), %rax
movq (%rax), %rcx
addq -0x38(%rcx), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xc1ef
movq -0x50(%rbp), %rdi
callq 0xc210
movl %eax, -0xb4(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, -0xb8(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2d0
movl -0xb8(%rbp), %ecx
movl %eax, %edx
movl -0xb4(%rbp), %eax
addl %edx, %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jne 0xc1ca
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0xc8(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0xc0(%rbp)
je 0xc1bd
movq -0xc8(%rbp), %rax
movq (%rax), %rcx
addq -0x38(%rcx), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xc1ed
movl $0x4, %edi
callq 0x3140
movq %rax, %rdi
movl $0x0, (%rdi)
leaq 0x14654(%rip), %rsi     # 0x20838
xorl %eax, %eax
movl %eax, %edx
callq 0x33a0
jmp 0xc1ef
jmp 0xc1f1
jmp 0xc1f3
jmp 0xc1f5
movq -0x18(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)