// File: johan-bjareholt[P]lua-compiler/src/ir.cc
// Function: namePass(Expression*, std::map<Expression*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<Expression*>, std::allocator<std::pair<Expression* const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&)
void namePass(Expression *tree, map<Expression*,string> &nameMap)
{
    std::string name;
    // Exp is funccall
    if (tree->kind == 'f'){
        for (Expression* exp : tree->subexp){
	        namePass(exp, nameMap);
        }
        name = newName();
    }
    // Exp is binop
    else if (tree->left != nullptr && tree->right != nullptr){
	    namePass(tree->left, nameMap);
	    namePass(tree->right, nameMap);
	    name = newName();
    }
    else {
        // Exp is string
        if (tree->name == "")
            name = to_string(tree->value);
        // Exp is var
	    else
            name = tree->name;
    }
  
    auto entry = std::pair<Expression*, string>(tree, name);
    nameMap.insert(entry);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x33a0
movq -0x8(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x66, %eax
jne 0x83b9
movq -0x8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xa040
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0xa070
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xa0a0
testb $0x1, %al
jne 0x8356
jmp 0x8393
leaq -0x40(%rbp), %rdi
callq 0xa0d0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x82f0
jmp 0x8375
jmp 0x8377
leaq -0x40(%rbp), %rdi
callq 0xa100
jmp 0x8343
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x8518
leaq -0x80(%rbp), %rdi
callq 0x8150
jmp 0x839e
leaq -0x30(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3340
leaq -0x80(%rbp), %rdi
callq 0x3528
jmp 0x8493
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x841f
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x841f
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x82f0
jmp 0x83e0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x82f0
jmp 0x83f3
leaq -0xa0(%rbp), %rdi
callq 0x8150
jmp 0x8401
leaq -0x30(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3340
leaq -0xa0(%rbp), %rdi
callq 0x3528
jmp 0x8491
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
leaq 0x230ec(%rip), %rsi     # 0x2b51a
callq 0xa770
movb %al, -0xf9(%rbp)
jmp 0x843b
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x8447
jmp 0x847a
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %esi
leaq -0xc0(%rbp), %rdi
callq 0xa7a0
jmp 0x845c
leaq -0x30(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3340
leaq -0xc0(%rbp), %rdi
callq 0x3528
jmp 0x848f
movq -0x8(%rbp), %rsi
addq $0x30, %rsi
leaq -0x30(%rbp), %rdi
callq 0x3040
jmp 0x848d
jmp 0x848f
jmp 0x8491
jmp 0x8493
leaq -0xe8(%rbp), %rdi
leaq -0x8(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0xa8c0
jmp 0x84a9
movq -0x10(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xa900
movb %dl, -0x109(%rbp)
movq %rax, -0x108(%rbp)
jmp 0x84c8
movb -0x109(%rbp), %al
movq -0x108(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movb %al, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xa940
leaq -0x30(%rbp), %rdi
callq 0x3528
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xa940
leaq -0x30(%rbp), %rdi
callq 0x3528
movq -0x58(%rbp), %rdi
callq 0x34b0
nopw (%rax,%rax)