// File: nishalkulkarni[P]fluid-wm/bsp.cpp
// Function: Node::split_node(unsigned long)
std::tuple<Node*, Node*> Node::split_node(Window new_window)
{
    Node* left_child = new Node();
    Node* right_child = new Node();

    left_child->set_window(this->window);
    right_child->set_window(new_window);

    int split_width = this->width, split_height = this->height;
    int split_x = this->x, split_y = this->y;
    if (this->width >= this->height) {
        split_width /= 2;
        split_x += split_width;
        left_child->set_dimensions(split_width, this->height, this->x, this->y);
        right_child->set_dimensions(this->width - split_width, this->height, split_x, this->y);
    } else if (this->width < this->height) {
        split_height /= 2;
        split_y += split_height;
        left_child->set_dimensions(this->width, split_height, this->x, this->y);
        right_child->set_dimensions(this->width, this->height - split_height, this->x, split_y);
    }

    set_children(left_child, right_child);

    return std::make_tuple(left_child, right_child);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x68(%rbp)
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x28, %edi
callq 0x4250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
callq 0xbe80
jmp 0xc102
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x28, %edi
callq 0x4250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0xbe80
jmp 0xc125
movq -0x58(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movq 0x10(%rax), %rsi
callq 0xbee0
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xbee0
movq -0x58(%rbp), %rcx
movl (%rcx), %eax
movl %eax, -0x3c(%rbp)
movl 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
movl 0x8(%rcx), %eax
movl %eax, -0x44(%rbp)
movl 0xc(%rcx), %eax
movl %eax, -0x48(%rbp)
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
jl 0xc203
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
addl -0x44(%rbp), %ecx
movl %ecx, -0x44(%rbp)
movq -0x20(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl 0x4(%rax), %edx
movl 0x8(%rax), %ecx
movl 0xc(%rax), %r8d
callq 0xbea0
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rdi
movl (%rax), %esi
subl -0x3c(%rbp), %esi
movl 0x4(%rax), %edx
movl -0x44(%rbp), %ecx
movl 0xc(%rax), %r8d
callq 0xbea0
jmp 0xc25e
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0xc28a
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0xc28a
movq -0x58(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
jge 0xc25c
movl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, -0x40(%rbp)
movl -0x40(%rbp), %ecx
addl -0x48(%rbp), %ecx
movl %ecx, -0x48(%rbp)
movq -0x20(%rbp), %rdi
movl (%rax), %esi
movl -0x40(%rbp), %edx
movl 0x8(%rax), %ecx
movl 0xc(%rax), %r8d
callq 0xbea0
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rdi
movl (%rax), %esi
movl 0x4(%rax), %edx
subl -0x40(%rbp), %edx
movl 0x8(%rax), %ecx
movl -0x48(%rbp), %r8d
callq 0xbea0
jmp 0xc25e
movq -0x58(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xbf00
movq -0x68(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0xcb00
movq -0x60(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x44b0
nopw %cs:(%rax,%rax)