// File: WinChua[P]MLDemo/DecisionTree.cpp
// Function: TreeNode::choose_attr(std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&)
struct TreeNode::FeatureGain TreeNode::choose_attr(std::vector<int> &max_l_index, std::vector<int> &max_r_index)
{
    std::string max_attr("no");
    double max_entropy=0.0;
    std::vector<int> l_index, r_index;
    for(auto feature : data.featureset)
    {
        double gain = gain_of_attr(feature, l_index, r_index);
        if(gain > max_entropy)
        {
            max_attr = feature;
            swap(max_l_index, l_index);
            swap(max_r_index, r_index);
            max_entropy = gain;
        }
        r_index.clear();
        l_index.clear();
    }
    if(max_entropy <  0.005)
    {
        return {"no divided", 0.0};
    }
    return {max_attr, max_entropy};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x118(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x2360
movq -0x100(%rbp), %rdx
leaq 0x93c7(%rip), %rsi      # 0xc07c
leaq -0x40(%rbp), %rdi
callq 0x4370
jmp 0x2cc0
leaq -0x41(%rbp), %rdi
callq 0x2260
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3a80
leaq -0x90(%rbp), %rdi
callq 0x3a80
movq -0x108(%rbp), %rax
movq (%rax), %rax
addq $0x38, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x4420
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x4450
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4480
testb $0x1, %al
jne 0x2d3d
jmp 0x2e9a
leaq -0xa0(%rbp), %rdi
callq 0x44b0
movq %rax, %rsi
leaq -0xc8(%rbp), %rdi
callq 0x20f0
jmp 0x2d5a
leaq -0xf0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x20f0
jmp 0x2d6f
movq -0x108(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x90(%rbp), %rcx
callq 0x35b0
movsd %xmm0, -0x120(%rbp)
jmp 0x2d97
leaq -0xf0(%rbp), %rdi
callq 0x2140
movsd -0x120(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x2e57
leaq -0x40(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2040
jmp 0x2dd8
movq -0x18(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x44d0
movq -0x20(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x44d0
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x2e57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x2260
jmp 0x2f92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2f74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2e89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2140
jmp 0x2e89
leaq -0x90(%rbp), %rdi
callq 0x4500
leaq -0x78(%rbp), %rdi
callq 0x4500
leaq -0xc8(%rbp), %rdi
callq 0x2140
leaq -0xa0(%rbp), %rdi
callq 0x4520
jmp 0x2d21
leaq -0xc8(%rbp), %rdi
callq 0x2140
jmp 0x2f74
movsd 0x9166(%rip), %xmm0     # 0xc008
ucomisd -0x60(%rbp), %xmm0
jbe 0x2f19
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x2360
movq -0x118(%rbp), %rdi
movq -0x128(%rbp), %rdx
leaq 0x914b(%rip), %rsi      # 0xc01c
callq 0x4370
jmp 0x2ed8
movq -0x118(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rax)
leaq -0xf1(%rbp), %rdi
callq 0x2260
movl $0x1, -0xf8(%rbp)
jmp 0x2f46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf1(%rbp), %rdi
callq 0x2260
jmp 0x2f74
movq -0x118(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x20f0
jmp 0x2f2b
movq -0x118(%rbp), %rax
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
movl $0x1, -0xf8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3b90
leaq -0x78(%rbp), %rdi
callq 0x3b90
leaq -0x40(%rbp), %rdi
callq 0x2140
movq -0x110(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x3b90
leaq -0x78(%rbp), %rdi
callq 0x3b90
leaq -0x40(%rbp), %rdi
callq 0x2140
movq -0x50(%rbp), %rdi
callq 0x2350
nopl (%rax,%rax)