// File: Mulan-Szechuan-Sauce[P]javelin/src/node.cpp
// Function: NAssignment::NAssignment(NIdentifier*, NExpression*)
NAssignment::
NAssignment(NIdentifier *lhs, NExpression *rhs) : lhs(lhs), rhs(rhs) {
  Type *type = rhs->get_type();
  Definition *def = scope->findDefinition(lhs->name);
  VariableDefinition *vdef = (VariableDefinition *)def;

  // FIXME accomodate conflicting function & class names

  if (def == NULL) {
    scope->addDefinition(lhs->name, new VariableDefinition(type));
  } else if (vdef->get_type()->isUnset()) {
    // For argument type implication
    lhs->set_type(type);
    vdef->set_type(type);
  // Already defined as a var
  } else if (type->cpp_type_string() != vdef->type->cpp_type_string()) {
    throw std::runtime_error(lhs->name +
                             " was previously declared as a '" +
                             vdef->type->cpp_type_string() + "'");
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0xbdd0
movq -0x168(%rbp), %rax
leaq 0xc803(%rip), %rcx      # 0x1ec08
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rax, %rcx
movq -0x168(%rbp), %rax
movq %rcx, -0x20(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x5100
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rax, -0x150(%rbp)
jmp 0x12474
leaq -0x48(%rbp), %rdi
callq 0x5190
movq -0x150(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x12558
movq -0x168(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
leaq -0x80(%rbp), %rdi
callq 0x5100
movl $0x18, %edi
callq 0x5220
movq %rax, -0x170(%rbp)
jmp 0x124d1
movq -0x170(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xef50
jmp 0x124e3
movq -0x170(%rbp), %rdx
movq -0x178(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xdf30
jmp 0x124fc
leaq -0x80(%rbp), %rdi
callq 0x5190
jmp 0x1276d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5190
jmp 0x12776
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1254a
movq -0x170(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x5200
leaq -0x80(%rbp), %rdi
callq 0x5190
jmp 0x12776
movq -0x60(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq %rax, %rdi
movq (%rdi), %rax
callq *0x10(%rax)
testb $0x1, %al
jne 0x12571
jmp 0x12592
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
jmp 0x1276b
movq -0x20(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0xa0(%rbp), %rdi
callq *%rax
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0xc0(%rbp), %rdi
callq *%rax
jmp 0x125be
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xcbe0
movb %al, -0x179(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5190
leaq -0xa0(%rbp), %rdi
callq 0x5190
movb -0x179(%rbp), %al
testb $0x1, %al
jne 0x125fe
jmp 0x12769
movb $0x1, -0x141(%rbp)
movl $0x10, %edi
callq 0x5130
movq %rax, -0x188(%rbp)
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
leaq 0x4770(%rip), %rdx      # 0x16d95
leaq -0x120(%rbp), %rdi
callq 0x13930
jmp 0x12633
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x140(%rbp), %rdi
callq *%rax
jmp 0x1264c
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x139b0
jmp 0x12668
leaq 0x440d(%rip), %rdx      # 0x16a7c
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xd590
jmp 0x12684
movq -0x188(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x5390
jmp 0x12699
movq -0x188(%rbp), %rdi
movb $0x0, -0x141(%rbp)
movq 0xc93a(%rip), %rsi      # 0x1efe8
movq 0xc903(%rip), %rdx      # 0x1efb8
callq 0x53d0
jmp 0x1277f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5190
jmp 0x12776
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12750
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12744
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12738
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1272c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x5190
leaq -0x100(%rbp), %rdi
callq 0x5190
leaq -0x140(%rbp), %rdi
callq 0x5190
leaq -0x120(%rbp), %rdi
callq 0x5190
testb $0x1, -0x141(%rbp)
jne 0x1275b
jmp 0x12767
movq -0x188(%rbp), %rdi
callq 0x51b0
jmp 0x12776
jmp 0x1276b
jmp 0x1276d
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x5400
nop