// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x3d3e
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3700
testb $0x1, %al
jne 0x3b05
jmp 0x3d3e
movq 0x10(%rsp), %rdi
callq 0x38e0
testb $0x1, %al
jne 0x3b18
jmp 0x3c14
movq 0x10(%rsp), %rax
movq (%rax), %rdi
callq 0x37c0
testb $0x1, %al
jne 0x3b2b
jmp 0x3b41
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x28(%rax)
jmp 0x3c0f
movq 0x10(%rsp), %rdi
callq 0x3950
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x28(%rax)
jmp 0x3d3c
movq 0x8(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
addss 0x10(%rax), %xmm0
movss %xmm0, 0x10(%rax)
movq 0x8(%rsp), %rax
movss 0x10(%rax), %xmm0
movq 0x8(%rsp), %rax
movss 0x8(%rax), %xmm2
movq 0x10(%rsp), %rax
movq (%rax), %rax
movss 0x1c(%rax), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x1c(%rax)
movq 0x8(%rsp), %rax
movss 0x14(%rax), %xmm0
movq 0x8(%rsp), %rax
movss 0x8(%rax), %xmm2
movq 0x10(%rsp), %rax
movq (%rax), %rax
movss 0x20(%rax), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x20(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movss 0x1c(%rax), %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
divss 0x10(%rax), %xmm0
movss %xmm0, 0x4(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movss 0x20(%rax), %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
divss 0x10(%rax), %xmm0
movss %xmm0, (%rsp)
movss 0x4(%rsp), %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movss %xmm0, 0x14(%rax)
movss (%rsp), %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movss %xmm0, 0x18(%rax)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x3ad0
jmp 0x3d3e
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)