// File: /workspace/github_cpp_makefile_star2_O3/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), %r13
testq %r13, %r13
jle 0x126ec
movq 0x20(%rbx), %rax
leal 0x1(%r13), %ecx
leaq -0x1(%r13), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %ecx
shlq $0x5, %rcx
leaq (%rcx,%rcx,2), %rcx
movdqa 0x3850e(%rip), %xmm1    # 0x4ab80
xorl %edx, %edx
movdqa 0x38514(%rip), %xmm2    # 0x4ab90
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x38514(%rip), %xmm4    # 0x4aba0
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %esi
notl %esi
testb $0x1, %sil
je 0x126c7
movq $0x0, 0x20(%rax,%rdx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x126df
movq $0x0, 0x50(%rax,%rdx)
paddq %xmm4, %xmm1
addq $0x60, %rdx
cmpq %rdx, %rcx
jne 0x1268c
cmpl $0x0, 0x3c(%rbx)
jle 0x12756
movq 0x8(%rbx), %rcx
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%rbx), %rdi
movsd (%rcx,%r14), %xmm0
movq 0x8(%rcx,%r14), %xmm1
movq 0x10(%rcx,%r14), %xmm2
callq 0x289c2
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 0x126fc
movl 0x38(%rbx), %r13d
cmpb $0x1, 0x69(%rbx)
jne 0x12851
testl %r13d, %r13d
jle 0x12795
movq 0x20(%rbx), %rax
movq 0x50(%rbx), %rcx
movl %r13d, %edx
addq $0x20, %rax
pxor %xmm0, %xmm0
xorl %esi, %esi
pxor %xmm1, %xmm1
addsd (%rax), %xmm1
addsd (%rcx,%rsi,8), %xmm0
incq %rsi
addq $0x30, %rax
cmpq %rsi, %rdx
jne 0x1277e
jmp 0x1279d
pxor %xmm1, %xmm1
pxor %xmm0, %xmm0
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq 0x4e7e8(%rip), %r14     # 0x60f98
leaq 0x384d0(%rip), %rsi     # 0x4ac87
movl $0x1e, %edx
movq %r14, %rdi
callq 0x73f0
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x7620
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7270
leaq 0x384a3(%rip), %rsi     # 0x4aca6
movl $0x1b, %edx
movq %r14, %rdi
callq 0x73f0
movq %r14, %rdi
movq 0x8(%rsp), %xmm0
callq 0x7620
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7270
callq 0x74f0
movl 0x38(%rbx), %r13d
testl %r13d, %r13d
js 0x129f5
movslq %r13d, %r15
leaq 0x40(%rbx), %r14
cmpq %r15, 0x48(%rbx)
je 0x12884
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x17b4c
cmpq %r15, 0x48(%rbx)
jne 0x12a33
movq (%r14), %r12
movl %r13d, %ebp
andl $0x7ffffffe, %ebp       # imm = 0x7FFFFFFE
cmpl $0x2, %r13d
jb 0x128bb
cmpl $0x3, %ebp
movl $0x2, %eax
cmovael %ebp, %eax
leaq -0x8(,%rax,8), %rdx
andq $-0x10, %rdx
addq $0x10, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x71e0
cmpl %r13d, %ebp
je 0x128de
shrl %r13d
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), %rcx
movq 0x48(%rbx), %rax
testq %rcx, %rcx
jle 0x12929
movq 0x20(%rbx), %rdx
movq 0x40(%rbx), %rsi
xorl %edi, %edi
testq %rax, %rax
movl $0x0, %r8d
cmovgq %rax, %r8
addq $0x20, %rdx
cmpq %rdi, %r8
je 0x129d6
movsd (%rdx), %xmm0
subsd -0x8(%rdx), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
addq $0x30, %rdx
cmpq %rdi, %rcx
jne 0x12906
movq %r14, 0x18(%rsp)
testq %rax, %rax
je 0x1295a
jle 0x12a14
movq (%r14), %rax
leaq 0x28(%rsp), %rdi
movq %rax, 0x8(%rdi)
leaq 0x18(%rsp), %rax
movq %rax, 0x18(%rdi)
leaq 0x7(%rsp), %rsi
callq 0x17bf4
jmp 0x1295e
pxor %xmm0, %xmm0
sqrtsd %xmm0, %xmm0
cmpb $0x0, 0x68(%rbx)
je 0x129c7
movq 0x4e629(%rip), %rbx     # 0x60f98
leaq 0x3834c(%rip), %rsi     # 0x4acc2
movl $0xf, %edx
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x73f0
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x7620
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7350
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7270
movsd 0x8(%rsp), %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38b97(%rip), %rdi     # 0x4b574
leaq 0x38bad(%rip), %rsi     # 0x4b591
leaq 0x3a109(%rip), %rcx     # 0x4caf4
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x7240
leaq 0x38830(%rip), %rdi     # 0x4b22c
leaq 0x388be(%rip), %rsi     # 0x4b2c1
leaq 0x39e56(%rip), %rcx     # 0x4c860
movl $0x4a, %edx
callq 0x7240
leaq 0x392d0(%rip), %rdi     # 0x4bceb
leaq 0x3930d(%rip), %rsi     # 0x4bd2f
leaq 0x3a152(%rip), %rcx     # 0x4cb7b
movl $0x19d, %edx            # imm = 0x19D
callq 0x7240
leaq 0x388f1(%rip), %rdi     # 0x4b32b
leaq 0x38919(%rip), %rsi     # 0x4b35a
leaq 0x39f0f(%rip), %rcx     # 0x4c957
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x7240