// File: /workspace/github_cpp_makefile_star2_O2/hanhwi[P]SimPoint/analysiscode/Utilities.cpp
// Function: Utilities::loadAndProjectFVFile(FVParser&, Dataset const&, Dataset*)
void Utilities::loadAndProjectFVFile(FVParser &parser, 
                                     const Dataset &projection, 
                                     Dataset *result) {
    check(NULL != result, "Utilities::loadAndProjectFVFile() result is null");
    check(projection.numCols() == (*result).numCols(),
            "Utilities::loadAndProjectFVFile() dimensions are wrong");

    result->fill(0.0);

    list<FVParserToken> current_vector;
    double totalWeight = 0.0;
    vector<double> rowWeights(result->numRows());
    int numProjectedColumns = projection.numCols();
    int numProjectedRows = projection.numRows();
    int largestDimensionSeen = 0;

    while (parser.nextLine(&current_vector)) {
        int point = parser.currentLineNumber() - 1;
        if (point >= (int)result->numRows()) {
            check(false, "Utilities::loadAndProjectFVFile() more vectors than expected "
                    "(loading vector " + toString(point + 1) + " when expecting " 
                    + toString((int)result->numRows()) + ")");
        }

        // normalize the vector
        double sumVector = 0.0;
        list<FVParserToken>::iterator i;
        for (i = current_vector.begin(); i != current_vector.end(); i++) {
            sumVector += i->value;
        }

        rowWeights[point] = sumVector;
        totalWeight += sumVector;

        // multiply the row we just pulled from the parser by *each column*
        // of the projection matrix to obtain the row in the result.

        // fill the resulting vector with zeros
        (*result)[point].fill(0.0);

        // over all original dimensions (columns of the original vector, rows of
        // the projection matrix)
        for (i = current_vector.begin(); i != current_vector.end(); i++) { 
            int dim = i->dimension;
            double val = i->value / sumVector;
            if (dim > largestDimensionSeen) { largestDimensionSeen = dim; }
            if (dim < 1 || dim > numProjectedRows) {
                check(dim >= 1, "Utilities::loadAndProjectFVFile() dimension < 1");
                check(dim <= numProjectedRows,
                    "Utilities::loadAndProjectFVFile() expecting only " +
                    toString((int)numProjectedRows) +
                    " dimensions, but found dimension " +
                    toString((int)dim));
            }

            // project the row
            for (int projCol = 0; projCol < numProjectedColumns; projCol++) {
                // note that dimension is changed to be offset 0
                (*result)[point][projCol] += val * projection[dim - 1][projCol];
            }
        }
    }
    check(parser.currentLineNumber() == (int)result->numRows(),
            "Utilities::loadAndProjectFVFile() the number of vectors loaded "
            "disagrees with the number specified (expected " +
            toString((int)result->numRows()) + " but loaded " +
            toString((int)parser.currentLineNumber()) + ")");

    check(largestDimensionSeen == (int)numProjectedRows,
            "Utilities::loadAndProjectFVFile() the number of dimensions loaded "
            "disagrees with the number specified (expected " +
            toString((int)numProjectedRows) + " but loaded " +
            toString((int)largestDimensionSeen) + ")");

    // normalize the weights and put them in the dataset
    for (unsigned int row = 0; row < result->numRows(); row++) {
        result->setWeight(row, rowWeights[row] / totalWeight);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %rbx
movq %rsi, 0x60(%rsp)
movq %rdi, %r14
leaq 0x434a(%rip), %rsi      # 0x188bf
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x53a6
movq %r14, 0x50(%rsp)
xorl %edi, %edi
testq %rbx, %rbx
setne %dil
leaq 0x10(%rsp), %rsi
callq 0x5364
leaq 0x10(%rsp), %rdi
callq 0x45e8
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax), %r12
movq 0x8(%rax), %r14
movq (%rbx), %rax
movq (%rax), %r13
movq 0x8(%rax), %r15
leaq 0x432a(%rip), %rsi      # 0x188f0
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x53a6
subq %r13, %r15
shrq $0x3, %r15
subq %r12, %r14
shrq $0x3, %r14
xorl %edi, %edi
cmpl %r15d, %r14d
sete %dil
leaq 0x10(%rsp), %rsi
callq 0x5364
leaq 0x10(%rsp), %rdi
callq 0x45e8
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
movq %rbx, %rdi
callq 0x632c
leaq 0x110(%rsp), %rbp
movq %rbp, 0x8(%rbp)
movq %rbp, (%rbp)
andq $0x0, 0x10(%rbp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
pushq $0x18
popq %r14
cqto
idivq %r14
movl %eax, %esi
leaq 0xf8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5e38
movq 0x50(%rsp), %r12
movq 0x60(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq 0x8(%rcx), %r13
subq (%rcx), %r13
shrq $0x3, %r13
subq %rcx, %rax
cqto
idivq %r14
movq %rax, (%rsp)
xorl %ecx, %ecx
testl %r13d, %r13d
movl $0x0, %eax
movq %rax, 0x68(%rsp)
cmovlel %ecx, %r13d
movq %r12, %rdi
movq %rbp, %rsi
callq 0x73fe
movslq 0x8(%r12), %rsi
testb %al, %al
je 0x14976
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpl %eax, %esi
leaq 0x98(%rsp), %r15
jle 0x14793
movq %r15, %rdi
movq %rsi, %r12
callq 0x13a78
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
leaq 0x424d(%rip), %rsi      # 0x18927
movq %r15, %rdx
callq 0x11fc4
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
leaq 0x4075(%rip), %rdx      # 0x18766
callq 0x5490
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
movl %eax, %esi
callq 0x13a78
leaq 0x30(%rsp), %r15
movq %r15, %rdi
leaq 0x78(%rsp), %rsi
movq %r14, %rdx
callq 0x5429
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
leaq 0xaf1(%rip), %rdx       # 0x1522f
callq 0x5490
xorl %edi, %edi
movq %r14, %rsi
callq 0x5364
movq %r14, %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x45e8
leaq 0xd8(%rsp), %rdi
callq 0x45e8
leaq 0x78(%rsp), %rdi
callq 0x45e8
leaq 0xb8(%rsp), %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
callq 0x45e8
movq %r12, %rsi
leaq -0x1(%rsi), %rax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rcx
movq (%rcx), %rcx
cmpq %rbp, %rcx
je 0x147bf
movsd 0x8(%rsp), %xmm0
addsd 0x18(%rcx), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x147a4
movq 0xf8(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
movsd %xmm0, -0x8(%rcx,%rsi,8)
imulq $0x18, %rax, %r14
movq (%rbx), %rdi
addq %r14, %rdi
xorpd %xmm0, %xmm0
callq 0x587c
movsd 0x58(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movq %rbp, %r12
movq (%r12), %r12
cmpq %rbp, %r12
je 0x1496c
movslq 0x10(%r12), %rbp
movq 0x68(%rsp), %rax
cmpl %eax, %ebp
cmovgl %ebp, %eax
movq %rax, 0x68(%rsp)
movsd 0x18(%r12), %xmm0
movsd %xmm0, 0x70(%rsp)
testq %rbp, %rbp
jle 0x14837
cmpl (%rsp), %ebp
jle 0x14916
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x412f(%rip), %rsi      # 0x18975
leaq 0x30(%rsp), %rdx
callq 0x53a6
xorl %edi, %edi
testl %ebp, %ebp
setg %dil
movq %r15, %rsi
callq 0x5364
movq %r15, %rdi
callq 0x45e8
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rsi
callq 0x13a78
leaq 0x78(%rsp), %rdi
leaq 0x411d(%rip), %rsi      # 0x189a5
movq %r15, %rdx
callq 0x11fc4
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x3efe(%rip), %rdx      # 0x1879f
callq 0x5490
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
callq 0x13a78
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x5429
xorl %edi, %edi
cmpl (%rsp), %ebp
setle %dil
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x5364
movq %r15, %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x45e8
leaq 0x78(%rsp), %rdi
callq 0x45e8
leaq 0xb8(%rsp), %rdi
callq 0x45e8
movsd 0x70(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
imulq $0x18, %rbp, %rax
movq 0x60(%rsp), %rcx
addq (%rcx), %rax
xorl %ecx, %ecx
leaq 0x110(%rsp), %rbp
cmpq %rcx, %r13
je 0x147fb
movq -0x18(%rax), %rdx
movq (%rbx), %rsi
movq (%rsi,%r14), %rsi
movsd (%rdx,%rcx,8), %xmm0
mulsd 0x70(%rsp), %xmm0
addsd (%rsi,%rcx,8), %xmm0
movsd %xmm0, (%rsi,%rcx,8)
incq %rcx
jmp 0x1493e
movq 0x50(%rsp), %r12
jmp 0x14686
movq %rsi, %r15
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0x18
popq %r14
idivq %r14
movq %rax, %r12
leaq 0x98(%rsp), %rdi
movl %r12d, %esi
callq 0x13a78
leaq 0x4034(%rip), %rsi      # 0x189d7
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x11fc4
leaq 0x3e8c(%rip), %rdx      # 0x1884b
leaq 0x78(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x5490
movq 0x50(%rsp), %rax
movl 0x8(%rax), %esi
leaq 0xd8(%rsp), %rdi
callq 0x13a78
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x5429
leaq 0x82b(%rip), %rdx       # 0x1522f
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5490
xorl %edi, %edi
cmpl %r12d, %r15d
sete %dil
leaq 0x10(%rsp), %rsi
callq 0x5364
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x45e8
leaq 0xd8(%rsp), %rdi
callq 0x45e8
leaq 0x78(%rsp), %rdi
callq 0x45e8
leaq 0xb8(%rsp), %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
movq (%rsp), %rsi
callq 0x13a78
movq 0x68(%rsp), %r15
leaq 0x3fbd(%rip), %rsi      # 0x18a45
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x11fc4
leaq 0x3da7(%rip), %rdx      # 0x1884b
leaq 0x78(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x5490
leaq 0xd8(%rsp), %rdi
movl %r15d, %esi
callq 0x13a78
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x5429
leaq 0x74b(%rip), %rdx       # 0x1522f
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5490
xorl %edi, %edi
cmpl (%rsp), %r15d
sete %dil
leaq 0x10(%rsp), %rsi
callq 0x5364
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x45e8
leaq 0xd8(%rsp), %rdi
callq 0x45e8
leaq 0x78(%rsp), %rdi
callq 0x45e8
leaq 0xb8(%rsp), %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
callq 0x45e8
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %r14
movq 0xf8(%rsp), %rcx
movl %eax, %eax
xorl %edx, %edx
cmpq %rdx, %rax
je 0x14b82
movsd (%rcx,%rdx,8), %xmm0
divsd 0x58(%rsp), %xmm0
movq 0x18(%rbx), %rsi
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0x14b64
leaq 0xf8(%rsp), %rdi
callq 0x5f0a
leaq 0x110(%rsp), %rdi
callq 0x7628
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14c0b
jmp 0x14bff
jmp 0x14c04
jmp 0x14c31
jmp 0x14c40
jmp 0x14c5a
jmp 0x14c65
jmp 0x14c0b
jmp 0x14bff
jmp 0x14c04
jmp 0x14c31
jmp 0x14c40
jmp 0x14c5a
jmp 0x14c65
movq %rax, %rbx
jmp 0x14cd0
jmp 0x14be5
jmp 0x14bf7
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x45e8
jmp 0x14cdd
movq %rax, %rbx
jmp 0x14cdd
movq %rax, %rbx
jmp 0x14c18
movq %rax, %rbx
jmp 0x14c22
jmp 0x14c65
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x45e8
leaq 0xd8(%rsp), %rdi
callq 0x45e8
jmp 0x14c34
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x45e8
jmp 0x14c43
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
jmp 0x14cbe
movq %rax, %rbx
jmp 0x14c50
jmp 0x14c65
jmp 0x14c65
jmp 0x14c65
movq %rax, %rbx
jmp 0x14cc3
movq %rax, %rbx
jmp 0x14cac
movq %rax, %rbx
jmp 0x14c95
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x14cbe
movq %rax, %rbx
jmp 0x14cb6
movq %rax, %rbx
jmp 0x14ca2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x98(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x45e8
leaq 0x78(%rsp), %rdi
callq 0x45e8
leaq 0xb8(%rsp), %rdi
callq 0x45e8
leaq 0xf8(%rsp), %rdi
callq 0x5f0a
leaq 0x110(%rsp), %rdi
callq 0x7628
movq %rbx, %rdi
callq 0x4530