// File: GouMinghao[P]graspnms/./graspnms.cpp
// Function: grasp_nms(double_array, tuple_thresh)
double_array grasp_nms(double_array da_in, tuple_thresh th)
{
    vector<unsigned int> sorted_arg_v = argsort_grasp(da_in);
    list<unsigned int> sorted_arg(sorted_arg_v.begin(), sorted_arg_v.end());
    list<unsigned int>::iterator current_num_grasp = sorted_arg.begin();
    list<unsigned int>::iterator num_grasp, next_grasp;
    while (current_num_grasp != sorted_arg.end())
    {
        num_grasp = current_num_grasp;
        num_grasp++;
        while (num_grasp != sorted_arg.end())
        {
            if (iou(da_in.data + da_in.c * (*current_num_grasp), da_in.data + da_in.c * (*num_grasp)).smaller(th))
            {
                num_grasp = sorted_arg.erase(num_grasp);
            }
            else
            {
                num_grasp++;
            }
        }
        current_num_grasp++;
    }
    double_array da_out(sorted_arg.size(), da_in.c);
    num_grasp = sorted_arg.begin();
    for (int i = 0; i < sorted_arg.size(); i++)
    {
        memcpy(da_out.data + i * da_in.c, da_in.data + (*num_grasp) * da_in.c, da_in.c * sizeof(double));
        num_grasp++;
    }
    return da_out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rsi, -0x130(%rbp)
movq %rdi, -0x128(%rbp)
movq %rdi, %rax
movq %rax, -0x120(%rbp)
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rsi, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0xce30
movq -0x118(%rbp), %rdi
callq 0x164f0
movq -0x118(%rbp), %rdi
movq %rax, -0x58(%rbp)
callq 0x16520
movq %rax, -0x60(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x16550
movq -0x110(%rbp), %rcx
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x16570
jmp 0xca7f
leaq -0x61(%rbp), %rdi
callq 0x16620
leaq -0x50(%rbp), %rdi
callq 0x16640
movq %rax, -0x80(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x16670
leaq -0x90(%rbp), %rdi
callq 0x16670
leaq -0x50(%rbp), %rdi
callq 0x166c0
movq %rax, -0x98(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x16690
testb $0x1, %al
jne 0xcad6
jmp 0xccb8
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x166f0
movq %rax, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x166c0
movq %rax, -0xa8(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x16690
testb $0x1, %al
jne 0xcb22
jmp 0xcca1
movq -0x130(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x160(%rbp)
movl 0xc(%rax), %eax
movl %eax, -0x164(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x16720
movl -0x164(%rbp), %edx
movq -0x160(%rbp), %rcx
movq %rax, %rsi
movq -0x130(%rbp), %rax
movl (%rsi), %esi
imull %esi, %edx
leaq (%rcx,%rdx,8), %rcx
movq %rcx, -0x150(%rbp)
movq (%rax), %rcx
movq %rcx, -0x148(%rbp)
movl 0xc(%rax), %eax
movl %eax, -0x154(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x16720
movl -0x154(%rbp), %ecx
movq -0x150(%rbp), %rdi
movq %rax, %rdx
movq -0x148(%rbp), %rax
movl (%rdx), %edx
imull %edx, %ecx
leaq (%rax,%rcx,8), %rsi
callq 0xcf30
movsd %xmm1, -0x140(%rbp)
movsd %xmm0, -0x138(%rbp)
jmp 0xcbc2
movsd -0x140(%rbp), %xmm0
movsd -0x138(%rbp), %xmm1
movsd %xmm1, -0xb8(%rbp)
movsd %xmm0, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
leaq -0xb8(%rbp), %rdi
callq 0xc7b0
cmpl $0x0, %eax
je 0xcc87
leaq -0xd8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x16790
movq -0xd8(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x16740
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0xcc9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x16620
jmp 0xce14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x167e0
jmp 0xce14
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x166f0
movq %rax, -0xe0(%rbp)
jmp 0xcaf6
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x166f0
movq %rax, -0xe8(%rbp)
jmp 0xcaad
movb $0x0, -0xe9(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x167b0
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movq -0x130(%rbp), %rax
movl %ecx, %esi
movl 0xc(%rax), %edx
callq 0xc8a0
jmp 0xcce5
leaq -0x50(%rbp), %rdi
callq 0x16640
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0xfc(%rbp)
movslq -0xfc(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x167b0
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0xcdd6
movq -0x130(%rbp), %rax
movq -0x128(%rbp), %rcx
movq (%rcx), %rcx
movl -0xfc(%rbp), %edx
imull 0xc(%rax), %edx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x178(%rbp)
movq (%rax), %rax
movq %rax, -0x180(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x16720
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdi
movq %rax, %rcx
movq -0x130(%rbp), %rax
movl (%rcx), %ecx
imull 0xc(%rax), %ecx
movl %ecx, %ecx
shlq $0x3, %rcx
addq %rcx, %rsi
movslq 0xc(%rax), %rdx
shlq $0x3, %rdx
callq 0xb320
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x166f0
movq %rax, -0x108(%rbp)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0xcd0d
movb $0x1, -0xe9(%rbp)
testb $0x1, -0xe9(%rbp)
jne 0xcdf2
movq -0x128(%rbp), %rdi
callq 0xc900
leaq -0x50(%rbp), %rdi
callq 0x167e0
leaq -0x38(%rbp), %rdi
callq 0x16800
movq -0x120(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x16800
movq -0x70(%rbp), %rdi
callq 0xb5d0
nopw %cs:(%rax,%rax)