// File: AgathokakologicalBit[P]wit/src/annotation/context_generation.cpp
// Function: akbit::system::annotation::(anonymous namespace)::cg_visit_binary_operation(std::shared_ptr<akbit::system::Node>, akbit::system::Node::binary_operation_t&, std::shared_ptr<akbit::system::Context>, bool)
void cg_visit_binary_operation(std::shared_ptr<Node> node, Node::binary_operation_t &val, std::shared_ptr<Context> ctx, bool reg_vars)
    {
      bool is_first = true;
      auto common_type = Node::etype_t::unknown;

      for (auto operand : val.operands)
      {
        cg_visit(operand, ctx, reg_vars && (val.operation != find_operator(":") || is_first));
        if (is_first) common_type = operand->result_type;
        else
        {
          auto rt = operand->result_type;
          if (common_type != rt && rt != Node::etype_t::unknown && rt != Node::etype_t::any)
          {
            // TODO: Report error
            std::cerr << "Binary operation type mismatch:\n  Expected <" << (int)common_type << ">, but <" << (int)rt << "> was given.\n";
            common_type = Node::etype_t::any;
          }
        }
        
        is_first = false;
      }

      node->result_type = common_type;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdx, -0xb8(%rbp)
movq %rdi, -0xb0(%rbp)
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movb $0x1, -0x1a(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x18160
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x17fa0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x22a70
testb $0x1, %al
jne 0x2b973
jmp 0x2bc3d
leaq -0x30(%rbp), %rdi
callq 0x184a0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x9b20
leaq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x9b20
movq -0xb8(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xa380
movb -0x19(%rbp), %cl
movb $0x0, -0x8a(%rbp)
movb $0x0, -0x9d(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xb9(%rbp)
je 0x2ba57
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x4570
movq -0xc8(%rbp), %rdx
movb $0x1, -0x8a(%rbp)
leaq 0xa860(%rip), %rsi      # 0x3625d
leaq -0x88(%rbp), %rdi
callq 0x9e70
jmp 0x2ba0b
movb $0x1, -0x9d(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xfbf0
movq %rax, -0xd8(%rbp)
jmp 0x2ba27
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0xd9(%rbp)
jne 0x2ba4b
movb -0x1a(%rbp), %al
movb %al, -0xd9(%rbp)
movb -0xd9(%rbp), %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %al
movzbl %al, %edx
andl $0x1, %edx
leaq -0x58(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2a060
jmp 0x2ba72
testb $0x1, -0x9d(%rbp)
jne 0x2ba7d
jmp 0x2ba89
leaq -0x88(%rbp), %rdi
callq 0x4210
testb $0x1, -0x8a(%rbp)
jne 0x2ba94
jmp 0x2baa0
leaq -0x89(%rbp), %rdi
callq 0x4370
leaq -0x68(%rbp), %rdi
callq 0xabf0
leaq -0x58(%rbp), %rdi
callq 0x9b50
testb $0x1, -0x1a(%rbp)
je 0x2bb3d
leaq -0x48(%rbp), %rdi
callq 0x9b90
movl 0x50(%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x2bc17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x2bb0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
testb $0x1, -0x9d(%rbp)
jne 0x2bb01
jmp 0x2bb0d
leaq -0x88(%rbp), %rdi
callq 0x4210
jmp 0x2bb0f
testb $0x1, -0x8a(%rbp)
jne 0x2bb1a
jmp 0x2bb26
leaq -0x89(%rbp), %rdi
callq 0x4370
leaq -0x68(%rbp), %rdi
callq 0xabf0
leaq -0x58(%rbp), %rdi
callq 0x9b50
jmp 0x2bc32
leaq -0x48(%rbp), %rdi
callq 0x9b90
movl 0x50(%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xa4(%rbp), %eax
je 0x2bc15
cmpl $0x0, -0xa4(%rbp)
je 0x2bc15
cmpl $0x7, -0xa4(%rbp)
je 0x2bc15
movq 0x29471(%rip), %rdi     # 0x54ff0
leaq 0xaf13(%rip), %rsi      # 0x36a99
callq 0x42e0
movq %rax, -0xe8(%rbp)
jmp 0x2bb94
movq -0xe8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x4540
movq %rax, -0xf0(%rbp)
jmp 0x2bbac
movq -0xf0(%rbp), %rdi
leaq 0xaf0c(%rip), %rsi      # 0x36ac6
callq 0x42e0
movq %rax, -0xf8(%rbp)
jmp 0x2bbc8
movq -0xf8(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x4540
movq %rax, -0x100(%rbp)
jmp 0x2bbe3
movq -0x100(%rbp), %rdi
leaq 0xaede(%rip), %rsi      # 0x36acf
callq 0x42e0
jmp 0x2bbf8
movl $0x7, -0x20(%rbp)
jmp 0x2bc15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x2bc32
jmp 0x2bc17
movb $0x0, -0x1a(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x9b50
leaq -0x30(%rbp), %rdi
callq 0x22ab0
jmp 0x2b95d
leaq -0x48(%rbp), %rdi
callq 0x9b50
jmp 0x2bc64
movq -0xb0(%rbp), %rdi
movl -0x20(%rbp), %eax
movl %eax, -0x104(%rbp)
callq 0x9b90
movl -0x104(%rbp), %ecx
movl %ecx, 0x50(%rax)
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x4560