// File: /workspace/github_cpp_makefile_star2_O1/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 0x40d6(%rip), %rsi      # 0xb46f
callq 0x2220
testq %rax, %rax
jne 0x73c1
leaq 0x40c5(%rip), %r15      # 0xb46f
xorl %edi, %edi
callq 0x2130
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x2220
testq %rax, %rax
je 0x73aa
movq %rax, %r14
leaq 0x40a6(%rip), %rsi      # 0xb471
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 0x408f(%rip), %rsi      # 0xb47f
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movl (%rbx), %eax
movl %eax, 0x24(%r12)
leaq 0x407d(%rip), %rsi      # 0xb488
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movl (%rbx), %eax
movl %eax, 0x28(%r12)
leaq 0x406d(%rip), %rsi      # 0xb493
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
movsd (%r15), %xmm0
movsd %xmm0, 0x48(%r12)
leaq 0x4053(%rip), %rsi      # 0xb49e
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
cmpl $0x1, %eax
jne 0x779f
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 0x3fe9(%rip), %rsi      # 0xb4a7
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
cmpl $0x1, 0x4(%rsp)
sete 0x58(%r12)
movq %r14, %rdi
leaq 0x3fd5(%rip), %rsi      # 0xb4b2
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
movl 0x4(%rsp), %eax
movl %eax, 0x34(%r12)
movq %r14, %rdi
leaq 0x3fc6(%rip), %rsi      # 0xb4c0
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
movl 0x4(%rsp), %eax
movl %eax, 0x38(%r12)
movq %r14, %rdi
leaq 0x3fb2(%rip), %rsi      # 0xb4c9
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%r12)
movq %r14, %rdi
leaq 0x3f9b(%rip), %rsi      # 0xb4d3
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 0x3f5e(%rip), %rsi      # 0xb4e0
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2330
movsd 0x8(%rsp), %xmm0
movq 0x80(%r12), %rax
movsd %xmm0, (%rax)
cmpl $0x2, 0x34(%r12)
leaq 0x3f43(%rip), %rbp      # 0xb4ee
jl 0x75e4
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 0x75b2
movq %r14, %rdi
leaq 0x3ea3(%rip), %rsi      # 0xb491
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 0x3ecf(%rip), %rsi      # 0xb4f3
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 0x3a4c(%rip), %xmm0     # 0xb0a0
mulpd 0x3a54(%rip), %xmm0     # 0xb0b0
cvttpd2dq %xmm0, %xmm0
movsd %xmm1, 0x70(%r12)
movlpd %xmm0, 0x48(%r12)
cmpl $0x0, 0x34(%r12)
movq %r12, %rbp
jle 0x7740
xorl %r12d, %r12d
movq %rbp, 0x20(%rsp)
movq %r14, %rdi
leaq 0x3e72(%rip), %rsi      # 0xb501
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 0x77b6
movq %rbx, %rdi
xorl %esi, %esi
callq 0x78e6
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 0x7685
movq %r14, %rdi
leaq 0x3d47(%rip), %rsi      # 0xb491
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 0x3d1e(%rip), %rsi      # 0xb49e
movq %r15, %rdx
xorl %eax, %eax
callq 0x2330
cmpl $0x1, %eax
leaq 0x8(%rsp), %rbx
movq $-0x1, %rbp
je 0x7477
movq %r14, %rdi
callq 0x21d0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq