// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/encoding/../maniac/compound_enc.h
// Function: PropertySymbolCoder<SimpleBitChance, RacDummy<DummyIO>, 15>::find_leaf(std::vector<int, std::allocator<int>> const&)
CompoundSymbolChances<BitChance,bits> inline &find_leaf(const Properties &properties) {
        uint32_t pos = 0;
        Ranges current_ranges = range;
        while(inner_node[pos].property != -1) {
            if (properties[inner_node[pos].property] > inner_node[pos].splitval) {
                current_ranges[inner_node[pos].property].first = inner_node[pos].splitval + 1;
                pos = inner_node[pos].childID;
            } else {
                current_ranges[inner_node[pos].property].second = inner_node[pos].splitval;
                pos = inner_node[pos].childID+1;
            }
        }
//        CompoundSymbolChances<BitChance,bits> &result = leaf_node[inner_node[pos].leafID];
        CompoundSymbolChances<BitChance,bits> &result = leaf_node[inner_node[pos].childID];
        set_selection_and_update_property_sums(properties,result,current_ranges);

        // split leaf node if some virtual context is performing (significantly) better
        if(result.best_property != -1
           && result.realSize > result.virtSize[result.best_property] + split_threshold
           && leaf_node.size() < 0xFFFF && inner_node.size() < 0xFFFF
           && current_ranges[result.best_property].first < current_ranges[result.best_property].second) {

          int16_t p = result.best_property;
          PropertyVal splitval = compute_splitval(result,p,current_ranges);
//            printf("splitting on property %i, splitval %i (pos=%i)\n",p,splitval,pos);
/*
          PropertyVal splitval = div_down(result.virtPropSum[p],result.count);
          if (splitval >= current_ranges[result.best_property].second)
             splitval = current_ranges[result.best_property].second-1; // == does happen because of rounding and running average
*/

          uint32_t new_inner = inner_node.size();
          inner_node.push_back(inner_node[pos]);
          inner_node.push_back(inner_node[pos]);
          inner_node[pos].splitval = splitval;
//            fprintf(stdout,"Splitting on property %i, splitval=%i (count=%i)\n",p,inner_node[pos].splitval, (int)result.count);
          inner_node[pos].property = p;
//          if (result.count < INT16_MAX) inner_node[pos].count = result.count;
//          else inner_node[pos].count = INT16_MAX;
          uint32_t new_leaf = leaf_node.size();
          result.resetCounters();
          leaf_node.push_back(CompoundSymbolChances<BitChance,bits>(result));
//          uint32_t old_leaf = inner_node[pos].leafID;
          uint32_t old_leaf = inner_node[pos].childID;
          inner_node[pos].childID = new_inner;
//          inner_node[new_inner].leafID = old_leaf;
//          inner_node[new_inner+1].leafID = new_leaf;
          inner_node[new_inner].childID = old_leaf;
          inner_node[new_inner+1].childID = new_leaf;
//          leaf_node[old_leaf].range[p].first = splitval+1;
//          leaf_node[new_leaf].range[p].second = splitval;
          if (properties[p] > inner_node[pos].splitval) {
                return leaf_node[old_leaf];
          } else {
                return leaf_node[new_leaf];
          }
        }
        return result;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4018(%rdi), %rsi
leaq 0x20(%rsp), %rdi
callq 0x18d8a
movq 0x4050(%rbx), %rdi
movq (%rdi), %r9
movzwl (%r9), %edx
cmpw $-0x1, %dx
movq %r14, 0x8(%rsp)
movq %rdi, 0x50(%rsp)
je 0x19d00
movq (%r14), %rax
movq 0x20(%rsp), %rcx
movq %r9, %r8
movswq %dx, %rdx
movl 0x4(%r8), %esi
cmpl %esi, (%rax,%rdx,4)
jle 0x19ce4
incl %esi
movl %esi, (%rcx,%rdx,8)
movzwl 0x2(%r8), %r12d
jmp 0x19cf0
movl %esi, 0x4(%rcx,%rdx,8)
movzwl 0x2(%r8), %r12d
incq %r12
leaq (%r9,%r12,8), %r8
movzwl (%r8), %edx
cmpw $-0x1, %dx
jne 0x19ccb
jmp 0x19d06
xorl %r12d, %r12d
movq %r9, %r8
movzwl 0x2(%r8), %eax
movq 0x4038(%rbx), %rcx
imulq $0x98, %rax, %rdx
leaq (%rcx,%rdx), %rax
movq %rax, 0x18(%rsp)
movslq 0x90(%rcx,%rdx), %r10
incq %r10
movq %rcx, 0x58(%rsp)
movq %rdx, 0x48(%rsp)
movl %r10d, 0x90(%rcx,%rdx)
movq %rbx, 0x10(%rsp)
movl 0x4030(%rbx), %esi
testq %rsi, %rsi
je 0x19e0b
movq 0x8(%rsp), %rax
movq (%rax), %r11
movq 0x18(%rsp), %rax
movq 0x78(%rax), %r14
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %rax
movq 0x4058(%rax), %r13
xorl %edi, %edi
xorl %ecx, %ecx
movslq (%r11,%rcx,4), %r15
addq %r15, (%r14,%rcx,8)
movq %rdi, %rbx
sarq $0x30, %rbx
movq %rdi, %rax
sarq $0x2d, %rax
cmpl $0x0, (%rbp,%rax)
js 0x19da6
movq (%r14,%rbx,8), %rax
testq %rax, %rax
js 0x19db1
cqto
idivq %r10
jmp 0x19dbe
xorl %edx, %edx
cmpl $0x0, 0x4(%rbp,%rbx,8)
jg 0x19dca
jmp 0x19d96
notq %rax
addq %r10, %rax
cqto
idivq %r10
negl %eax
movl 0x4(%rbp,%rbx,8), %ebx
leal -0x1(%rbx), %edx
cmpl %ebx, %eax
cmovll %eax, %edx
movq %rcx, %rax
shrq $0x6, %rax
movl $0x1, %ebx
shlq %cl, %rbx
cmpl %edx, %r15d
jle 0x19de5
orq (%r13,%rax,8), %rbx
jmp 0x19ded
notq %rbx
andq (%r13,%rax,8), %rbx
movq %rbx, (%r13,%rax,8)
incq %rcx
movabsq $0x1000000000000, %rax  # imm = 0x1000000000000
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x19d79
movq 0x18(%rsp), %r13
movswq 0x94(%r13), %r14
cmpq $-0x1, %r14
je 0x1a0ac
movq 0x60(%r13), %rax
movq 0x10(%rsp), %r15
movslq 0x4080(%r15), %rcx
addq (%rax,%r14,8), %rcx
cmpq %rcx, 0x58(%r13)
jbe 0x1a0ac
movq 0x4040(%r15), %rax
movq 0x58(%rsp), %rbp
subq %rbp, %rax
sarq $0x3, %rax
movabsq $-0x79435e50d79435e5, %rcx # imm = 0x86BCA1AF286BCA1B
imulq %rcx, %rax
cmpq $0xfffe, %rax           # imm = 0xFFFE
ja 0x1a0ac
movq 0x50(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq %rsi, %rdx
subq %r9, %rdx
movq %rdx, %r9
sarq $0x3, %r9
cmpq $0xfffe, %r9            # imm = 0xFFFE
ja 0x1a0ac
movq 0x20(%rsp), %rcx
movl (%rcx,%r14,8), %eax
movl 0x4(%rcx,%r14,8), %ecx
cmpl %ecx, %eax
jge 0x1a0ac
movq %r9, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
testl %eax, %eax
sets %al
testl %ecx, %ecx
setg %dl
xorl %ebx, %ebx
testb %dl, %al
jne 0x19eec
movq 0x78(%r13), %rax
movq (%rax,%r14,8), %rax
movslq %r10d, %r9
testq %rax, %rax
js 0x19ed7
cqto
idivq %r9
jmp 0x19ee4
notq %rax
addq %r9, %rax
cqto
idivq %r9
negl %eax
leal -0x1(%rcx), %ebx
cmpl %ecx, %eax
cmovll %eax, %ebx
cmpq 0x10(%rdi), %rsi
je 0x19eff
movq (%r8), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x19f07
movq %r8, %rdx
callq 0x1a1c2
movq 0x4050(%r15), %rdi
leal (,%r12,8), %edx
addq (%rdi), %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x19f30
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x19f35
callq 0x1a1c2
movq 0x4050(%r15), %rax
movq (%rax), %rax
movl %ebx, 0x4(%rax,%r12,8)
movw %r14w, (%rax,%r12,8)
movq 0x4040(%r15), %rbx
subq 0x4038(%r15), %rbx
movq %r13, %rdi
callq 0x1a152
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups 0x2e(%r13), %xmm3
leaq 0xa0(%rsp), %rdi
movups %xmm3, -0x12(%rdi)
movaps %xmm2, -0x20(%rdi)
movaps %xmm1, -0x30(%rdi)
movaps %xmm0, -0x40(%rdi)
leaq 0x40(%r13), %rsi
callq 0x199c4
leaq 0x60(%r13), %rsi
movq 0x58(%r13), %rax
leaq 0xc0(%rsp), %rdi
movq %rax, -0x8(%rdi)
callq 0x19a62
leaq 0xd8(%rsp), %rdi
addq $0x78, %r13
movq %r13, %rsi
callq 0x19ae2
leaq 0x4038(%r15), %rdi
movq 0x48(%rsp), %rax
addq %rbp, %rax
addq $0x90, %rax
movzwl 0x4(%rax), %ecx
leaq 0x60(%rsp), %rsi
movw %cx, 0x94(%rsi)
movl (%rax), %eax
movl %eax, 0x90(%rsi)
callq 0x1aa84
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x1a010
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
sarq $0x3, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x1a031
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movabsq $-0x79435e50d79435e5, %rax # imm = 0x86BCA1AF286BCA1B
imulq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x1a05c
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x4050(%r15), %rax
movq (%rax), %rcx
movzwl 0x2(%rcx,%r12,8), %eax
movq 0x38(%rsp), %rdx
movw %dx, 0x2(%rcx,%r12,8)
movq 0x40(%rsp), %rdx
movw %ax, 0x2(%rcx,%rdx)
movw %bx, 0xa(%rcx,%rdx)
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movl (%rdx,%r14,4), %edx
movq 0x4038(%r15), %r13
cmpl 0x4(%rcx,%r12,8), %edx
jg 0x1a0a2
movl %ebx, %eax
imulq $0x98, %rax, %rax
addq %rax, %r13
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1a0c3
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %r13, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1a12f
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x18fd0
jmp 0x1a132
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x1a10e
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x1a10e
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x1a132
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x1a132
jmp 0x1a12f
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1a149
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x35a0
nop