// File: /workspace/github_cpp_makefile_star2_O2/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, 0x20(%rsp)
andl $0x0, 0x1c(%rdi)
leaq 0x44e2(%rip), %r15      # 0xa41f
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x2210
testq %rax, %rax
jne 0x5f56
xorl %edi, %edi
callq 0x2130
jmp 0x5f3d
movq %rax, %r14
leaq 0x44c1(%rip), %rsi      # 0xa421
leaq 0x8(%rsp), %r12
movq %rax, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
movl (%r12), %eax
movq 0x20(%rsp), %rbx
movl %eax, 0x20(%rbx)
leaq 0x44aa(%rip), %rsi      # 0xa42f
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
movl (%r12), %eax
movl %eax, 0x24(%rbx)
leaq 0x4498(%rip), %rsi      # 0xa438
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
movl (%r12), %eax
movl %eax, 0x28(%rbx)
leaq 0x4488(%rip), %rsi      # 0xa443
leaq 0x10(%rsp), %r13
movq %r14, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2340
movsd (%r13), %xmm0
movsd %xmm0, 0x48(%rbx)
leaq 0xc(%rsp), %rbp
leaq 0x28(%rsp), %rbx
movq %r14, %rdi
leaq 0x4462(%rip), %rsi      # 0xa44e
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
cmpl $0x1, %eax
jne 0x62c3
movl $0x90, %edi
callq 0x21f0
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x18(%rax), %rcx
movq %rcx, 0x20(%rax)
movq %rcx, 0x18(%rax)
andq $0x0, 0x28(%rax)
movq %rax, (%rsp)
movl 0x8(%rsp), %ecx
movl %ecx, 0x30(%rax)
movq %r14, %rdi
leaq 0x441c(%rip), %rsi      # 0xa457
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
cmpl $0x1, 0x8(%rsp)
movq (%rsp), %rax
sete 0x58(%rax)
movq %r14, %rdi
leaq 0x4406(%rip), %rsi      # 0xa462
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
movl 0x8(%rsp), %eax
movq (%rsp), %rcx
movl %eax, 0x34(%rcx)
movq %r14, %rdi
leaq 0x43f5(%rip), %rsi      # 0xa470
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
movl 0x8(%rsp), %eax
movq (%rsp), %rcx
movl %eax, 0x38(%rcx)
movq %r14, %rdi
leaq 0x43df(%rip), %rsi      # 0xa479
movq %r13, %rdx
xorl %eax, %eax
callq 0x2340
movsd 0x10(%rsp), %xmm0
movq (%rsp), %rax
movsd %xmm0, 0x40(%rax)
movq %r14, %rdi
leaq 0x43c6(%rip), %rsi      # 0xa483
movq %r12, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2340
movl 0x8(%rsp), %eax
movq (%rsp), %r15
movl %eax, 0x48(%r15)
movl 0xc(%rsp), %eax
movl %eax, 0x4c(%r15)
movslq 0x34(%r15), %rax
leaq (,%rax,8), %rdi
testq %rax, %rax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x80(%r15)
movq %r14, %rdi
leaq 0x4386(%rip), %rsi      # 0xa490
movq %r13, %rdx
xorl %eax, %eax
callq 0x2340
movsd 0x10(%rsp), %xmm0
movq (%rsp), %rax
movq 0x80(%rax), %rcx
movsd %xmm0, (%rcx)
pushq $0x1
popq %r15
leaq 0x436a(%rip), %rbp      # 0xa49e
movslq 0x34(%rax), %rax
cmpq %rax, %r15
jge 0x6169
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2340
movsd 0x10(%rsp), %xmm0
movq (%rsp), %rax
movq 0x80(%rax), %rcx
movsd %xmm0, (%rcx,%r15,8)
incq %r15
jmp 0x6134
movq %r13, %rbp
movq %r12, %r13
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0x42c5(%rip), %rsi      # 0xa441
xorl %eax, %eax
callq 0x2340
movq (%rsp), %r15
movslq 0x34(%r15), %rax
leaq (,%rax,8), %rdi
testq %rax, %rax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x78(%r15)
movq %r14, %rdi
leaq 0x42f3(%rip), %rsi      # 0xa4a3
movq %rbp, %rdx
leaq 0xc(%rsp), %rbp
leaq 0x30(%rsp), %rcx
xorl %eax, %eax
callq 0x2340
movsd 0x10(%rsp), %xmm0
movq (%rsp), %rax
movsd %xmm0, 0x68(%rax)
movsd 0x30(%rsp), %xmm1
movsd %xmm1, 0x70(%rax)
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
addpd 0x3ef6(%rip), %xmm0     # 0xa0e0
mulpd 0x3efe(%rip), %xmm0     # 0xa0f0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x48(%rax)
cmpl 0x34(%rax), %r12d
jge 0x6291
movq %r14, %rdi
leaq 0x42a2(%rip), %rsi      # 0xa4b1
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2340
pushq $0x38
popq %rdi
callq 0x21f0
movq %rax, 0x18(%rsp)
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movq %rax, %rdi
movq %r14, %rsi
callq 0x62da
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x640a
movq (%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4bac
movq (%rsp), %r15
addq $0x18, %r15
pushq $0x8
popq %rdi
callq 0x21f0
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movq %rax, 0x28(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4bb8
incl %r12d
movq (%rsp), %rax
jmp 0x61fb
movq %r14, %rdi
leaq 0x41a6(%rip), %rsi      # 0xa441
xorl %eax, %eax
callq 0x2340
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rsp, %rsi
callq 0x4764
incl 0x1c(%r15)
movq %r13, %r12
leaq 0x10(%rsp), %r13
jmp 0x5fe2
movq %r14, %rdi
callq 0x21e0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq