// File: /workspace/github_cpp_makefile_star2_O1/icemiliang[P]vot/src/vot/diagram.cc
// Function: vot::Diagram::compute_gradient()
double Diagram::compute_gradient() {
        // Reset cell mass
        for (int i = 0; i < mNumDiracs; i++) {
            mDiracs[i].reset_mass();
        }
        
        // Assign cellIndex to every measure and add mass to that cell
        int cellIndex = -1;
        for (int i = 0; i < mNumEmpiricals; i++) {
            cellIndex = mDiagram->cell_index(mEmpiricals[i].x(),
                                             mEmpiricals[i].y(), 
                                             mEmpiricals[i].z());
            mEmpiricals[i].set_cellIndex(cellIndex);
            mDiracs[cellIndex].add_mass(mEmpiricals[i].mass());
        }

        // Multiple-point check
        if (mFlagDebug) {
            double sumMass = 0;
            double sumH = 0;
            for (int i = 0; i < mNumDiracs; i++) {
                sumMass += mDiracs[i].mass();
                sumH += mHs[i];
            }
            std::cout << "[Debug] Total mass of Diracs: " << sumMass << std::endl;
            std::cout << "[Debug] Total h of Diracs: " << sumH << std::endl;
            getchar();
        }


        // Compute gradient and their norm
        double gradNorm = 0;
        mGradient = Eigen::VectorXd::Zero(mNumDiracs);
        for (int i = 0; i < mNumDiracs; i++) {
            mGradient(i) = mDiracs[i].mass() - mDiracs[i].dirac();
        }
        gradNorm = mGradient.norm();
        if (mFlagVerbose) {
            std::cout << "Gradient norm: " << gradNorm << std::endl;
        }

        return gradNorm;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movslq 0x38(%rdi), %rcx
testq %rcx, %rcx
jle 0x1278c
movq 0x20(%rbx), %rax
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movq $0x0, 0x20(%rax,%rdx)
addq $0x30, %rdx
cmpq %rdx, %rcx
jne 0x1277a
cmpl $0x0, 0x3c(%rbx)
jle 0x127f2
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%rbx), %rdi
movq 0x8(%rbx), %rax
movsd (%rax,%r14), %xmm0
movsd 0x8(%rax,%r14), %xmm1
movsd 0x10(%rax,%r14), %xmm2
callq 0x28280
movq 0x8(%rbx), %rcx
movl %eax, 0x20(%rcx,%r14)
cltq
movq 0x20(%rbx), %rdx
movsd 0x18(%rcx,%r14), %xmm0
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
addsd 0x20(%rdx,%rax), %xmm0
movsd %xmm0, 0x20(%rdx,%rax)
incq %r15
movslq 0x3c(%rbx), %rax
addq $0x28, %r14
cmpq %rax, %r15
jl 0x12798
cmpb $0x1, 0x69(%rbx)
jne 0x128ea
movslq 0x38(%rbx), %rax
testq %rax, %rax
jle 0x12832
movq 0x20(%rbx), %rcx
movq 0x50(%rbx), %rdx
addq $0x20, %rcx
xorpd %xmm0, %xmm0
xorl %esi, %esi
xorpd %xmm1, %xmm1
addsd (%rcx), %xmm1
addsd (%rdx,%rsi,8), %xmm0
incq %rsi
addq $0x30, %rcx
cmpq %rsi, %rax
jne 0x1281b
jmp 0x1283a
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq 0x4f74b(%rip), %r14     # 0x61f98
leaq 0x383e3(%rip), %rsi     # 0x4ac37
movl $0x1e, %edx
movq %r14, %rdi
callq 0x73e0
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x7610
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7340
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
leaq 0x383b6(%rip), %rsi     # 0x4ac56
movl $0x1b, %edx
movq %r14, %rdi
callq 0x73e0
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x7610
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7340
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
callq 0x74e0
movslq 0x38(%rbx), %r12
testq %r12, %r12
js 0x12a98
leaq 0x40(%rbx), %r14
cmpq %r12, 0x48(%rbx)
je 0x12914
movl $0x1, %ecx
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x17896
movq 0x48(%rbx), %r15
cmpq %r12, %r15
jne 0x12ab7
movq (%r14), %r12
movq %r15, %r13
shrq $0x3f, %r13
addq %r15, %r13
movq %r13, %rbp
andq $-0x2, %rbp
cmpq $0x2, %r15
jl 0x12962
cmpq $0x3, %rbp
movl $0x2, %eax
cmovgeq %rbp, %rax
leaq -0x8(,%rax,8), %rdx
andq $-0x10, %rdx
addq $0x10, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x71e0
cmpq %r15, %rbp
jge 0x12985
sarq %r13
shlq $0x4, %r13
addq %r13, %r12
shlq $0x3, %r15
subq %r13, %r15
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x71e0
movslq 0x38(%rbx), %rax
testq %rax, %rax
jle 0x129ca
movq 0x48(%rbx), %rcx
movq 0x20(%rbx), %rdx
movq 0x40(%rbx), %rsi
xorl %edi, %edi
testq %rcx, %rcx
cmovleq %rdi, %rcx
addq $0x20, %rdx
cmpq %rdi, %rcx
je 0x12a79
movsd (%rdx), %xmm0
subsd -0x8(%rdx), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
addq $0x30, %rdx
cmpq %rdi, %rax
jne 0x129a7
movq %r14, 0x18(%rsp)
cmpq $0x0, 0x48(%rbx)
je 0x129fd
jle 0x12ad6
movq (%r14), %rax
leaq 0x28(%rsp), %rdi
movq %rax, 0x8(%rdi)
leaq 0x18(%rsp), %rax
movq %rax, 0x18(%rdi)
leaq 0x7(%rsp), %rsi
callq 0x1793e
jmp 0x12a01
xorpd %xmm0, %xmm0
sqrtsd %xmm0, %xmm0
cmpb $0x0, 0x68(%rbx)
je 0x12a6a
movq 0x4f586(%rip), %rbx     # 0x61f98
leaq 0x38259(%rip), %rsi     # 0x4ac72
movl $0xf, %edx
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x73e0
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x7610
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7340
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7260
movsd 0x8(%rsp), %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38aa4(%rip), %rdi     # 0x4b524
leaq 0x38aba(%rip), %rsi     # 0x4b541
leaq 0x3a016(%rip), %rcx     # 0x4caa4
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x7240
leaq 0x3873d(%rip), %rdi     # 0x4b1dc
leaq 0x387cb(%rip), %rsi     # 0x4b271
leaq 0x39d63(%rip), %rcx     # 0x4c810
movl $0x4a, %edx
callq 0x7240
leaq 0x3881d(%rip), %rdi     # 0x4b2db
leaq 0x38845(%rip), %rsi     # 0x4b30a
leaq 0x39e3b(%rip), %rcx     # 0x4c907
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x7240
leaq 0x391be(%rip), %rdi     # 0x4bc9b
leaq 0x391fb(%rip), %rsi     # 0x4bcdf
leaq 0x3a040(%rip), %rcx     # 0x4cb2b
movl $0x19d, %edx            # imm = 0x19D
callq 0x7240
nop