// File: /workspace/github_cpp_makefile_star2_O2/Heptagon196[P]Gos/GosASTCompiler.cpp
// Function: Gos::AST::LambdaDef::CompileAST(Gos::Compiler::VMCompiler&)
Compile(LambdaDef) {
    START();

    int start = 0;
    std::stringstream ss;
    ss << compilingFileName << ":" << compilingLine << "_#" << (lambdaCount++);
    std::string lambdaName = ss.str();
    std::vector<std::pair<std::string, int>> captureVarNames;
    std::vector<int> captureType;
    std::vector<std::string> captureTypeName;
    std::vector<int> capturedID;
    std::vector<std::string> argTypes;
    std::vector<std::string> argNames;
    std::vector<std::string> ctorTypes;
    if (branch & 1) {
        std::string errorInfo;
        for (GosAST* ast : nodes[start]->nodes) {
            int id = code.currentScope->GetVarID(ast->token.str, errorInfo);
            std::string varType = "";
            if (errorInfo.size() > 0) {
                for (int i = 0; i < compilingClassVars.size(); i++) {
                    if (compilingClassVars[i] == ast->token.str) {
                        int& cache = GetFieldCache(code.currentScope, ast->token.str);
                        if (cache != -1) {
                            id = cache;
                        } else {
                            id = code.GetTmpVar();
                            vm.WriteCommandGetField(id, 1, ast->token.str);
                            cache = id;
                        }
                        varType = compilingClassVarTypes[i];
                        errorInfo = "";
                        break;
                    }
                }
                if (errorInfo.size() > 0) {
                    std::cerr << errorInfo << std::endl;
                }
            } else {
                varType = code.currentScope->GetVarType(ast->token.str);
            }
            captureVarNames.push_back({ ast->token.str, id });
            captureType.push_back(ast->branch);
            capturedID.push_back(captureVarNames[captureVarNames.size() - 1].second);
            captureTypeName.push_back(varType);
        }
        start++;
    }
    if (branch & 2) {
        for (auto* ast : nodes[start]->nodes) {
            argNames.push_back(ast->nodes[0]->token.str);
            argTypes.push_back(ast->nodes[1]->token.str);
        }
        start++;
    }

    auto jmpFromStartTo = vm.WriteCommandJmp();
    int startPos = vm.GetProgress();

    vm.WriteCommandDefClass(lambdaName, {});

    for (int i = 0; i < captureVarNames.size(); i++) {
        vm.WriteCommandDefVar(captureTypeName[i], captureVarNames[i].first);
        ctorTypes.push_back(captureTypeName[i]);
    }

    code.MoveToNew();
    int pcBack = pc;

    auto jmpCall = vm.WriteCommandDefFunc("__call", nodes[start++]->token.str, argTypes);
    auto setMemSize = vm.WriteAlloc();

    pc = 1;

    vm.WriteCommandArg(pc++, 0);
    for (int i = 0; i < argNames.size(); i++) {
        int id = pc++;
        vm.WriteCommandArg(id, i + 1);
        code.currentScope->varID[argNames[i]] = id;
        code.currentScope->varType[argNames[i]] = argTypes[i];
    }

    for (int i = 0; i < captureVarNames.size(); i++) {
        int id = pc++;
        vm.WriteCommandGetField(id, 1, captureVarNames[i].first);
        code.currentScope->varID[captureVarNames[i].first] = id;
        code.currentScope->varType[captureVarNames[i].first] = captureTypeName[i];
    }

    SUB(start++);

    jmpCall(vm.GetProgress());

    setMemSize(pc);
    pc = pcBack;
    code.MoveBack();

    code.lambdaDefStartPos.push_back(startPos);
    code.lambdaDefJumpout.push_back(vm.WriteCommandJmp());
    jmpFromStartTo(vm.GetProgress());

    int tmp = code.GetTmpVar();
    vm.WriteCommandNew(lambdaName, tmp, capturedID);

    for (int i = 0; i < captureVarNames.size(); i++) {
        int id = pc++;
        vm.WriteCommandGetField(id, tmp, captureVarNames[i].first);
        if (captureType[i] == 0) {
            if (captureTypeName[i] == "unknown") {
                vm.WriteCommandClone(id, captureVarNames[i].second);
            } else {
                vm.WriteCommandMov(id, captureVarNames[i].second);
            }
        } else {
            vm.WriteCommandRef(id, captureVarNames[i].second);
        }
    }

    return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movl 0x2c(%rdi), %eax
movl %eax, 0x7fe6a(%rip)     # 0x107278
movq 0x18(%rdi), %rax
movq %rdi, 0x8(%rsp)
cmpq 0x10(%rdi), %rax
je 0x8773c
movq %rsi, %rbx
leaq 0x1b0(%rsp), %rdi
callq 0x11270
leaq 0x1c0(%rsp), %rdi
leaq 0x7fdb0(%rip), %rsi     # 0x1071f0
callq 0x11320
leaq 0xe8b1(%rip), %rsi      # 0x95cfd
movq %rax, %rdi
callq 0x11340
movl 0x7fe1e(%rip), %esi     # 0x107278
movq %rax, %rdi
callq 0x11540
leaq 0x236d4(%rip), %rsi     # 0xaab3d
movq %rax, %rdi
callq 0x11340
movl 0x7febd(%rip), %esi     # 0x107334
leal 0x1(%rsi), %ecx
movl %ecx, 0x7feb4(%rip)     # 0x107334
movq %rax, %rdi
callq 0x11540
leaq 0x1c8(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x112a0
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
andq $0x0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
andq $0x0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
andq $0x0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x160(%rsp)
movaps %xmm0, 0x150(%rsp)
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movl $0x0, 0x4(%rsp)
testb $0x1, %al
je 0x87755
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x10(%rax), %r13
movq 0x18(%rax), %rax
movq %rax, 0x120(%rsp)
leaq 0x60(%rsp), %rbp
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
cmpq 0x120(%rsp), %r13
je 0x87743
movq (%r13), %r14
movq 0xd0(%rbx), %rdi
leaq 0x40(%r14), %r12
movq %r12, %rsi
leaq 0x40(%rsp), %rdx
callq 0x84d7c
movl %eax, (%rsp)
movq %rbp, %rdi
leaq 0x2221d(%rip), %rsi     # 0xa97b6
leaq 0x128(%rsp), %rdx
callq 0x664f4
cmpq $0x0, 0x48(%rsp)
je 0x87686
movq %r13, 0x30(%rsp)
pushq $-0x1
popq %rbp
pushq $-0x20
popq %r13
movq 0x7fc73(%rip), %rcx     # 0x107238
movq 0x7fc64(%rip), %rax     # 0x107230
subq %rax, %rcx
sarq $0x5, %rcx
incq %rbp
cmpq %rbp, %rcx
jbe 0x87659
leaq (%rax,%r13), %rdi
addq $0x20, %rdi
addq $0x20, %r13
movq %r12, %rsi
callq 0x51ab0
testb %al, %al
je 0x875be
movq 0xd0(%rbx), %rdi
movq %r12, %rsi
callq 0x8531b
movq %rax, %rbp
movl (%rax), %eax
movl %eax, (%rsp)
cmpl $-0x1, %eax
jne 0x87634
movq %rbx, %rdi
callq 0x85044
movq 0xe8(%rbx), %rdi
movl %eax, (%rsp)
movl %eax, %esi
pushq $0x1
popq %rdx
movq %r12, %rcx
callq 0x78e68
movl (%rsp), %eax
movl %eax, (%rbp)
addq 0x7fc0d(%rip), %r13     # 0x107248
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x2de0e
leaq 0x40(%rsp), %rdi
leaq 0x22162(%rip), %rsi     # 0xa97b6
callq 0x664c4
cmpq $0x0, 0x48(%rsp)
je 0x876b5
movq 0x7e988(%rip), %rdi     # 0x105ff0
leaq 0x40(%rsp), %rsi
callq 0x11320
movq 0x30(%rsp), %r13
leaq 0x60(%rsp), %rbp
movq %rax, %rdi
callq 0x111b0
jmp 0x876bf
movq 0xd0(%rbx), %rsi
leaq 0x128(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0x84e78
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2dc3c
movq %r15, %rdi
callq 0x209be
jmp 0x876bf
movq 0x30(%rsp), %r13
leaq 0x60(%rsp), %rbp
leaq 0x128(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x2b71e
movl (%rsp), %eax
movl %eax, 0x148(%rsp)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x8a102
movq %r15, %rdi
callq 0x209be
addq $0x8, %r14
leaq 0x100(%rsp), %rdi
movq %r14, %rsi
callq 0x88a7e
movq 0x18(%rsp), %rsi
addq $-0x8, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x88a7e
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
callq 0x79a38
movq %rbp, %rdi
callq 0x209be
addq $0x8, %r13
jmp 0x87562
xorl %ebp, %ebp
jmp 0x87c96
leaq 0x40(%rsp), %rdi
callq 0x209be
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
testb $0x2, %al
je 0x877bc
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x4(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %r12
movq 0x18(%rax), %r13
leaq 0x80(%rsp), %r14
leaq 0xc0(%rsp), %r15
cmpq %r13, %r12
je 0x877b8
movq (%r12), %rbp
movq 0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x40, %rsi
movq %r14, %rdi
callq 0x79a38
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x40, %rsi
movq %r15, %rdi
callq 0x79a38
addq $0x8, %r12
jmp 0x87782
incl 0x4(%rsp)
movq 0xe8(%rbx), %rsi
leaq 0x128(%rsp), %rdi
callq 0x790b0
movq 0xe8(%rbx), %rdi
callq 0x7932e
movl %eax, 0x3c(%rsp)
movq 0xe8(%rbx), %rdi
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x190(%rsp), %rsi
callq 0x787c8
leaq 0x40(%rsp), %rdi
callq 0x2b668
xorl %r15d, %r15d
leaq 0x150(%rsp), %r14
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
cmpq %r13, %rax
jbe 0x87876
movq 0xe8(%rbx), %rdi
movq 0xa0(%rsp), %rsi
addq %r12, %rsi
addq %r15, %rcx
movq %rcx, %rdx
callq 0x78886
movq 0xa0(%rsp), %rsi
addq %r12, %rsi
movq %r14, %rdi
callq 0x79a38
incq %r13
addq $0x20, %r12
addq $0x28, %r15
jmp 0x8781f
movq %rbx, %rdi
callq 0x84f42
movl 0xe0(%rbx), %ebp
movq 0xe8(%rbx), %r14
leaq 0xe542(%rip), %rsi      # 0x95dd4
leaq 0x60(%rsp), %rdi
leaq 0x170(%rsp), %rdx
callq 0x664f4
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x4(%rsp), %r13d
movq (%rax,%r13,8), %rcx
addq $0x40, %rcx
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0xc0(%rsp), %r8
movq %r14, %rsi
callq 0x78912
leaq 0x60(%rsp), %rdi
callq 0x209be
movq 0xe8(%rbx), %rsi
leaq 0x60(%rsp), %rdi
callq 0x79332
movq 0xe8(%rbx), %rdi
movl $0x2, 0xe0(%rbx)
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x78e38
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x88(%rsp), %rax
subq 0x80(%rsp), %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0x879ad
movl 0xe0(%rbx), %r14d
leal 0x1(%r14), %eax
movl %eax, 0xe0(%rbx)
movq 0xe8(%rbx), %rdi
leal 0x1(%r12), %edx
movl %r14d, %esi
callq 0x78e38
movq 0xd0(%rbx), %rdi
addq $0x28, %rdi
movq 0x80(%rsp), %rsi
addq %r15, %rsi
callq 0x7a76e
movl %r14d, (%rax)
movq 0xc0(%rsp), %r14
movq 0xd0(%rbx), %rdi
addq $0x60, %rdi
movq 0x80(%rsp), %rsi
addq %r15, %rsi
callq 0x89230
addq %r15, %r14
addq $0x20, %r15
incq %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x2de0e
jmp 0x87910
movq %r13, 0x30(%rsp)
movl %ebp, (%rsp)
xorl %r12d, %r12d
pushq $0x1
popq %rbp
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
cmpq %r13, %rax
jbe 0x87a59
movl 0xe0(%rbx), %r14d
leal 0x1(%r14), %eax
movl %eax, 0xe0(%rbx)
movq 0xe8(%rbx), %rdi
addq %r15, %rcx
movl %r14d, %esi
movl %ebp, %edx
callq 0x78e68
movq 0xd0(%rbx), %rdi
addq $0x28, %rdi
movq 0x10(%rsp), %rsi
addq %r15, %rsi
callq 0x7a76e
movl %r14d, (%rax)
movq 0xa0(%rsp), %r14
movq 0xd0(%rbx), %rdi
addq $0x60, %rdi
movq 0x10(%rsp), %rsi
addq %r15, %rsi
callq 0x89230
addq %r12, %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x2de0e
incq %r13
addq $0x28, %r15
addq $0x20, %r12
jmp 0x879c1
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *(%rax)
movl (%rsp), %ebp
movq 0xe8(%rbx), %rdi
callq 0x7932e
leaq 0x40(%rsp), %rdi
movl %eax, %esi
callq 0x83e66
movl 0xe0(%rbx), %esi
leaq 0x60(%rsp), %rdi
callq 0x83e66
movl %ebp, 0xe0(%rbx)
movq 0xd0(%rbx), %rax
movq (%rax), %rax
movq %rax, 0xd0(%rbx)
leaq 0x128(%rbx), %rdi
leaq 0x3c(%rsp), %rsi
callq 0x88a7e
movq 0xe8(%rbx), %rsi
leaq 0x170(%rsp), %rdi
callq 0x790b0
leaq 0x140(%rbx), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8a3c8
leaq 0x170(%rsp), %rdi
callq 0x21f04
movq 0xe8(%rbx), %rdi
callq 0x7932e
leaq 0x128(%rsp), %rdi
movl %eax, %esi
callq 0x83e66
movq %rbx, %rdi
callq 0x85044
movl %eax, %ebp
movq 0xe8(%rbx), %rdi
leaq 0x190(%rsp), %rsi
leaq 0xe0(%rsp), %rcx
movl %eax, %edx
callq 0x78c3c
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
cmpq %r12, %rax
jbe 0x87c03
movl 0xe0(%rbx), %r15d
leal 0x1(%r15), %eax
movl %eax, 0xe0(%rbx)
movq 0xe8(%rbx), %rdi
addq %r14, %rcx
movl %r15d, %esi
movl %ebp, %edx
callq 0x78e68
movq 0x100(%rsp), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x87bb5
movq 0xe8(%rbx), %rdi
movq 0x10(%rsp), %rax
movl 0x20(%rax,%r14), %edx
movl %r15d, %esi
callq 0x78dd8
jmp 0x87bf3
movq 0xa0(%rsp), %rdi
addq %r13, %rdi
leaq 0x22f5e(%rip), %rsi     # 0xaab25
callq 0x21c5b
movq 0xe8(%rbx), %rdi
movq 0x10(%rsp), %rcx
movl 0x20(%rcx,%r14), %edx
testb %al, %al
je 0x87beb
movl %r15d, %esi
callq 0x78e08
jmp 0x87bf3
movl %r15d, %esi
callq 0x78da8
incq %r12
addq $0x28, %r14
addq $0x20, %r13
jmp 0x87b48
leaq 0x60(%rsp), %rdi
callq 0x21f04
leaq 0x40(%rsp), %rdi
callq 0x21f04
leaq 0x128(%rsp), %rdi
callq 0x21f04
leaq 0x150(%rsp), %rdi
callq 0x2b668
leaq 0x80(%rsp), %rdi
callq 0x2b668
leaq 0xc0(%rsp), %rdi
callq 0x2b668
leaq 0xe0(%rsp), %rdi
callq 0x89956
leaq 0xa0(%rsp), %rdi
callq 0x2b668
leaq 0x100(%rsp), %rdi
callq 0x89956
leaq 0x10(%rsp), %rdi
callq 0x88a9c
leaq 0x190(%rsp), %rdi
callq 0x209be
leaq 0x1b0(%rsp), %rdi
callq 0x112c0
movl %ebp, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x87d44
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x21f04
jmp 0x87d47
jmp 0x87d44
movq %rax, %rbx
jmp 0x87d51
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x209be
jmp 0x87d5b
jmp 0x87d3d
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2b668
jmp 0x87d5b
jmp 0x87d1d
jmp 0x87cf4
jmp 0x87d3d
movq %rax, %rbx
jmp 0x87dcd
jmp 0x87d22
jmp 0x87d44
jmp 0x87d22
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x209be
jmp 0x87d25
jmp 0x87d16
movq %rax, %rbx
jmp 0x87d2f
jmp 0x87d22
movq %rax, %rbx
jmp 0x87d68
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x209be
leaq 0x40(%rsp), %rdi
callq 0x209be
jmp 0x87d68
jmp 0x87d44
movq %rax, %rbx
jmp 0x87d5b
jmp 0x87d44
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x21f04
leaq 0x40(%rsp), %rdi
callq 0x21f04
leaq 0x128(%rsp), %rdi
callq 0x21f04
leaq 0x150(%rsp), %rdi
callq 0x2b668
leaq 0x80(%rsp), %rdi
callq 0x2b668
leaq 0xc0(%rsp), %rdi
callq 0x2b668
leaq 0xe0(%rsp), %rdi
callq 0x89956
leaq 0xa0(%rsp), %rdi
callq 0x2b668
leaq 0x100(%rsp), %rdi
callq 0x89956
leaq 0x10(%rsp), %rdi
callq 0x88a9c
leaq 0x190(%rsp), %rdi
callq 0x209be
leaq 0x1b0(%rsp), %rdi
callq 0x112c0
movq %rbx, %rdi
callq 0x11570