// File: pgrouchy[P]NoiseWorld/mathNet.cpp
// Function: Population::loadPop(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Population::loadPop(string myFilename) {
    Genome *myGenome;
    Tree *myTree;
    FILE *myFile;
    int myInt, myInt2, i;
    double myDouble, myDouble2;

    this->pop_size = 0;

    do {
        myFile = fopen(myFilename.c_str(), "r");
        if (myFile == NULL)
            sleep(0.1);
    } while (myFile == NULL);

    // Population details
    fscanf(myFile, "Timestep: %d\n", &myInt);
    this->gen = myInt;
    fscanf(myFile, "Isl: %d\n", &myInt);
    this->my_isl_id = myInt;
    fscanf(myFile, "MaxID: %d\n", &myInt);
    this->max_tree_id = myInt;
    fscanf(myFile, "beta: %lf\n", &myDouble);
    this->beta = myDouble;

    // Agent and agent genome details
    while (fscanf(myFile, "Pop: %d\n", &myInt) == 1) {
        myGenome = new Genome();
        myGenome->pop_id = myInt;
        fscanf(myFile, "Alive: %d\n", &myInt);
        if (myInt == 1) {
            myGenome->is_alive = true;
        } else {
            myGenome->is_alive = false;
        }
        fscanf(myFile, "NumTrees: %d\n", &myInt);
        myGenome->num_trees = myInt;
        fscanf(myFile, "Fit: %d\n", &myInt);
        myGenome->fitness = myInt;
        fscanf(myFile, "Age: %lf\n", &myDouble);
        myGenome->age = myDouble;
        fscanf(myFile, "Grid: %d,%d\n", &myInt, &myInt2);
        myGenome->mainGridLocation[0] = myInt;
        myGenome->mainGridLocation[1] = myInt2;

        myGenome->initialVal = new double[myGenome->num_trees];

        fscanf(myFile, "InitVals: %lf", &myDouble);
        myGenome->initialVal[0] = myDouble;
        for (i = 1; i < myGenome->num_trees; i++) {
            fscanf(myFile, ",%lf", &myDouble);
            myGenome->initialVal[i] = myDouble;
        }
        fscanf(myFile,"\n");

        myGenome->myData = new double[myGenome->num_trees];

        fscanf(myFile, "Pos: %lf,%lf\n", &myDouble, &myDouble2);
        myGenome->myPosition[0] = myDouble;
        myGenome->myPosition[1] = myDouble2;
        myGenome->mainGridLocation[0] = (int)((myGenome->myPosition[0] + ((double)ISLAND_SIZE / 2.0)) / NN_BLOCK_SIZE);
        myGenome->mainGridLocation[1] = (int)((myGenome->myPosition[1] + ((double)ISLAND_SIZE / 2.0)) / NN_BLOCK_SIZE);

        // Tree details
        for (i = 0; i < myGenome->num_trees; i++) {
            fscanf(myFile, "Tree: %d,%d\n", &myInt, &myInt2);
            myTree = new Tree();
            myTree->loadTree(myFile, myInt, myInt2);
            myTree->recountNodes(0);
            myGenome->trees.push_back(myTree);
            myGenome->tree_id_lookup.push_back(new TreeID(myTree->tree_id));
        }

        fscanf(myFile,"\n");

        this->genomes.push_back(myGenome);
        this->pop_size++;
    }

    fclose(myFile);
}

