// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
movl $0x0, 0x1c(%rdi)
movq (%rsi), %rdi
leaq 0x40c8(%rip), %rsi      # 0xb47f
callq 0x2220
testq %rax, %rax
jne 0x73df
leaq 0x40b7(%rip), %r15      # 0xb47f
xorl %edi, %edi
callq 0x2130
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x2220
testq %rax, %rax
je 0x73c8
movq %rax, %r14
leaq 0x4098(%rip), %rsi      # 0xb481
leaq 0x4(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movl (%rbx), %eax
movq 0x18(%rsp), %r12
movl %eax, 0x20(%r12)
leaq 0x4081(%rip), %rsi      # 0xb48f
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movl (%rbx), %eax
movl %eax, 0x24(%r12)
leaq 0x406f(%rip), %rsi      # 0xb498
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movl (%rbx), %eax
movl %eax, 0x28(%r12)
leaq 0x405f(%rip), %rsi      # 0xb4a3
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
movsd (%r15), %xmm0
movsd %xmm0, 0x48(%r12)
leaq 0x4045(%rip), %rsi      # 0xb4ae
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
cmpl $0x1, %eax
jne 0x77bd
leaq 0x4(%rsp), %r15
leaq 0x8(%rsp), %rbx
leaq 0x14(%rsp), %r13
movq $-0x1, %rbp
movl $0x90, %edi
callq 0x21e0
movq %rax, %r12
movq %rax, 0x8(%rax)
movq %rax, (%rax)
xorl %eax, %eax
movq %rax, 0x10(%r12)
leaq 0x18(%r12), %rcx
movq %rcx, 0x20(%r12)
movq %rcx, 0x28(%rsp)
movq %rcx, 0x18(%r12)
movq %rax, 0x28(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0x30(%r12)
movq %r14, %rdi
leaq 0x3fdb(%rip), %rsi      # 0xb4b7
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
cmpl $0x1, 0x4(%rsp)
sete 0x58(%r12)
movq %r14, %rdi
leaq 0x3fc7(%rip), %rsi      # 0xb4c2
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
movl 0x4(%rsp), %eax
movl %eax, 0x34(%r12)
movq %r14, %rdi
leaq 0x3fb8(%rip), %rsi      # 0xb4d0
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
movl 0x4(%rsp), %eax
movl %eax, 0x38(%r12)
movq %r14, %rdi
leaq 0x3fa4(%rip), %rsi      # 0xb4d9
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%r12)
movq %r14, %rdi
leaq 0x3f8d(%rip), %rsi      # 0xb4e3
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2330
movl 0x4(%rsp), %eax
movl %eax, 0x48(%r12)
movl 0x14(%rsp), %eax
movl %eax, 0x4c(%r12)
movslq 0x34(%r12), %rax
leaq (,%rax,8), %rdi
testq %rax, %rax
cmovsq %rbp, %rdi
callq 0x2030
movq %rax, 0x80(%r12)
movq %r14, %rdi
leaq 0x3f50(%rip), %rsi      # 0xb4f0
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movsd 0x8(%rsp), %xmm0
movq 0x80(%r12), %rax
movsd %xmm0, (%rax)
cmpl $0x2, 0x34(%r12)
leaq 0x3f35(%rip), %rbp      # 0xb4fe
jl 0x7602
movl $0x1, %ebx
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x2330
movsd 0x8(%rsp), %xmm0
movq 0x80(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movslq 0x34(%r12), %rax
cmpq %rax, %rbx
jl 0x75d0
movq %r14, %rdi
leaq 0x3e95(%rip), %rsi      # 0xb4a1
xorl %eax, %eax
callq 0x2330
movslq 0x34(%r12), %rax
leaq (,%rax,8), %rdi
testq %rax, %rax
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x78(%r12)
movq %r14, %rdi
leaq 0x3ec1(%rip), %rsi      # 0xb503
leaq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %eax, %eax
callq 0x2330
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x68(%r12)
movsd 0x30(%rsp), %xmm1
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
addpd 0x3a4e(%rip), %xmm0     # 0xb0c0
mulpd 0x3a56(%rip), %xmm0     # 0xb0d0
cvttpd2dq %xmm0, %xmm0
movsd %xmm1, 0x70(%r12)
movlpd %xmm0, 0x48(%r12)
cmpl $0x0, 0x34(%r12)
movq %r12, %rbp
jle 0x775e
xorl %r12d, %r12d
movq %rbp, 0x20(%rsp)
movq %r14, %rdi
leaq 0x3e64(%rip), %rsi      # 0xb511
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2330
movl $0x38, %edi
callq 0x21e0
movq %rax, %rbx
movl 0x4(%rsp), %edx
movl 0x14(%rsp), %ecx
movq %rax, %rdi
movq %r14, %rsi
callq 0x77d4
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7904
movl $0x18, %edi
callq 0x21e0
movq %rbx, 0x10(%rax)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2060
incq 0x10(%rbp)
movl $0x8, %edi
callq 0x21e0
movq %r14, %rbp
movq %r13, %r14
movq %r15, %r13
movq %rax, %r15
movq 0x10(%rbx), %rax
movq 0x28(%rsp), %rbx
movq (%rax), %rax
movq %rax, (%r15)
movl $0x18, %edi
callq 0x21e0
movq %r15, 0x10(%rax)
movq %r13, %r15
movq %r14, %r13
movq %rbp, %r14
movq 0x20(%rsp), %rbp
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2060
incq 0x28(%rbp)
incl %r12d
cmpl 0x34(%rbp), %r12d
jl 0x76a3
movq %r14, %rdi
leaq 0x3d39(%rip), %rsi      # 0xb4a1
xorl %eax, %eax
callq 0x2330
movl $0x18, %edi
callq 0x21e0
movq %rbp, 0x10(%rax)
movq %rax, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x2060
incq 0x10(%rbx)
incl 0x1c(%rbx)
movq %r14, %rdi
leaq 0x3d10(%rip), %rsi      # 0xb4ae
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
cmpl $0x1, %eax
leaq 0x8(%rsp), %rbx
movq $-0x1, %rbp
je 0x7495
movq %r14, %rdi
callq 0x21d0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq