// File: cloudinary[P]fuif/encoding/../maniac/compound.h
// Function: FinalPropertySymbolCoder<SimpleBitChance, RacOutput24<BlobIO>, 15>::find_leaf(std::vector<int, std::allocator<int>> const&)
FinalCompoundSymbolChances<BitChance,bits> inline &find_leaf(const Properties &properties) ATTRIBUTE_HOT {
        Tree::size_type pos = 0;

        while(true) {
//                if (inner_node[pos].property == -1) assert(inner_node[pos].leafID < leaf_node.size());
//                if (inner_node[pos].property == -1) return leaf_node[inner_node[pos].leafID];
//                if (inner_node[pos].count >= 0) break;
                if (inner_node[pos].property == -1) return leaf_node[inner_node[pos].childID];
                if (properties[inner_node[pos].property] > inner_node[pos].splitval)
                     pos = inner_node[pos].childID;
                else pos = inner_node[pos].childID+1;
        }
/*
        if (inner_node[pos].count > 0) {
                inner_node[pos].count--;
                return leaf_node[inner_node[pos].leafID];
        } else if (inner_node[pos].count == 0) {
                inner_node[pos].count--;
                FinalCompoundSymbolChances<BitChance,bits> &result = leaf_node[inner_node[pos].leafID];
                uint32_t old_leaf = inner_node[pos].leafID;
                uint32_t new_leaf = leaf_node.size();
                leaf_node.push_back(result);
                inner_node[inner_node[pos].childID].leafID = old_leaf;
                inner_node[inner_node[pos].childID+1].leafID = new_leaf;
                if (properties[inner_node[pos].property] > inner_node[pos].splitval) {
                  return leaf_node[old_leaf];
                } else {
                  return leaf_node[new_leaf];
                }
        }
*/
/*

        while(inner_node[pos].property != -1) {
            if (inner_node[pos].count < 0) {
                if (properties[inner_node[pos].property] > inner_node[pos].splitval) {
                  pos = inner_node[pos].childID;
                } else {
                  pos = inner_node[pos].childID+1;
                }
            } else if (inner_node[pos].count > 0) {
                assert(inner_node[pos].leafID >= 0);
                assert((unsigned int)inner_node[pos].leafID < leaf_node.size());
                inner_node[pos].count--;
                break;
            } else if (inner_node[pos].count == 0) {
                inner_node[pos].count--;
                FinalCompoundSymbolChances<BitChance,bits> &result = leaf_node[inner_node[pos].leafID];
                uint32_t old_leaf = inner_node[pos].leafID;
                uint32_t new_leaf = leaf_node.size();
                FinalCompoundSymbolChances<BitChance,bits> resultCopy = result;
                leaf_node.push_back(resultCopy);
                inner_node[inner_node[pos].childID].leafID = old_leaf;
                inner_node[inner_node[pos].childID+1].leafID = new_leaf;
                if (properties[inner_node[pos].property] > inner_node[pos].splitval) {
                  return leaf_node[old_leaf];
                } else {
                  return leaf_node[new_leaf];
                }
            }
        }
        return leaf_node[inner_node[pos].leafID];
*/
    }

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq 0x4030(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x30990
movswl (%rax), %eax
cmpl $-0x1, %eax
jne 0x35999
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x4018, %rcx           # imm = 0x4018
movq %rcx, 0x10(%rsp)
movq 0x4030(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x30990
movq 0x10(%rsp), %rdi
movzwl 0x2(%rax), %eax
movl %eax, %esi
callq 0x355b0
addq $0x38, %rsp
retq
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x4030(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x30990
movq (%rsp), %rdi
movswq (%rax), %rsi
callq 0x13560
movq %rax, %rcx
movq 0x18(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0xc(%rsp)
movq 0x4030(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x30990
movq %rax, %rcx
movl 0xc(%rsp), %eax
cmpl 0x4(%rcx), %eax
jle 0x35a11
movq 0x18(%rsp), %rax
movq 0x4030(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x30990
movzwl 0x2(%rax), %eax
movq %rax, 0x20(%rsp)
jmp 0x35a35
movq 0x18(%rsp), %rax
movq 0x4030(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x30990
movzwl 0x2(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, 0x20(%rsp)
jmp 0x35941
nopw (%rax,%rax)