// File: AgathokakologicalBit[P]wit/src/annotation/context_generation.cpp
// Function: akbit::system::annotation::(anonymous namespace)::cg_visit_declaration(std::shared_ptr<akbit::system::Node>, akbit::system::Node::declaration_t&, std::shared_ptr<akbit::system::Context>, bool)
void cg_visit_declaration(std::shared_ptr<Node> node, Node::declaration_t &val, std::shared_ptr<Context> ctx, bool reg_vars)
    {
      // Assumes that the assignee is a signle variable
      // TODO: Enhance the code to support more assignment types
      // TODO: Make a normal type checking
      cg_visit(val.type, ctx, false);
      auto t = Node::etype_t::unknown;
      if (val.type && val.type->value.index() == 12)
      {
        auto type_info = std::get<Node::value_variable_t>(val.type->value);
        if (!type_info.record.lock())
        {
          if (type_info.name == "int") t = Node::etype_t::integer;
          else if (type_info.name == "float") t = Node::etype_t::decimal;
          else if (type_info.name == "string") t = Node::etype_t::string;
          else if (type_info.name == "function") t = Node::etype_t::function;
        }
      }

      auto record = ctx->add(ctx, std::get<Node::value_variable_t>(val.variable->value).name, t);
      node->result_type = t;
      std::get<Node::value_variable_t>(val.variable->value).record = record;

      if (!val.value) return;
      cg_visit(val.value, ctx, reg_vars);
      auto rt = t != Node::etype_t::unknown ? t : val.value->result_type;
      if (t != Node::etype_t::unknown && rt != t)
      {
        // TODO: Handle error properly
        std::cerr << "Mismatch between declared and assigned value types.\n";
      }

      record->type = rt;
      node->result_type = rt;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdx, -0xf8(%rbp)
movq %rdi, -0x100(%rbp)
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x9b20
movq -0xf8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0xa380
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
xorl %edx, %edx
callq 0x2a060
jmp 0x2ada2
leaq -0x40(%rbp), %rdi
callq 0xabf0
leaq -0x30(%rbp), %rdi
callq 0x9b50
movl $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x9b00
testb $0x1, %al
jne 0x2add1
jmp 0x2af5f
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x9b90
movq %rax, %rdi
addq $0x10, %rdi
callq 0x9e50
cmpq $0xc, %rax
jne 0x2af5f
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x9b90
movq %rax, %rdi
addq $0x10, %rdi
callq 0x2d0f0
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0xc020
leaq -0x80(%rbp), %rsi
addq $0x20, %rsi
leaq -0x90(%rbp), %rdi
callq 0xd8f0
leaq -0x90(%rbp), %rdi
callq 0xd920
xorb $-0x1, %al
movb %al, -0x101(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xd940
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x2ae5c
jmp 0x2af56
leaq 0xbbf7(%rip), %rsi      # 0x36a5a
leaq -0x80(%rbp), %rdi
callq 0x184c0
movb %al, -0x102(%rbp)
jmp 0x2ae74
movb -0x102(%rbp), %al
testb $0x1, %al
jne 0x2ae80
jmp 0x2aec9
movl $0x3, -0x50(%rbp)
jmp 0x2af54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xabf0
leaq -0x30(%rbp), %rdi
callq 0x9b50
jmp 0x2b1ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xc060
jmp 0x2b1ce
leaq 0xbb8e(%rip), %rsi      # 0x36a5e
leaq -0x80(%rbp), %rdi
callq 0x184c0
movb %al, -0x103(%rbp)
jmp 0x2aee1
movb -0x103(%rbp), %al
testb $0x1, %al
jne 0x2aeed
jmp 0x2aef6
movl $0x4, -0x50(%rbp)
jmp 0x2af52
leaq 0xb281(%rip), %rsi      # 0x3617e
leaq -0x80(%rbp), %rdi
callq 0x184c0
movb %al, -0x104(%rbp)
jmp 0x2af0e
movb -0x104(%rbp), %al
testb $0x1, %al
jne 0x2af1a
jmp 0x2af23
movl $0x1, -0x50(%rbp)
jmp 0x2af50
leaq 0xb26e(%rip), %rsi      # 0x36198
leaq -0x80(%rbp), %rdi
callq 0x184c0
movb %al, -0x105(%rbp)
jmp 0x2af3b
movb -0x105(%rbp), %al
testb $0x1, %al
jne 0x2af47
jmp 0x2af4e
movl $0x5, -0x50(%rbp)
jmp 0x2af50
jmp 0x2af52
jmp 0x2af54
jmp 0x2af56
leaq -0x80(%rbp), %rdi
callq 0xc060
movq -0xf8(%rbp), %rdi
callq 0xda20
movq -0xf8(%rbp), %rsi
movq %rax, -0x118(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa380
movq -0x10(%rbp), %rdi
callq 0x9b90
movq %rax, %rdi
addq $0x10, %rdi
callq 0x2d0f0
movq %rax, -0x110(%rbp)
jmp 0x2afa3
movq -0x110(%rbp), %rcx
movq -0x118(%rbp), %rsi
movl -0x50(%rbp), %r8d
leaq -0xa0(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x2d110
jmp 0x2afca
leaq -0xb0(%rbp), %rdi
callq 0xabf0
movq -0x100(%rbp), %rdi
movl -0x50(%rbp), %eax
movl %eax, -0x124(%rbp)
callq 0x9b90
movl -0x124(%rbp), %ecx
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rdi
callq 0x9b90
movq %rax, %rdi
addq $0x10, %rdi
callq 0x2d0f0
movq %rax, -0x120(%rbp)
jmp 0x2b012
movq -0x120(%rbp), %rdi
addq $0x20, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2d1f0
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x9b00
testb $0x1, %al
jne 0x2b077
movl $0x1, -0xb4(%rbp)
jmp 0x2b1ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xabf0
jmp 0x2b1ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2b1c2
movq -0x10(%rbp), %rsi
addq $0x20, %rsi
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x9b20
movq -0xf8(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0xa380
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
movzbl -0x19(%rbp), %edx
andl $0x1, %edx
callq 0x2a060
jmp 0x2b0c8
leaq -0xd8(%rbp), %rdi
callq 0xabf0
leaq -0xc8(%rbp), %rdi
callq 0x9b50
cmpl $0x0, -0x50(%rbp)
je 0x2b0f1
movl -0x50(%rbp), %eax
movl %eax, -0x13c(%rbp)
jmp 0x2b107
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x9b90
movl 0x50(%rax), %eax
movl %eax, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x2b161
movl -0xdc(%rbp), %eax
cmpl -0x50(%rbp), %eax
je 0x2b161
movq 0x29ec5(%rip), %rdi     # 0x54ff0
leaq 0xb932(%rip), %rsi      # 0x36a64
callq 0x42e0
jmp 0x2b139
jmp 0x2b161
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xabf0
leaq -0xc8(%rbp), %rdi
callq 0x9b50
jmp 0x2b1c2
movl -0xdc(%rbp), %eax
movl %eax, -0x144(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xd9d0
movl -0x144(%rbp), %ecx
movq -0x100(%rbp), %rdi
movl %ecx, 0x30(%rax)
movl -0xdc(%rbp), %eax
movl %eax, -0x140(%rbp)
callq 0x9b90
movl -0x140(%rbp), %ecx
movl %ecx, 0x50(%rax)
movl $0x0, -0xb4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xd940
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0xd940
movq -0x48(%rbp), %rdi
callq 0x4560
nopw (%rax,%rax)