// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
testq %rbx, %rbx
je 0x2f2d
movq (%rbx), %rax
movss 0x10(%r14), %xmm0
movss (%rax), %xmm1
movss 0x8(%rax), %xmm2
movaps %xmm1, %xmm3
addss %xmm2, %xmm3
ucomiss %xmm0, %xmm3
jb 0x2f2d
subss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jb 0x2f2d
movss 0x14(%r14), %xmm1
movss 0x4(%rax), %xmm2
movss 0xc(%rax), %xmm3
movaps %xmm2, %xmm4
addss %xmm3, %xmm4
ucomiss %xmm1, %xmm4
jb 0x2f2d
subss %xmm3, %xmm2
ucomiss %xmm2, %xmm1
jb 0x2f2d
cmpq $0x0, 0x8(%rbx)
je 0x2e99
cmpq $0x0, 0x10(%rbx)
je 0x2e99
cmpq $0x0, 0x18(%rbx)
je 0x2e99
cmpq $0x0, 0x20(%rbx)
je 0x2e99
movss 0x8(%r14), %xmm1
movss 0x10(%rax), %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x10(%rax)
movsd 0x1c(%rax), %xmm3
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movss 0x14(%r14), %xmm4
unpcklps %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
mulps %xmm0, %xmm1
addps %xmm3, %xmm1
movlps %xmm1, 0x1c(%rax)
unpcklps %xmm2, %xmm2            # xmm2 = xmm2[0,0,1,1]
divps %xmm2, %xmm1
movlps %xmm1, 0x14(%rax)
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq 0x20(%rbx), %rbx
jmp 0x2db2
cmpq $0x0, 0x28(%rax)
je 0x2f29
movq %rbx, %rdi
callq 0x2cb7
movq (%rbx), %rax
movq 0x8(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2da8
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2da8
movq (%rbx), %rax
movq 0x18(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2da8
movq (%rbx), %rax
movq 0x20(%rbx), %rdi
movq 0x28(%rax), %rsi
callq 0x2da8
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x2da8
movq (%rbx), %rax
movq $0x0, 0x28(%rax)
jmp 0x2f2d
movq %r14, 0x28(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
retq