// File: /workspace/github_cpp_makefile_star2_O1/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 $0x268, %rsp            # imm = 0x268
movq %rdi, %r13
movq 0x9b8f(%rip), %r14      # 0xdfd8
leaq 0x5c89(%rip), %rsi      # 0xa0d9
movl $0x18, %edx
movq %r14, %rdi
callq 0x32a0
movq %r14, %rdi
callq 0x3170
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x80(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xb0(%r13), %rbx
movq 0xb0(%r13), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x3400
incl 0x4d8(%r13)
leaq 0xe0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x8, %edx
callq 0x33b0
leaq 0xe0(%rsp), %r14
leaq 0x70(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x32e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4504
incl 0x4dc(%r13)
jmp 0x44e2
movq 0x9ac5(%rip), %rsi      # 0xdfd0
leaq 0xe0(%rsp), %rdi
callq 0x3330
leaq 0x158(%rsp), %rdi
callq 0x30d0
movl 0x68(%r13), %ecx
testl %ecx, %ecx
jle 0x453e
movl 0x4dc(%r13), %eax
cltd
idivl %ecx
movl %eax, 0x4e8(%r13)
movl 0x4dc(%r13), %eax
movl 0x4e4(%r13), %ecx
movl 0x4e8(%r13), %edx
testl %ecx, %ecx
je 0x456b
addl %edx, %ecx
cmpl %ecx, %eax
jns 0x45be
movl $0x35, %edx
leaq 0x5bc5(%rip), %rsi      # 0xa12e
jmp 0x4584
subl %edx, %eax
jle 0x4578
movl %eax, 0x4e4(%r13)
jmp 0x45be
movl $0x3b, %edx
leaq 0x5b6e(%rip), %rsi      # 0xa0f2
movq 0x9a4d(%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 0x9a27(%rip), %rdi      # 0xdfd8
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x9a13(%rip), %rdi      # 0xdfd8
leaq 0x5b98(%rip), %rsi      # 0xa164
movl $0x5, %edx
callq 0x32a0
movl 0x4dc(%r13), %esi
movq 0x99f4(%rip), %rdi      # 0xdfd8
callq 0x33d0
movq %rax, %r14
leaq 0x5b77(%rip), %rsi      # 0xa16a
movl $0xe, %edx
movq %rax, %rdi
callq 0x32a0
movq %r14, %rdi
callq 0x3170
leaq 0x50(%rsp), %r14
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3400
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4646
incl 0x4d8(%r13)
jmp 0x460d
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x1, 0x20(%rbx,%rax)
je 0x469a
movq 0x997d(%rip), %r14      # 0xdfd8
leaq 0x5b17(%rip), %rsi      # 0xa179
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 0x994b(%rip), %rdi      # 0xdfd8
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x9937(%rip), %rdi      # 0xdfd8
leaq 0x59ef(%rip), %rsi      # 0xa097
movl $0x3, %edx
callq 0x32a0
movl 0x4d8(%r13), %esi
movq 0x9918(%rip), %rdi      # 0xdfd8
callq 0x33d0
movq %rax, %r14
leaq 0x5ac3(%rip), %rsi      # 0xa192
movl $0x9, %edx
movq %rax, %rdi
callq 0x32a0
movq %r14, %rdi
callq 0x3170
movslq 0x4dc(%r13), %rsi
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x69ea
xorps %xmm0, %xmm0
leaq 0xe0(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x50(%r13), %rax
movups 0x58(%r13), %xmm0
movq %rsp, %r14
movq (%r14), %rcx
movq %rcx, 0x50(%r13)
movq 0x8(%r14), %rcx
movq %rcx, 0x58(%r13)
movq 0x10(%r14), %rcx
movq %rcx, 0x60(%r13)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x6a9c
movq %r14, %rdi
callq 0x6a9c
movl 0x4dc(%r13), %eax
testl %eax, %eax
movq %rbx, 0x40(%rsp)
jle 0x4860
movl $0x20, %ebx
leaq 0x100(%rsp), %r15
xorl %r12d, %r12d
movq %rsp, %rbp
movl 0x4d8(%r13), %edx
leaq 0xe0(%rsp), %rdi
movl %r12d, %esi
callq 0x6acc
movq 0x50(%r13), %rax
leaq (%rax,%rbx), %r14
movl 0xe0(%rsp), %ecx
movl %ecx, -0x20(%rax,%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq -0x18(%rax,%rbx), %rcx
movups -0x10(%rax,%rbx), %xmm0
movq 0xe8(%rsp), %rdx
movq %rdx, -0x18(%rax,%rbx)
movq 0xf0(%rsp), %rdx
movq %rdx, -0x10(%rax,%rbx)
movq 0xf8(%rsp), %rdx
movq %rdx, -0x8(%rax,%rbx)
movq (%rsp), %rax
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq %rcx, (%rsp)
movups %xmm0, 0x8(%rsp)
movq %rax, 0xe8(%rsp)
movq %rdx, 0xf0(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rbp, %rdi
callq 0x745a
movq %r14, %rdi
movq %r15, %rsi
callq 0x3440
movq %r15, %rdi
callq 0x7536
leaq 0xe8(%rsp), %rdi
callq 0x745a
incq %r12
movslq 0x4dc(%r13), %rax
addq $0x58, %rbx
cmpq %rax, %r12
jl 0x4782
movq 0x40(%rsp), %rbx
movslq %eax, %rsi
leaq 0xc8(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x6ba8
movslq 0x4dc(%r13), %rsi
leaq 0xe0(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
movq %rsp, %rcx
callq 0x689e
movq %r13, %r12
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
movq $0x0, 0x48(%rsp)
leaq 0x70(%rsp), %r15
leaq 0x20(%rsp), %rbp
movq 0x40(%rsp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
callq 0x3400
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4b19
leaq 0xe0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x8, %edx
callq 0x33b0
movq 0x48(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0xa8(%rsp)
xorl %r14d, %r14d
leaq 0xe0(%rsp), %rdi
movq %r15, %rsi
callq 0x32e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4aee
leaq 0xb0(%rsp), %rdi
movq %r15, %rsi
movl $0x3a, %edx
callq 0x36fc
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq 0xb0(%rsp), %rbx
movq 0xb8(%rsp), %r15
cmpq %r15, %rbx
je 0x4ab9
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x78a0
movq %rbp, %rdi
leaq 0x5e07(%rip), %rsi      # 0xa7ca
callq 0x3410
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rsp, %rdi
callq 0x30c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x49f6
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3250
leaq (%r14,%r14,2), %r13
shlq $0x4, %r13
movq 0xc8(%rsp), %rdi
addq %r13, %rdi
movq %rsp, %rsi
callq 0x8e4a
movq 0x90(%rsp), %rcx
movl (%rcx,%r14,4), %edx
movl %edx, 0x20(%rsp)
movq 0xc8(%rsp), %rdi
leaq (%rdi,%r13), %rdx
addq $0x8, %rdx
cmpq %rdx, %rax
je 0x4a3f
movl 0x40(%rax), %eax
movl %eax, 0x20(%rsp)
jmp 0x4a5d
addq %r13, %rdi
movl (%rcx,%r14,4), %r13d
movq %rsp, %rsi
callq 0x6c44
movl %r13d, (%rax)
movq 0x90(%rsp), %rax
incl (%rax,%r14,4)
movq 0x50(%r12), %rax
imulq $0x58, %r14, %r13
movq 0x8(%rax,%r13), %rax
movq 0xa8(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4a91
movl 0x20(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x4a99
movq %rbp, %rdx
callq 0x91e6
movq 0x50(%r12), %rax
leaq (%rax,%r13), %rdi
addq $0x20, %rdi
movq %rbp, %rsi
callq 0x83ea
incl (%rax)
addq $0x20, %rbx
jmp 0x4994
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4ad4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3250
incq %r14
leaq 0xb0(%rsp), %rdi
callq 0x651c
leaq 0x70(%rsp), %r15
jmp 0x4936
incq 0x48(%rsp)
leaq 0xe0(%rsp), %rdi
movq 0x94ce(%rip), %rsi      # 0xdfd0
callq 0x3330
leaq 0x158(%rsp), %rdi
callq 0x30d0
jmp 0x48d0
movq 0x94b8(%rip), %rbx      # 0xdfd8
leaq 0x5675(%rip), %rsi      # 0xa19c
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 0x9486(%rip), %rdi      # 0xdfd8
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x4b7c
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0xc8(%rsp), %rdi
callq 0x6cc0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x4bab
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3250
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4bc7
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3250
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4cc9
jmp 0x4c2a
jmp 0x4c2a
jmp 0x4c2a
jmp 0x4c22
jmp 0x4c22
jmp 0x4c2a
movq %rax, %rdi
callq 0x72e5
jmp 0x4c2a
jmp 0x4c22
movq %rax, %rbx
movq 0x93cd(%rip), %rsi      # 0xdfd0
leaq 0xe0(%rsp), %rdi
callq 0x3330
leaq 0x158(%rsp), %rdi
callq 0x30d0
jmp 0x4cd6
movq %rax, %rbx
jmp 0x4cac
movq %rax, %rbx
jmp 0x4cd6
jmp 0x4c34
movq %rax, %rbx
jmp 0x4c8b
jmp 0x4c3b
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x4c63
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3250
jmp 0x4c63
jmp 0x4c60
jmp 0x4c60
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4c7e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3250
leaq 0xb0(%rsp), %rdi
callq 0x651c
movq 0x933e(%rip), %rsi      # 0xdfd0
leaq 0xe0(%rsp), %rdi
callq 0x3330
leaq 0x158(%rsp), %rdi
callq 0x30d0
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x4cc9
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0xc8(%rsp), %rdi
callq 0x6cc0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x4cf8
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3250
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4d14
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x33e0