// File: /workspace/github_cpp_makefile_star2_O3/mapequation[P]partition-validation/./partition-validation.h
// Function: Partitions::readPartitionsFile()
void Partitions::readPartitionsFile() {
    cout << "Reading partitions file " << flush;

    string line;
    string buf;

    // Count number of nodes and boot partitions
    getline(ifs, line);
    nNodes++; // First line corresponds to first node

    {
        istringstream read(line);
        while (read >> buf) nPartitions++;
    }

    if (crossValidateK > 0) {
        nValidationPartitions = nPartitions / crossValidateK;
    }

    if (nTrainingPartitions == 0) {
        if (nPartitions - nValidationPartitions > 0) {
            nTrainingPartitions = nPartitions - nValidationPartitions;
        } else {
            cout << "-- Not enough partitions for validation. Will not validate." << endl;
        }
    } else if (nPartitions - nValidationPartitions - nTrainingPartitions < 0) {
        cout << "-- Not enough partitions for training and validation." << endl;
    }

    cout << "with " << nPartitions << " partitions..." << flush;

    // Count remaining nodes
    while (getline(ifs, line)) {
        nNodes++;
    }

    if (ifs.bad()) {
        cout << "Error while reading file" << endl;
    }

    cout << "of " << nNodes << " nodes..." << flush;

    partitions = vector<Partition>(nPartitions);

    for (int i = 0; i < nPartitions; i++) {
        partitions[i] = Partition(i, nNodes);
    }

    // Restart from beginning of file
    vector<map<string, int> > partitionsAssignmentId(nPartitions);
    vector<int> partitionsAssignmentIds(nPartitions, 0);
    ifs.clear();
    ifs.seekg(0, ios::beg);

    // Read partitions data
    int nodeNr = 0;

    while (getline(ifs, line)) {
        istringstream read(line);
        int i = 0;

        while (read >> buf) {
            vector<string> assignments = tokenize(buf, ':');
            string assignmentKey;

            for (auto &assignment: assignments) {
                assignmentKey += assignment + ":";

                auto lookup = partitionsAssignmentId[i].find(assignmentKey);
                int assignmentId = partitionsAssignmentIds[i];

                if (lookup != end(partitionsAssignmentId[i])) {
                    assignmentId = lookup->second;
                } else {
                    partitionsAssignmentId[i][assignmentKey] = partitionsAssignmentIds[i];
                    partitionsAssignmentIds[i]++;
                }

                partitions[i].assignments[nodeNr].push_back(assignmentId);
                partitions[i].clusterSizes[assignmentId]++;
            }
            i++;
        }
        nodeNr++;
    }

    cout << "done!" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %rbp
movq 0x9b5b(%rip), %r14      # 0xdfd8
leaq 0x5cb5(%rip), %rsi      # 0xa139
movl $0x18, %edx
movq %r14, %rdi
callq 0x32a0
movq %r14, %rdi
callq 0x3170
leaq 0x68(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x88(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xb0(%rbp), %r12
movq 0xb0(%rbp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
leaq 0x58(%rsp), %rsi
movq %r12, %rdi
callq 0x3400
incl 0x4d8(%rbp)
leaq 0xf0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movl $0x8, %edx
callq 0x33b0
leaq 0xf0(%rsp), %r14
leaq 0x78(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x32e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4536
incl 0x4dc(%rbp)
jmp 0x4515
movq 0x9a93(%rip), %rsi      # 0xdfd0
leaq 0xf0(%rsp), %rdi
callq 0x3330
leaq 0x168(%rsp), %rdi
callq 0x30d0
movl 0x68(%rbp), %ecx
testl %ecx, %ecx
jle 0x456d
movl 0x4dc(%rbp), %eax
cltd
idivl %ecx
movl %eax, 0x4e8(%rbp)
movl 0x4dc(%rbp), %eax
movl 0x4e4(%rbp), %ecx
movl 0x4e8(%rbp), %edx
testl %ecx, %ecx
je 0x4597
addl %edx, %ecx
cmpl %ecx, %eax
jns 0x45e9
movl $0x35, %edx
leaq 0x5bf9(%rip), %rsi      # 0xa18e
jmp 0x45af
subl %edx, %eax
jle 0x45a3
movl %eax, 0x4e4(%rbp)
jmp 0x45e9
movl $0x3b, %edx
leaq 0x5ba3(%rip), %rsi      # 0xa152
movq 0x9a22(%rip), %r14      # 0xdfd8
movq %r14, %rdi
callq 0x32a0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x99fc(%rip), %rdi      # 0xdfd8
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x99e8(%rip), %rdi      # 0xdfd8
leaq 0x5bcd(%rip), %rsi      # 0xa1c4
movl $0x5, %edx
callq 0x32a0
movl 0x4dc(%rbp), %esi
movq 0x99ca(%rip), %rdi      # 0xdfd8
callq 0x33d0
movq %rax, %r14
leaq 0x5bad(%rip), %rsi      # 0xa1ca
movl $0xe, %edx
movq %rax, %rdi
callq 0x32a0
movq %r14, %rdi
callq 0x3170
leaq 0x58(%rsp), %r14
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x3400
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4670
incl 0x4d8(%rbp)
jmp 0x4637
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x1, 0x20(%r12,%rax)
je 0x46c6
movq 0x9951(%rip), %r14      # 0xdfd8
leaq 0x5b4b(%rip), %rsi      # 0xa1d9
movl $0x18, %edx
movq %r14, %rdi
callq 0x32a0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x991f(%rip), %rdi      # 0xdfd8
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x990b(%rip), %rdi      # 0xdfd8
leaq 0x5a23(%rip), %rsi      # 0xa0f7
movl $0x3, %edx
callq 0x32a0
movl 0x4d8(%rbp), %esi
movq 0x98ed(%rip), %rdi      # 0xdfd8
callq 0x33d0
movq %rax, %r14
leaq 0x5af8(%rip), %rsi      # 0xa1f2
movl $0x9, %edx
movq %rax, %rdi
callq 0x32a0
movq %r14, %rdi
callq 0x3170
movq %r12, 0x48(%rsp)
movslq 0x4dc(%rbp), %rsi
movq %rsp, %rdi
leaq 0x28(%rsp), %rdx
callq 0x6b6a
movq 0x60(%rbp), %rax
movq %rsp, %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x60(%rbp)
movups 0x50(%rbp), %xmm1
movups %xmm0, 0x50(%rbp)
leaq 0xf0(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x6c1a
movq %r14, %rdi
callq 0x6c1a
movslq 0x4dc(%rbp), %rsi
testq %rsi, %rsi
jle 0x4835
leaq 0xf8(%rsp), %r14
movl $0x20, %ebx
leaq 0x110(%rsp), %r15
xorl %r12d, %r12d
movl 0x4d8(%rbp), %edx
leaq 0xf0(%rsp), %rdi
movl %r12d, %esi
callq 0x6c4a
movq 0x50(%rbp), %rax
leaq (%rax,%rbx), %r13
movl 0xf0(%rsp), %ecx
movl %ecx, -0x20(%rax,%rbx)
movq -0x8(%rax,%rbx), %rcx
movups 0xf8(%rsp), %xmm0
movups -0x18(%rax,%rbx), %xmm1
movups %xmm0, -0x18(%rax,%rbx)
movq 0x108(%rsp), %rdx
movq %rdx, -0x8(%rax,%rbx)
movaps %xmm1, (%rsp)
movq %rcx, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movq %rsp, %rdi
callq 0x75b4
movq %r13, %rdi
movq %r15, %rsi
callq 0x3440
movq %r15, %rdi
callq 0x762e
movq %r14, %rdi
callq 0x75b4
incq %r12
movslq 0x4dc(%rbp), %rsi
addq $0x58, %rbx
cmpq %rsi, %r12
jl 0x4796
movq %rbp, 0x20(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xf0(%rsp), %rdx
callq 0x6d0a
movq 0x20(%rsp), %rax
movslq 0x4dc(%rax), %rsi
leaq 0xf0(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x98(%rsp), %rdi
movq %rsp, %rcx
callq 0x6920
movq 0x48(%rsp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x33c0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3310
leaq 0x38(%rsp), %rbp
movq $0x0, 0x50(%rsp)
leaq 0x78(%rsp), %r14
leaq 0xc0(%rsp), %r15
leaq 0x28(%rsp), %r12
movq 0x48(%rsp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0x3400
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4b0f
leaq 0xf0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movl $0x8, %edx
callq 0x33b0
movq 0x50(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0xb0(%rsp)
xorl %ebx, %ebx
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
callq 0x32e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4ae4
movq %r15, %rdi
movq %r14, %rsi
movl $0x3a, %edx
callq 0x36fc
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq 0xc0(%rsp), %r14
movq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
cmpq %rax, %r14
je 0x4ac7
movq %rbp, 0x28(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x799e
movq %r12, %rdi
leaq 0x5e7f(%rip), %rsi      # 0xa82a
callq 0x3410
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %rsp, %rdi
callq 0x30c0
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x49d9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3250
leaq (%rbx,%rbx,2), %r13
shlq $0x4, %r13
movq 0xd8(%rsp), %rdi
addq %r13, %rdi
movq %rsp, %rsi
callq 0x8f12
movq %rbp, %r15
movq 0x98(%rsp), %rcx
movl (%rcx,%rbx,4), %ebp
movl %ebp, 0x28(%rsp)
movq 0xd8(%rsp), %rdi
leaq (%rdi,%r13), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x4a24
movl 0x40(%rax), %eax
movl %eax, 0x28(%rsp)
jmp 0x4a3c
addq %r13, %rdi
movq %rsp, %rsi
callq 0x6da2
movl %ebp, (%rax)
movq 0x98(%rsp), %rax
incl (%rax,%rbx,4)
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
imulq $0x58, %rbx, %r13
movq 0x8(%rax,%r13), %rcx
movq 0xb0(%rsp), %rdx
leaq (%rcx,%rdx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4a74
movl 0x28(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x4a85
movq %r12, %rdx
callq 0x92ae
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
leaq (%rax,%r13), %rdi
addq $0x20, %rdi
movq %r12, %rsi
callq 0x8518
incl (%rax)
addq $0x20, %r14
cmpq 0xb8(%rsp), %r14
movq %r15, %rbp
jne 0x498a
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4ac7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3250
incq %rbx
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x64fa
leaq 0x78(%rsp), %r14
jmp 0x4920
incq 0x50(%rsp)
leaq 0xf0(%rsp), %rdi
movq 0x94d8(%rip), %rsi      # 0xdfd0
callq 0x3330
leaq 0x168(%rsp), %rdi
callq 0x30d0
jmp 0x48bb
movq 0x94c2(%rip), %rbx      # 0xdfd8
leaq 0x56df(%rip), %rsi      # 0xa1fc
movl $0x5, %edx
movq %rbx, %rdi
callq 0x32a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x9490(%rip), %rdi      # 0xdfd8
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x4b72
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0xd8(%rsp), %rdi
callq 0x6e1e
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x4ba1
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3250
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x4bbd
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3250
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4cb7
jmp 0x4c1d
jmp 0x4c1d
jmp 0x4c1d
jmp 0x4c18
jmp 0x4c18
jmp 0x4c1d
movq %rax, %rdi
callq 0x7449
jmp 0x4c1d
jmp 0x4c18
movq %rax, %rbx
movq 0x93d7(%rip), %rsi      # 0xdfd0
leaq 0xf0(%rsp), %rdi
callq 0x3330
leaq 0x168(%rsp), %rdi
callq 0x30d0
jmp 0x4cc4
movq %rax, %rbx
jmp 0x4c9a
movq %rax, %rbx
jmp 0x4cc4
jmp 0x4c27
movq %rax, %rbx
jmp 0x4c79
jmp 0x4c2e
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4c51
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3250
jmp 0x4c51
jmp 0x4c4e
jmp 0x4c4e
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4c6c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3250
leaq 0xc0(%rsp), %rdi
callq 0x64fa
movq 0x9350(%rip), %rsi      # 0xdfd0
leaq 0xf0(%rsp), %rdi
callq 0x3330
leaq 0x168(%rsp), %rdi
callq 0x30d0
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x4cb7
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0xd8(%rsp), %rdi
callq 0x6e1e
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x4ce6
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3250
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x4d02
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x33e0