// File: Heptagon196[P]Gos/Reflection/ReflMgr.cpp
// Function: FieldInfo* ReflMgr::WalkThroughInherits<FieldInfo>(std::function<void* (void*)>*, TypeID, std::function<FieldInfo* (TypeID)>)
Ret* ReflMgr::WalkThroughInherits(std::function<void*(void*)>* conv, TypeID id, std::function<Ret*(TypeID)> func) {
    std::queue<std::pair<TypeID, std::function<void*(void*)>>> q;
    q.push({id, *conv});
    while (!q.empty()) {
        auto type = q.front().first;
        auto convFunc = q.front().second;
        q.pop();
        auto* ret = func(type);
        if (ret != nullptr) {
            *conv = convFunc;
            return ret;
        }
        if (HasClassInfo(type)) {
            ClassInfo& info = classInfo[type];
            for (int i = 0; i < info.parents.size(); i++) {
                q.push({info.parents[i], [convFunc, info, i](void* instance) { return info.cast[i](convFunc(instance)); }});
            }
        }
    }
    return nullptr;
}

// Assembly:
subq $0x308, %rsp            # imm = 0x308
movq %rdx, 0x68(%rsp)
leaq 0x310(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %rdi, 0x2f8(%rsp)
movq %rsi, 0x2f0(%rsp)
movq %rdx, 0x2e8(%rsp)
movq 0x2f8(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x298(%rsp), %rdi
callq 0x191a10
movq 0x78(%rsp), %rsi
movq 0x2f0(%rsp), %rdx
leaq 0x258(%rsp), %rdi
callq 0x191a70
jmp 0x1915f7
leaq 0x298(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x191a40
jmp 0x19160e
leaq 0x258(%rsp), %rdi
callq 0x191ac0
leaq 0x298(%rsp), %rdi
callq 0x191ae0
movb %al, 0x67(%rsp)
jmp 0x19162e
movb 0x67(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x19163d
jmp 0x1919bf
leaq 0x298(%rsp), %rdi
callq 0x191b00
movq %rax, 0x58(%rsp)
jmp 0x191651
movq 0x58(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0x230(%rsp)
movaps %xmm0, 0x220(%rsp)
leaq 0x298(%rsp), %rdi
callq 0x191b00
movq %rax, 0x50(%rsp)
jmp 0x191681
movq 0x50(%rsp), %rsi
addq $0x20, %rsi
leaq 0x200(%rsp), %rdi
callq 0x191b10
jmp 0x191699
leaq 0x298(%rsp), %rdi
callq 0x191bc0
jmp 0x1916a8
movq 0x68(%rsp), %rdi
movaps 0x220(%rsp), %xmm0
movaps 0x230(%rsp), %xmm1
movaps %xmm1, 0x1e0(%rsp)
movaps %xmm0, 0x1d0(%rsp)
movaps 0x1d0(%rsp), %xmm0
movaps 0x1e0(%rsp), %xmm1
movq %rsp, %rax
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x191bd0
movq %rax, 0x48(%rsp)
jmp 0x1916f3
movq 0x48(%rsp), %rax
movq %rax, 0x1f8(%rsp)
cmpq $0x0, 0x1f8(%rsp)
je 0x19179e
movq 0x2f0(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x191c10
jmp 0x191726
movq 0x1f8(%rsp), %rax
movq %rax, 0x300(%rsp)
movl $0x1, 0x1cc(%rsp)
jmp 0x191991
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x1919f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x191ac0
jmp 0x1919f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x1919b0
movq 0x70(%rsp), %rdi
movaps 0x220(%rsp), %xmm0
movaps 0x230(%rsp), %xmm1
movaps %xmm1, 0x1b0(%rsp)
movaps %xmm0, 0x1a0(%rsp)
movaps 0x1a0(%rsp), %xmm0
movaps 0x1b0(%rsp), %xmm1
movq %rsp, %rax
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x4a420
movb %al, 0x47(%rsp)
jmp 0x1917e8
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x1917f5
jmp 0x191986
movq 0x70(%rsp), %rdi
addq $0x90, %rdi
leaq 0x220(%rsp), %rsi
callq 0x6b980
movq %rax, 0x38(%rsp)
jmp 0x191815
movq 0x38(%rsp), %rax
movq %rax, 0x198(%rsp)
movl $0x0, 0x194(%rsp)
movslq 0x194(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x198(%rsp), %rdi
addq $0x20, %rdi
callq 0x57080
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x191984
movq 0x198(%rsp), %rdi
addq $0x20, %rdi
movslq 0x194(%rsp), %rsi
callq 0x190e30
movq %rax, 0x20(%rsp)
leaq 0x80(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x200(%rsp), %rsi
callq 0x191b10
jmp 0x191896
leaq 0xa0(%rsp), %rdi
movq 0x198(%rsp), %rsi
callq 0x191c60
jmp 0x1918ad
movq 0x20(%rsp), %rsi
movl 0x194(%rsp), %eax
movl %eax, 0x148(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x191d60
jmp 0x1918d7
leaq 0x298(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x191a40
jmp 0x1918ee
leaq 0x150(%rsp), %rdi
callq 0x191ac0
leaq 0x80(%rsp), %rdi
callq 0x191db0
movl 0x194(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x194(%rsp)
jmp 0x19182d
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
callq 0x56a00
jmp 0x1919b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x191975
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x191ac0
leaq 0x80(%rsp), %rdi
callq 0x191db0
jmp 0x1919b0
jmp 0x191986
movl $0x0, 0x1cc(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x56a00
movl 0x1cc(%rsp), %eax
testl %eax, %eax
jne 0x1919d6
jmp 0x1919ab
jmp 0x19161b
leaq 0x200(%rsp), %rdi
callq 0x56a00
jmp 0x1919f3
movq $0x0, 0x300(%rsp)
movl $0x1, 0x1cc(%rsp)
leaq 0x298(%rsp), %rdi
callq 0x191de0
movq 0x300(%rsp), %rax
addq $0x308, %rsp            # imm = 0x308
retq
leaq 0x298(%rsp), %rdi
callq 0x191de0
movq 0x250(%rsp), %rdi
callq 0x133f0
nopl (%rax)