// File: xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::UpdateWeightsAndBiasFC()
void ConstructLayer::UpdateWeightsAndBiasFC()
{
    //cout<<__func__<<" started..."<<endl;
    // after finishing one batch, update weights and bias, for FC layer
    size_t M = __imageDeltaFull.size(); // batch size
    if( M != __wGradient.size() ) {
        std::cout<<__func__<<" Error: update FC weights, batch size not match."<<std::endl;
        std::cout<<"           weight gradient batch size: "<<__wGradient.size()<<std::endl;
        std::cout<<"           delta image batch size: "<<__imageDeltaFull.size()<<std::endl;
        exit(0);
    }
    if( __wGradient[0].OutputImageFromKernel.size() != 1 || __bGradient[0].OutputImageFromKernel.size()!=1) 
    {
        std::cout<<__func__<<" Error: update FC weiths, more than 1 w gradient matrix found."
            <<std::endl;
        exit(0);
    }

    // gradient descent
    if(__weightMatrix.size() != __neuronDim.k) {
        std::cout<<__func__<<" Error: update FC layer weights, more than 1 weight matrix found."<<std::endl;
        std::cout<<"__weightMatrix size: "<<__weightMatrix.size()<<std::endl;
        std::cout<<"neuron dimension: "<<__neuronDim<<std::endl;
        exit(0);
    }
    Matrix dw((__weightMatrix[0]).Dimension(), 0); 
    for(size_t i=0;i<M;i++){ // sum x (batches)
        dw  = dw + __wGradient[i].OutputImageFromKernel[0];
        //cout<<__wGradient[i].OutputImageFromKernel[0]<<endl;
        //cout<<i<<" before sum"<<endl;
        //getchar();
    }

    if(__weights_optimizer == WeightsOptimizer::SGD)
    {
        // standard SGD 
        dw = dw * double(__learningRate/(double)M); // over batch 
    }
    else if(__weights_optimizer == WeightsOptimizer::Adam)
    {
        // Adam optimizer
        dw = dw * (1./ (double)M );

        //Matrix tmp = dw * __learningRate;
        //cout<<"Before adam: "<<endl<<dw<<endl;
        dw = AdamOptimizer(dw, 0);
        //cout<<"after adam: "<<endl<<dw<<endl;
        //getchar();
    }
    else
    {
        std::cout<<__func__<<" Error: unsupported optimization method."<<std::endl;
        exit(0);
    }
    //cout<<"learning rate: "<<double(__learningRate/(double)M)<<endl;

    // Get filter Matrix for masking Regularization item
    assert(__activeFlag.size() == 1);
    auto convertFilterToMatrix = [&](Filter2D & F) -> Matrix
    {
        auto dim = F.Dimension();
        Matrix M(dim, 0);
        for(size_t i=0;i<dim.first;i++)
        {
            for(size_t j=0;j<dim.second;j++)
            {
                if(F[i][j]) M[i][j] = 1;
            }
        }
        return M;
    };
    Matrix currentLayerFilter = convertFilterToMatrix(__activeFlag[0]);
    //cout<<currentLayerFilter.Dimension()<<endl;
    Matrix prevLayerFilter(1, dw.Dimension().second, 1);
    //cout<<"before: "<<endl<<prevLayerFilter<<endl;

    if(__prevLayer->GetType() == LayerType::input) // only fc layer need this, other layers won't affect
    {
        auto & prevLayerFilters = __prevLayer->GetActiveFlag();
        assert(prevLayerFilters.size() == 1);
        assert(prevLayerFilters[0].Dimension().first == (size_t)__prevLayer->GetNumberOfNeurons());

        Matrix filter = convertFilterToMatrix(prevLayerFilters[0]);
        prevLayerFilter = filter.Transpose();
        //cout<<"after: "<<endl<<prevLayerFilter<<endl;
    }

    // following is two flag matrix (dim[n,1] x dim[1, m], with bool elements) product
    // all the elements of the product will be either 0 or 1
    // this product can be used to mask out disabled elements in weight matrix regularization
    Matrix F = currentLayerFilter * prevLayerFilter;
    //cout<<F<<endl;
    //cout<<prevLayerFilter<<endl;
    //cout<<dw<<endl;
    //getchar();

    assert(F.Dimension() == (__weightMatrix[0]).Dimension());
    // Regularization
    //double f_regularization = 0.;
    if(__regularizationMethod == Regularization::L2) 
    {
        // obsolete
        //f_regularization = 1 - __learningRate * __regularizationParameter / M;
        //(__weightMatrix[0]) = (__weightMatrix[0]) * f_regularization - dw;

        // new
        // hadamard multiply with F to maks out all inactive elements
        Matrix regularization_M = (__weightMatrix[0]^F) *(__learningRate * __regularizationParameter/((double)M)); 
        Matrix total_correction_M = regularization_M + dw; // dw already include learning rate during generation
        __weightMatrix[0] = __weightMatrix[0] - total_correction_M;
    } 
    else if(__regularizationMethod == Regularization::L1) 
    {
        Matrix _t = (__weightMatrix[0]); // make a copy of weight matrix
        _t(&SGN); // get the sign for each element in weight matrix
        _t = _t^F; // hadamard operation to mask out all inactive elements
        _t = _t * (__learningRate*__regularizationParameter/(double)M); // L1 regularization part
        (__weightMatrix[0]) = (__weightMatrix[0]) -  _t; // apply L1 regularization to weight matrix
        (__weightMatrix[0]) = (__weightMatrix[0]) - dw; // apply gradient decsent part
    } 
    else 
    {
        std::cout<<__func__<<" Error: update FC weights, unsupported regularization."<<std::endl;
        exit(0);
    }

    //cout<<"reached hrere..."<<endl;

    if(!__use_batch_normalization || 
            (__type != LayerType::cnn && __type != LayerType::fullyConnected && __type != LayerType::output))
    {
        // for cnn, fc, output layers, if BN is not used, one need to update b paramter.
        // if BN is used, b parameter is discarded (combined into \beta parameter)
        // bias
        Matrix db(__biasVector[0].Dimension());
        for(size_t i=0;i<M;i++){
            db = db + __bGradient[i].OutputImageFromKernel[0];
        }
        db = db / (double)M;
        db = db * __learningRate;
        __biasVector[0] = __biasVector[0] - db;
    }
    //cout<<__func__<<" ended.."<<endl;
}

