// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_expr.c
// Function: doInterfaceToInterfaceConv
static void doInterfaceToInterfaceConv(Compiler *comp, const Type *dest, const Type **src, Const *constant)
{
    if (constant)
        comp->error.handler(comp->error.context, "Conversion to interface is not allowed in constant expressions");

    int destOffset = identAllocStack(&comp->idents, &comp->types, &comp->blocks, dest);

    // Assign to #self
    genDup(&comp->gen);                                                     // Duplicate src pointer
    genDeref(&comp->gen, TYPE_PTR);                                         // Get src.#self value
    genPushLocalPtr(&comp->gen, destOffset);                                // Push dest pointer
    genSwapAssign(&comp->gen, TYPE_PTR, 0);                                 // Assign to dest.#self (NULL means a dynamic type)

    // Assign to #selftype (RTTI)
    const Field *selfType = typeAssertFindField(&comp->types, dest, "#selftype", NULL);

    genDup(&comp->gen);                                                     // Duplicate src pointer
    genGetFieldPtr(&comp->gen, selfType->offset);                           // Get src.#selftype pointer
    genDeref(&comp->gen, TYPE_PTR);                                         // Get src.#selftype value
    genPushLocalPtr(&comp->gen, destOffset + selfType->offset);             // Push dest.#selftype pointer
    genSwapAssign(&comp->gen, TYPE_PTR, 0);                                 // Assign to dest.#selftype

    // Assign to methods
    for (int i = 2; i < dest->numItems; i++)
    {
        const char *name = dest->field[i]->name;
        const Field *srcMethod = typeFindField(*src, name, NULL);
        if (!srcMethod)
        {
            char srcBuf[DEFAULT_STR_LEN + 1], destBuf[DEFAULT_STR_LEN + 1];
            comp->error.handler(comp->error.context, "Cannot convert %s to %s: method %s is not implemented", typeSpelling(*src, srcBuf), typeSpelling(dest, destBuf), name);
        }

        if (!typeCompatible(dest->field[i]->type, srcMethod->type))
        {
            char srcBuf[DEFAULT_STR_LEN + 1], destBuf[DEFAULT_STR_LEN + 1];
            comp->error.handler(comp->error.context, "Cannot convert %s to %s: method %s has incompatible signature", typeSpelling(*src, srcBuf), typeSpelling(dest, destBuf), name);
        }

        genDup(&comp->gen);                                                 // Duplicate src pointer
        genGetFieldPtr(&comp->gen, srcMethod->offset);                      // Get src.method pointer
        genDeref(&comp->gen, TYPE_FN);                                      // Get src.method value (entry point)
        genPushLocalPtr(&comp->gen, destOffset + dest->field[i]->offset);   // Push dest.method pointer
        genSwapAssign(&comp->gen, TYPE_FN, 0);                              // Assign to dest.method
    }

    genPop(&comp->gen);                                                     // Remove src pointer
    genPushLocalPtr(&comp->gen, destOffset);
    *src = dest;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xf903
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1c90a9(%rip), %rsi    # 0x1d89a8
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x4e18, %rsi           # imm = 0x4E18
movq -0x8(%rbp), %rdx
addq $0x4220, %rdx           # imm = 0x4220
movq -0x10(%rbp), %rcx
callq 0x1a320
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16eb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x10, %esi
callq 0x16fa0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x24(%rbp), %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x10, %esi
xorl %edx, %edx
callq 0x17120
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x10(%rbp), %rsi
leaq 0x1c4a49(%rip), %rdx    # 0x1d43de
xorl %eax, %eax
movl %eax, %ecx
callq 0x23000
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16eb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x30(%rbp), %rax
movl 0x110(%rax), %esi
callq 0x17bb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x10, %esi
callq 0x16fa0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x24(%rbp), %esi
movq -0x30(%rbp), %rax
addl 0x110(%rax), %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x10, %esi
xorl %edx, %edx
callq 0x17120
movl $0x2, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xfc03
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x22ee0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xfad5
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rax
movq %rax, -0x458(%rbp)
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rax
movq %rax, -0x468(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
leaq -0x150(%rbp), %rsi
callq 0x22070
movq %rax, -0x460(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x22070
movq -0x468(%rbp), %rdi
movq -0x460(%rbp), %rdx
movq -0x458(%rbp), %r9
movq %rax, %rcx
movq -0x40(%rbp), %r8
leaq 0x1c8f17(%rip), %rsi    # 0x1d89e7
movb $0x0, %al
callq *%r9
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x108(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x108(%rax), %rsi
callq 0x22790
testb $0x1, %al
jne 0xfb76
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rax
movq %rax, -0x470(%rbp)
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rax
movq %rax, -0x480(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
leaq -0x350(%rbp), %rsi
callq 0x22070
movq %rax, -0x478(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x22070
movq -0x480(%rbp), %rdi
movq -0x478(%rbp), %rdx
movq -0x470(%rbp), %r9
movq %rax, %rcx
movq -0x40(%rbp), %r8
leaq 0x1c8eac(%rip), %rsi    # 0x1d8a1d
movb $0x0, %al
callq *%r9
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16eb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x48(%rbp), %rax
movl 0x110(%rax), %esi
callq 0x17bb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x1a, %esi
callq 0x16fa0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x24(%rbp), %esi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addl 0x110(%rax), %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x1a, %esi
xorl %edx, %edx
callq 0x17120
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xfa1c
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16d30
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x24(%rbp), %esi
callq 0x169a0
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq
nopw (%rax,%rax)