// File: WinChua[P]MLDemo/DecisionTree.cpp
// Function: TreeNode::gain_of_attr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&)
double TreeNode::gain_of_attr(std::string attr, std::vector<int> &l_index, std::vector<int> &r_index)
{
    double en = entropy();
    float index_size = record_index.size();
    for(auto ri : record_index)
    {
        if(data.records[ri].data.find(attr) == data.records[ri].data.end())
        {
            r_index.push_back(ri);
        }
        else l_index.push_back(ri);
    }
    double r_entropy = _entropy(r_index);
    double l_entropy = _entropy(l_index);
    double div = r_index.size()/index_size* r_entropy + l_index.size() / index_size* l_entropy;
    double gain = en - div;
    return gain;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rsi, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x3970
movq -0x90(%rbp), %rdi
movsd %xmm0, -0x28(%rbp)
addq $0x8, %rdi
callq 0x3d40
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x88(%rbp)
testq %rax, %rax
movss %xmm0, -0x84(%rbp)
js 0x3638
movss -0x88(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
movq -0x90(%rbp), %rax
movss -0x84(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3d80
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3db0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3de0
testb $0x1, %al
jne 0x3684
jmp 0x372c
leaq -0x40(%rbp), %rdi
callq 0x3e20
movq %rax, %rcx
movq -0x90(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x4c(%rbp)
movq (%rax), %rdi
addq $0x20, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x3e40
movq -0x98(%rbp), %rsi
movq %rax, %rdi
addq $0x8, %rdi
callq 0x3eb0
movq %rax, %rcx
movq -0x90(%rbp), %rax
movq %rcx, -0x58(%rbp)
movq (%rax), %rdi
addq $0x20, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x3e40
movq %rax, %rdi
addq $0x8, %rdi
callq 0x3ee0
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3e80
testb $0x1, %al
jne 0x3700
jmp 0x370f
movq -0x20(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x3b00
jmp 0x371c
movq -0x18(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x3b00
jmp 0x371e
leaq -0x40(%rbp), %rdi
callq 0x3e60
jmp 0x366e
movq -0x90(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x39a0
movq -0x90(%rbp), %rdi
movsd %xmm0, -0x68(%rbp)
movq -0x18(%rbp), %rsi
callq 0x39a0
movsd %xmm0, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3d40
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0xa0(%rbp)
testq %rax, %rax
movss %xmm0, -0x9c(%rbp)
js 0x37a0
movss -0xa0(%rbp), %xmm0
movss %xmm0, -0x9c(%rbp)
movss -0x9c(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3d40
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0xa8(%rbp)
testq %rax, %rax
movss %xmm0, -0xa4(%rbp)
js 0x3814
movss -0xa8(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movsd -0xb0(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm0
movss -0xa4(%rbp), %xmm1
divss -0x2c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd -0x70(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x28(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)