// Assembly:
subq $0x98, %rsp
movq %rsi, 0x28(%rsp)
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x1c(%rax)
movq 0x28(%rsp), %rdi
callq 0x30e0
movq %rax, %rdi
leaq 0x8acb(%rip), %rsi      # 0x1535f
callq 0x3310
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0xc8ad
xorl %edi, %edi
callq 0x31c0
jmp 0xc8af
cmpq $0x0, 0x70(%rsp)
je 0xc880
movq 0x70(%rsp), %rdi
leaq 0x8a9e(%rip), %rsi      # 0x15361
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movq 0x30(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, 0x20(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8a88(%rip), %rsi      # 0x1536f
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movq 0x30(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, 0x24(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8a6d(%rip), %rsi      # 0x15378
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movq 0x30(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, 0x28(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8a54(%rip), %rsi      # 0x15383
leaq 0x58(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movq 0x30(%rsp), %rax
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x48(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8a37(%rip), %rsi      # 0x1538e
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
cmpl $0x1, %eax
jne 0xcddc
movl $0x90, %edi
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
callq 0x12d80
jmp 0xc988
movq 0x20(%rsp), %rax
movq %rax, 0x80(%rsp)
movl 0x6c(%rsp), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x30(%rax)
movq 0x70(%rsp), %rdi
leaq 0x89e7(%rip), %rsi      # 0x15397
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
cmpl $0x1, 0x6c(%rsp)
jne 0xc9f3
movq 0x80(%rsp), %rax
movb $0x1, 0x58(%rax)
jmp 0xc9ff
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl $0x90, %esi
callq 0x32b0
jmp 0xcdee
movq 0x80(%rsp), %rax
movb $0x0, 0x58(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8997(%rip), %rsi      # 0x153a2
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movl 0x6c(%rsp), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x34(%rax)
movq 0x70(%rsp), %rdi
leaq 0x897e(%rip), %rsi      # 0x153b0
leaq 0x6c(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movl 0x6c(%rsp), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8960(%rip), %rsi      # 0x153b9
leaq 0x58(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movsd 0x58(%rsp), %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x40(%rax)
movq 0x70(%rsp), %rdi
leaq 0x893f(%rip), %rsi      # 0x153c3
leaq 0x6c(%rsp), %rdx
leaq 0x68(%rsp), %rcx
movb $0x0, %al
callq 0x3470
movl 0x6c(%rsp), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x48(%rax)
movl 0x68(%rsp), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x4c(%rax)
movq 0x80(%rsp), %rax
movslq 0x34(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x80(%rax)
movq 0x70(%rsp), %rdi
leaq 0x88d2(%rip), %rsi      # 0x153d0
leaq 0x58(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movsd 0x58(%rsp), %xmm0
movq 0x80(%rsp), %rax
movq 0x80(%rax), %rax
movsd %xmm0, (%rax)
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
movq 0x80(%rsp), %rcx
cmpl 0x34(%rcx), %eax
jge 0xcb80
movq 0x70(%rsp), %rdi
leaq 0x8896(%rip), %rsi      # 0x153de
leaq 0x58(%rsp), %rdx
movb $0x0, %al
callq 0x3470
movsd 0x58(%rsp), %xmm0
movq 0x80(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x64(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0xcb2b
movq 0x70(%rsp), %rdi
leaq 0x87f5(%rip), %rsi      # 0x15381
movb $0x0, %al
callq 0x3470
movq 0x80(%rsp), %rax
movslq 0x34(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x78(%rax)
movq 0x70(%rsp), %rdi
leaq 0x8808(%rip), %rsi      # 0x153e3
leaq 0x58(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movb $0x0, %al
callq 0x3470
movsd 0x58(%rsp), %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x68(%rax)
movsd 0x50(%rsp), %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x70(%rax)
movq 0x80(%rsp), %rax
movsd 0x8436(%rip), %xmm0     # 0x15058
addsd 0x68(%rax), %xmm0
movsd 0x8609(%rip), %xmm1     # 0x15238
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x48(%rax)
movq 0x80(%rsp), %rax
movsd 0x8406(%rip), %xmm0     # 0x15058
addsd 0x70(%rax), %xmm0
movsd 0x85d9(%rip), %xmm1     # 0x15238
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x4c(%rax)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
movq 0x80(%rsp), %rcx
cmpl 0x34(%rcx), %eax
jge 0xcda4
movq 0x70(%rsp), %rdi
leaq 0x8756(%rip), %rsi      # 0x153f1
xorl %eax, %eax
leaq 0x6c(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x3470
movl $0x38, %edi
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x12db0
jmp 0xccc8
movq 0x18(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x6c(%rsp), %edx
movl 0x68(%rsp), %ecx
callq 0xce00
movq 0x78(%rsp), %rdi
xorl %esi, %esi
callq 0xd020
movq 0x80(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x9250
movq 0x80(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edi
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x92d0
jmp 0xcd3d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x9290
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0xcc7a
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl $0x38, %esi
callq 0x32b0
jmp 0xcdee
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl $0x8, %esi
callq 0x32b0
jmp 0xcdee
movq 0x70(%rsp), %rdi
leaq 0x85d1(%rip), %rsi      # 0x15381
movb $0x0, %al
callq 0x3470
movq 0x30(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x80d0
movq 0x30(%rsp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
jmp 0xc94b
movq 0x70(%rsp), %rdi
callq 0x3290
addq $0x98, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x3430
nopl (%rax,%rax)