// File: /workspace/github_cpp_makefile_star2_O2/baziotis[P]minijava-cpp/typecheck.cpp
// Function: DeclarationVisitor::visit(MethodDeclaration*)
Method *DeclarationVisitor::visit(MethodDeclaration *method_decl) {
    // Note: It's responsibility of the one who calls this visit
    // to have assured that a method with the same id does not exist.
    LOG_SCOPE;
    assert(!method_decl->is_undefined());
    print_indentation();
    debug_log(method_decl->loc, "MethodDeclaration: ", method_decl->id, "\n");
    Method *method = new Method(method_decl);
    assert(method);
    method->ret_type = this->typespec_to_type(method_decl->typespec, method_decl->ret->loc);
    for (LocalDeclaration *par : method_decl->params) {
        // We accept the param anyway. But in the case that there is
        // another param with the same name, we still insert this
        // (so that the rest of type-checking can sort of continue) but
        // we have to generate a (dummy) id for it.
        Param *param = par->accept(this);
        if (method->locals.find(par->id)) {
            typecheck_error(par->loc, "Parameter `", par->id, "` is already defined",
                            " in method `", method_decl->id, "`");
            param->id = gen_id();
        }
        method->locals.insert(param->id, param);
    }
    for (LocalDeclaration *var : method_decl->vars) {
        if (method->locals.find(var->id)) {
            typecheck_error(var->loc, "Variable `", var->id, "` is already defined",
                            " in method `", method_decl->id, "`");
        } else {
            Var *v = var->accept(this);
            method->locals.insert(v->id, v);
        }
    }
    return method;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
leaq 0xf(%rsp), %rdi
callq 0x3108
cmpq $0x0, 0x18(%rbx)
je 0x87c4
callq 0x312f
movl (%rbx), %edi
movq 0x18(%rbx), %rdx
leaq 0x8213(%rip), %rsi      # 0x10854
callq 0x8336
pushq $0x78
popq %rdi
callq 0xcbbc
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0xc6fc
movl 0x8(%rbx), %esi
movq 0x10(%rbx), %rdx
movq 0x68(%rbx), %rax
movl (%rax), %ecx
movq 0x18(%rsp), %rdi
callq 0x7d16
movq %rax, 0x8(%r12)
movq 0x28(%rbx), %r15
movq %rbx, 0x10(%rsp)
movq 0x30(%rbx), %r14
movq %r12, 0x20(%rsp)
addq $0x18, %r12
shlq $0x3, %r15
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x871d
movq (%r14,%rbx), %rbp
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x84a0
movq %rax, %r13
movq 0x18(%rbp), %rsi
movq %r12, %rdi
callq 0xda72
testq %rax, %rax
je 0x8702
movl (%rbp), %edi
movq 0x18(%rbp), %rdx
movq 0x10(%rsp), %rax
movq 0x18(%rax), %r9
leaq 0x7308(%rip), %rax      # 0xf9e1
movq %rax, (%rsp)
leaq 0x8184(%rip), %rsi      # 0x10868
leaq 0x8189(%rip), %rcx      # 0x10874
leaq 0x8197(%rip), %r8       # 0x10889
callq 0x8429
callq 0x85d0
movq %rax, (%r13)
jmp 0x8706
movq (%r13), %rax
movq %r12, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xcd72
addq $0x8, %rbx
jmp 0x8694
movq 0x10(%rsp), %rax
movq 0x40(%rax), %rbx
movq 0x48(%rax), %r14
shlq $0x3, %rbx
xorl %r13d, %r13d
leaq 0x8151(%rip), %rbp      # 0x10889
cmpq %r13, %rbx
je 0x87a6
movq (%r14,%r13), %r15
movq 0x18(%r15), %rsi
movq %r12, %rdi
callq 0xda72
testq %rax, %rax
je 0x8785
movl (%r15), %edi
movq 0x18(%r15), %rdx
movq 0x10(%rsp), %rax
movq 0x18(%rax), %r9
leaq 0x7278(%rip), %rax      # 0xf9e1
movq %rax, (%rsp)
leaq 0x8122(%rip), %rsi      # 0x10896
leaq 0x80f9(%rip), %rcx      # 0x10874
movq %rbp, %r8
callq 0x8429
jmp 0x87a0
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x84a0
movq (%rax), %rsi
movq %r12, %rdi
movq %rax, %rdx
callq 0xcd72
addq $0x8, %r13
jmp 0x8738
leaq 0xf(%rsp), %rdi
callq 0x311c
movq 0x20(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8035(%rip), %rdi      # 0x10800
leaq 0x7c1c(%rip), %rsi      # 0x103ee
leaq 0x8044(%rip), %rcx      # 0x1081d
movl $0x2ad, %edx            # imm = 0x2AD
callq 0x20b0
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r12, %rdi
callq 0x2100
jmp 0x87fe
jmp 0x87fb
jmp 0x87fb
jmp 0x87fb
jmp 0x87fb
movq %rax, %rbx
leaq 0xf(%rsp), %rdi
callq 0x311c
movq %rbx, %rdi
callq 0x21c0