// File: /workspace/github_c_makefile_star2_O2/mesbahamin[P]star-sim/src/barnes_hut.c
// Function: quad_tree_node_insert_star
void quad_tree_node_insert_star(struct QuadTreeNode *node, struct Star *star)
{
    if (node && cell_contains_star(node->cell, star))
    {
        if (quad_tree_node_is_leaf(node))
        {
            if (cell_is_empty(node->cell))
            {
                node->cell->star = star;
            }
            else
            {
                quad_tree_node_subdivide(node);

                quad_tree_node_insert_star(node->ne, node->cell->star);
                quad_tree_node_insert_star(node->nw, node->cell->star);
                quad_tree_node_insert_star(node->sw, node->cell->star);
                quad_tree_node_insert_star(node->se, node->cell->star);

                quad_tree_node_insert_star(node->ne, star);
                quad_tree_node_insert_star(node->nw, star);
                quad_tree_node_insert_star(node->sw, star);
                quad_tree_node_insert_star(node->se, star);

                node->cell->star = NULL;
            }
        }
        else
        {
            node->cell->mass_total += star->mass;
            node->cell->stars_sum_x += star->x * star->mass;
            node->cell->stars_sum_y += star->y * star->mass;

            float x_avg = node->cell->stars_sum_x / node->cell->mass_total;
            float y_avg = node->cell->stars_sum_y / node->cell->mass_total;

            node->cell->mass_center_x = x_avg;
            node->cell->mass_center_y = y_avg;

            quad_tree_node_insert_star(node->ne, star);
            quad_tree_node_insert_star(node->nw, star);
            quad_tree_node_insert_star(node->sw, star);
            quad_tree_node_insert_star(node->se, star);
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
testq %rbx, %rbx
je 0x2c6d
movq (%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2942
testb %al, %al
je 0x2c6d
movq %rbx, %rdi
callq 0x2a37
testb %al, %al
jne 0x2bdc
movss 0x8(%r14), %xmm0
movss 0x10(%r15), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x10(%r15)
movsd 0x10(%r14), %xmm2
movsd 0x1c(%r15), %xmm3
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
mulps %xmm2, %xmm0
addps %xmm3, %xmm0
movlps %xmm0, 0x1c(%r15)
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
divps %xmm1, %xmm0
movlps %xmm0, 0x14(%r15)
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq 0x20(%rbx), %rbx
jmp 0x2b48
cmpq $0x0, 0x28(%r15)
je 0x2c69
movq %rbx, %rdi
callq 0x2a5f
movq (%rbx), %rax
movq 0x8(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2b3d
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2b3d
movq (%rbx), %rax
movq 0x18(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2b3d
movq (%rbx), %rax
movq 0x20(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2b3d
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x2b3d
movq (%rbx), %rax
andq $0x0, 0x28(%rax)
jmp 0x2c6d
movq %r14, 0x28(%r15)
popq %rbx
popq %r14
popq %r15
retq