// Assembly:
subq $0x3a8, %rsp            # imm = 0x3A8
movq %rdi, 0x3a0(%rsp)
movq 0x3a0(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
addq $0x1e0, %rdi            # imm = 0x1E0
callq 0x1ff40
movq 0xb8(%rsp), %rdi
movq %rax, 0x398(%rsp)
movq 0x398(%rsp), %rax
movq %rax, 0xc0(%rsp)
addq $0x90, %rdi
callq 0x1ff40
movq %rax, %rcx
movq 0xc0(%rsp), %rax
cmpq %rcx, %rax
je 0x162af
movq 0x54df6(%rip), %rdi     # 0x6afd8
leaq 0x3d3a3(%rip), %rsi     # 0x5358c
callq 0x4230
movq %rax, %rdi
leaq 0x3d3ab(%rip), %rsi     # 0x535a3
callq 0x4230
movq %rax, %rdi
movq 0x54da9(%rip), %rsi     # 0x6afb0
callq 0x4260
movq 0x54dc5(%rip), %rdi     # 0x6afd8
leaq 0x3d3ba(%rip), %rsi     # 0x535d4
callq 0x4230
movq 0xb8(%rsp), %rdi
movq %rax, 0xa8(%rsp)
addq $0x90, %rdi
callq 0x1ff40
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
callq 0x4080
movq %rax, %rdi
movq 0x54d5b(%rip), %rsi     # 0x6afb0
callq 0x4260
movq 0x54d77(%rip), %rdi     # 0x6afd8
leaq 0x3d394(%rip), %rsi     # 0x535fc
callq 0x4230
movq 0xb8(%rsp), %rdi
movq %rax, 0xb0(%rsp)
addq $0x1e0, %rdi            # imm = 0x1E0
callq 0x1ff40
movq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x4080
movq %rax, %rdi
movq 0x54d0d(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
movq 0xb8(%rsp), %rdi
addq $0x90, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fd40
movq %rax, %rdi
callq 0x1f9c0
cmpq $0x1, %rax
jne 0x162fb
movq 0xb8(%rsp), %rdi
addq $0xa8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fd40
movq %rax, %rdi
callq 0x1f9c0
cmpq $0x1, %rax
je 0x16333
movq 0x54cd6(%rip), %rdi     # 0x6afd8
leaq 0x3d283(%rip), %rsi     # 0x5358c
callq 0x4230
movq %rax, %rdi
leaq 0x3d308(%rip), %rsi     # 0x53620
callq 0x4230
movq %rax, %rdi
movq 0x54c89(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
callq 0x1f9c0
movq 0xb8(%rsp), %rcx
cmpq 0x3a8(%rcx), %rax
je 0x16415
movq 0x54c78(%rip), %rdi     # 0x6afd8
leaq 0x3d225(%rip), %rsi     # 0x5358c
callq 0x4230
movq %rax, %rdi
leaq 0x3d2e9(%rip), %rsi     # 0x5365f
callq 0x4230
movq %rax, %rdi
movq 0x54c2b(%rip), %rsi     # 0x6afb0
callq 0x4260
movq 0x54c47(%rip), %rdi     # 0x6afd8
leaq 0x3d309(%rip), %rsi     # 0x536a1
callq 0x4230
movq 0xb8(%rsp), %rdi
movq %rax, 0xa0(%rsp)
addq $0x60, %rdi
callq 0x1f9c0
movq 0xa0(%rsp), %rdi
movq %rax, %rsi
callq 0x4080
movq %rax, %rdi
movq 0x54be0(%rip), %rsi     # 0x6afb0
callq 0x4260
movq 0x54bfc(%rip), %rdi     # 0x6afd8
leaq 0x3d2d4(%rip), %rsi     # 0x536b7
callq 0x4230
movq 0xb8(%rsp), %rsi
movq %rax, %rdi
addq $0x398, %rsi            # imm = 0x398
callq 0x3ad60
movq %rax, %rdi
movq 0x54ba7(%rip), %rsi     # 0x6afb0
callq 0x4260
xorl %edi, %edi
callq 0x4290
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rax, 0x370(%rsp)
movq %rdx, 0x378(%rsp)
movq 0x370(%rsp), %rsi
movq 0x378(%rsp), %rdx
leaq 0x380(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0x3b680
movq $0x0, 0x368(%rsp)
movq 0x368(%rsp), %rax
cmpq 0x398(%rsp), %rax
jae 0x16542
movq 0xb8(%rsp), %rdi
addq $0x90, %rdi
movq 0x368(%rsp), %rsi
callq 0x1fd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdx
leaq 0x350(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0x3bf90
jmp 0x164c6
leaq 0x380(%rsp), %rdi
leaq 0x350(%rsp), %rsi
callq 0x1fa20
jmp 0x164dd
leaq 0x350(%rsp), %rdi
callq 0x3bb80
movq 0x368(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x368(%rsp)
jmp 0x1646e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x173c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x350(%rsp), %rdi
callq 0x3bb80
jmp 0x173c8
movq 0xb8(%rsp), %rax
cmpl $0x0, 0x440(%rax)
jne 0x165fc
movq 0xb8(%rsp), %rax
movsd 0xc0(%rax), %xmm0
movaps 0x3baf2(%rip), %xmm2    # 0x52060
movq 0x398(%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3baed(%rip), %xmm2    # 0x52070
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x328(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0x3cfd0
jmp 0x165ad
leaq 0x380(%rsp), %rdi
leaq 0x328(%rsp), %rsi
callq 0x1fa20
jmp 0x165c4
leaq 0x328(%rsp), %rdi
callq 0x3bb80
jmp 0x16773
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x3bb80
jmp 0x173c8
movq 0xb8(%rsp), %rax
cmpl $0x1, 0x440(%rax)
jne 0x16719
movaps 0x3ba48(%rip), %xmm0    # 0x52060
movq 0x398(%rsp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x3ba43(%rip), %xmm0    # 0x52070
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x3b9c4(%rip), %xmm0    # 0x52008
divsd %xmm1, %xmm0
leaq 0x310(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0x3cfd0
jmp 0x1665f
leaq 0x380(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x1fa20
jmp 0x16676
leaq 0x310(%rsp), %rdi
callq 0x3bb80
movq 0xb8(%rsp), %rsi
leaq 0x2f8(%rsp), %rdi
leaq 0x380(%rsp), %rdx
xorl %ecx, %ecx
callq 0x19340
jmp 0x166a4
leaq 0x380(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x1fa20
jmp 0x166bb
leaq 0x2f8(%rsp), %rdi
callq 0x3bb80
jmp 0x16771
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x3bb80
jmp 0x173c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x2f8(%rsp), %rdi
callq 0x3bb80
jmp 0x173c8
movq 0x548b8(%rip), %rdi     # 0x6afd8
leaq 0x3ce65(%rip), %rsi     # 0x5358c
callq 0x4230
movq %rax, 0x98(%rsp)
jmp 0x16736
movq 0x98(%rsp), %rdi
leaq 0x3cf85(%rip), %rsi     # 0x536ca
callq 0x4230
movq %rax, 0x90(%rsp)
jmp 0x16754
movq 0x90(%rsp), %rdi
movq 0x5484d(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1676a
xorl %edi, %edi
callq 0x4290
jmp 0x16773
movq 0xb8(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x1ffd0
cmpq $0x1, %rax
jne 0x1678f
jmp 0x167ae
leaq 0x3c658(%rip), %rdi     # 0x52dee
leaq 0x3ba35(%rip), %rsi     # 0x521d2
movl $0xd4a, %edx            # imm = 0xD4A
leaq 0x3cf4a(%rip), %rcx     # 0x536f3
callq 0x4170
movq 0xb8(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
xorl %eax, %eax
movl %eax, %esi
callq 0x1ff80
movq %rax, %rdx
leaq 0x2d8(%rsp), %rdi
leaq 0x2f7(%rsp), %rsi
callq 0x19df0
jmp 0x167e0
leaq 0x380(%rsp), %rdi
callq 0x3bae0
movq %rdx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
jmp 0x167ff
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
movq %rcx, 0x2b0(%rsp)
movq %rax, 0x2b8(%rsp)
movq 0x2b8(%rsp), %rdx
leaq 0x2c0(%rsp), %rdi
movl $0x1, %esi
movsd 0x3b7cc(%rip), %xmm0    # 0x52008
callq 0x3b590
jmp 0x16843
movq 0xb8(%rsp), %rax
movq 0x3f0(%rax), %rdi
movq (%rdi), %rax
movq 0x250(%rax), %rax
callq *%rax
movl %eax, 0x7c(%rsp)
jmp 0x16864
movl 0x7c(%rsp), %eax
cmpl $0x3, %eax
jne 0x16a63
movq 0xb8(%rsp), %rax
movq 0x3f0(%rax), %rdi
movq (%rdi), %rax
movq 0x268(%rax), %rax
callq *%rax
movq %rax, 0x70(%rsp)
jmp 0x16893
movq 0x70(%rsp), %rax
movq %rax, 0x2a8(%rsp)
movq 0x2a8(%rsp), %rdi
callq 0x1ffd0
cmpq $0x1, %rax
jne 0x168b5
jmp 0x16906
leaq 0x3ce65(%rip), %rdi     # 0x53721
leaq 0x3b90f(%rip), %rsi     # 0x521d2
movl $0xd60, %edx            # imm = 0xD60
leaq 0x3ce24(%rip), %rcx     # 0x536f3
callq 0x4170
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x173bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x173ae
movq 0x2a8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1ff80
movq %rax, %rdi
callq 0x200b0
movq %rdx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
jmp 0x1692b
movq 0xb8(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rdx
movq %rdx, 0x298(%rsp)
movq %rcx, 0x2a0(%rsp)
movq 0x298(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movq 0x3f0(%rax), %rdi
movq (%rdi), %rax
movq 0x278(%rax), %rax
callq *%rax
movl %eax, 0x5c(%rsp)
jmp 0x16973
movq 0x50(%rsp), %rax
movl 0x5c(%rsp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x16986
jmp 0x169a5
leaq 0x3cdb1(%rip), %rdi     # 0x5373e
leaq 0x3b83e(%rip), %rsi     # 0x521d2
movl $0xd61, %edx            # imm = 0xD61
leaq 0x3cd53(%rip), %rcx     # 0x536f3
callq 0x4170
movq 0x2a8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1ff80
movq %rax, %rdx
leaq 0x280(%rsp), %rdi
leaq 0x2f7(%rsp), %rsi
callq 0x19df0
jmp 0x169d0
leaq 0x268(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x3e9f0
jmp 0x169e7
leaq 0x2c0(%rsp), %rdi
leaq 0x268(%rsp), %rsi
callq 0x1fa20
jmp 0x169fe
leaq 0x268(%rsp), %rdi
callq 0x3bb80
leaq 0x280(%rsp), %rdi
callq 0x3bb80
jmp 0x16a63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x16a51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x3bb80
leaq 0x280(%rsp), %rdi
callq 0x3bb80
jmp 0x173ae
leaq 0x250(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
leaq 0x2c0(%rsp), %rdx
callq 0x3bbb0
jmp 0x16a82
leaq 0x250(%rsp), %rdi
callq 0x3bae0
movq %rdx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
jmp 0x16a9b
movq 0xb8(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x240(%rsp)
movq %rax, 0x248(%rsp)
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rdx, 0x30(%rsp)
movq %rax, 0x38(%rsp)
jmp 0x16ade
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, 0x230(%rsp)
movq %rax, 0x238(%rsp)
movq 0x240(%rsp), %rdi
movq 0x248(%rsp), %rsi
movq 0x230(%rsp), %rdx
movq 0x238(%rsp), %rcx
callq 0x3b180
movb %al, 0x2f(%rsp)
jmp 0x16b23
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x16b2d
jmp 0x16b2f
jmp 0x16b67
leaq 0x3cc5b(%rip), %rdi     # 0x53791
leaq 0x3b695(%rip), %rsi     # 0x521d2
movl $0xd71, %edx            # imm = 0xD71
leaq 0x3cbaa(%rip), %rcx     # 0x536f3
callq 0x4170
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x173a1
movq 0xb8(%rsp), %rax
cmpl $0x0, 0xc8(%rax)
jne 0x16d4d
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rsi
leaq 0x200(%rsp), %rdi
leaq 0x250(%rsp), %rdx
callq 0x3c680
jmp 0x16bab
movq 0xb8(%rsp), %rax
movsd 0xc0(%rax), %xmm0
movsd 0xd0(%rax), %xmm1
mulsd %xmm1, %xmm0
movaps 0x3b492(%rip), %xmm2    # 0x52060
movq 0x398(%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3b48d(%rip), %xmm2    # 0x52070
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x218(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x3cfd0
jmp 0x16c0d
leaq 0x200(%rsp), %rdi
callq 0x3bb80
leaq 0x1e8(%rsp), %rdi
leaq 0x218(%rsp), %rsi
leaq 0x380(%rsp), %rdx
callq 0x3bf90
jmp 0x16c39
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rsi
leaq 0x1d0(%rsp), %rdi
leaq 0x1e8(%rsp), %rdx
callq 0x3c480
jmp 0x16c68
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x1fa20
jmp 0x16c8f
leaq 0x1d0(%rsp), %rdi
callq 0x3bb80
leaq 0x1e8(%rsp), %rdi
callq 0x3bb80
leaq 0x218(%rsp), %rdi
callq 0x3bb80
jmp 0x17043
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x3bb80
jmp 0x173a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x16d3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x16d2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x3bb80
leaq 0x1e8(%rsp), %rdi
callq 0x3bb80
leaq 0x218(%rsp), %rdi
callq 0x3bb80
jmp 0x173a1
movq 0xb8(%rsp), %rax
cmpl $0x1, 0xc8(%rax)
jne 0x16ff5
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x3b810
jmp 0x16d89
leaq 0x3200(%rip), %rsi      # 0x19f90
leaq 0x1b8(%rsp), %rdi
callq 0x3dc20
jmp 0x16d9f
leaq 0x1a0(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
leaq 0x250(%rsp), %rdx
callq 0x3c680
jmp 0x16dbe
leaq 0x1b8(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x1fa20
jmp 0x16dd5
leaq 0x1a0(%rsp), %rdi
callq 0x3bb80
movq 0xb8(%rsp), %rax
movsd 0xc0(%rax), %xmm0
movsd 0xd0(%rax), %xmm1
mulsd %xmm1, %xmm0
movaps 0x3b25b(%rip), %xmm2    # 0x52060
movq 0x398(%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3b256(%rip), %xmm2    # 0x52070
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x188(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x3cfd0
jmp 0x16e44
leaq 0x1b8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x1fa20
jmp 0x16e5b
leaq 0x188(%rsp), %rdi
callq 0x3bb80
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rsi
leaq 0x170(%rsp), %rdi
leaq 0x1b8(%rsp), %rdx
callq 0x3c480
jmp 0x16e97
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
leaq 0x170(%rsp), %rsi
callq 0x1fa20
jmp 0x16ebe
leaq 0x170(%rsp), %rdi
callq 0x3bb80
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rsi
leaq 0x158(%rsp), %rdi
leaq 0x380(%rsp), %rdx
callq 0x3c480
jmp 0x16efa
movq 0xb8(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
leaq 0x158(%rsp), %rsi
callq 0x1fa20
jmp 0x16f21
leaq 0x158(%rsp), %rdi
callq 0x3bb80
leaq 0x1b8(%rsp), %rdi
callq 0x3bb80
jmp 0x17041
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x16fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x3bb80
jmp 0x16fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x3bb80
jmp 0x16fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x3bb80
jmp 0x16fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x3bb80
leaq 0x1b8(%rsp), %rdi
callq 0x3bb80
jmp 0x173a1
movq 0x53fdc(%rip), %rdi     # 0x6afd8
leaq 0x3c589(%rip), %rsi     # 0x5358c
callq 0x4230
movq %rax, 0x20(%rsp)
jmp 0x1700f
movq 0x20(%rsp), %rdi
leaq 0x3c7a7(%rip), %rsi     # 0x537c2
callq 0x4230
movq %rax, 0x18(%rsp)
jmp 0x17027
movq 0x18(%rsp), %rdi
movq 0x53f7d(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x1703a
xorl %edi, %edi
callq 0x4290
jmp 0x17043
movq 0xb8(%rsp), %rax
testb $0x1, 0x210(%rax)
je 0x1708a
movq 0xb8(%rsp), %rax
cmpl $0x1, 0xc(%rax)
je 0x17365
movq 0xb8(%rsp), %rax
cmpl $0x0, 0xc(%rax)
je 0x17365
movq 0xb8(%rsp), %rax
cmpl $0x4, 0xc(%rax)
je 0x17365
movq 0xb8(%rsp), %rdi
addq $0x78, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
callq 0x3bae0
movq %rdx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x170b3
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x130(%rsp)
movq %rax, 0x138(%rsp)
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
leaq 0x140(%rsp), %rdi
callq 0x3b4a0
jmp 0x170ec
movq $0x0, 0x128(%rsp)
movq 0x128(%rsp), %rax
cmpq 0x398(%rsp), %rax
jae 0x171cc
movq 0xb8(%rsp), %rdi
addq $0xa8, %rdi
movq 0x128(%rsp), %rsi
callq 0x1fd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdx
leaq 0x110(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x3bf90
jmp 0x17150
leaq 0x140(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x1fa20
jmp 0x17167
leaq 0x110(%rsp), %rdi
callq 0x3bb80
movq 0x128(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x128(%rsp)
jmp 0x170f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x17356
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x3bb80
jmp 0x17356
movaps 0x3ae8d(%rip), %xmm1    # 0x52060
movq 0x398(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3ae88(%rip), %xmm1    # 0x52070
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
leaq 0xf8(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x3d140
jmp 0x1720e
leaq 0x140(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x1fa20
jmp 0x17225
leaq 0xf8(%rsp), %rdi
callq 0x3bb80
movq 0xb8(%rsp), %rax
movsd 0xc0(%rax), %xmm0
leaq 0xe0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x3cfd0
jmp 0x17259
leaq 0x140(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x1fa20
jmp 0x17270
leaq 0xe0(%rsp), %rdi
callq 0x3bb80
movq 0xb8(%rsp), %rdi
addq $0x78, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x140(%rsp), %rdx
callq 0x3c480
jmp 0x172ac
movq 0xb8(%rsp), %rdi
addq $0x78, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f9e0
movq %rax, %rdi
leaq 0xc8(%rsp), %rsi
callq 0x1fa20
jmp 0x172d3
leaq 0xc8(%rsp), %rdi
callq 0x3bb80
leaq 0x140(%rsp), %rdi
callq 0x3bb80
jmp 0x17365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x3bb80
jmp 0x17356
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x3bb80
jmp 0x17356
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x3bb80
leaq 0x140(%rsp), %rdi
callq 0x3bb80
jmp 0x173a1
leaq 0x250(%rsp), %rdi
callq 0x3bb80
leaq 0x2c0(%rsp), %rdi
callq 0x3bb80
leaq 0x2d8(%rsp), %rdi
callq 0x3bb80
leaq 0x380(%rsp), %rdi
callq 0x3bb80
addq $0x3a8, %rsp            # imm = 0x3A8
retq
leaq 0x250(%rsp), %rdi
callq 0x3bb80
leaq 0x2c0(%rsp), %rdi
callq 0x3bb80
leaq 0x2d8(%rsp), %rdi
callq 0x3bb80
leaq 0x380(%rsp), %rdi
callq 0x3bb80
movq 0x348(%rsp), %rdi
callq 0x43f0
nopw %cs:(%rax,%rax)