// File: /workspace/github_cpp_makefile_star2_O1/kram[P]kram/./src/parser/parser.cpp
// Function: Parser::assign_with_type(Instruction*)
Instruction* Parser::assign_with_type(Instruction* prev) {
	Instruction* ins = new Instruction(Ins::ASSIGN);

	if (prev->instruction != Ins::NAME) {
		std::cout << ": expects previous instruction to be of type NAME";
		exit(0);
	}

	// Get name from previous OP
	ins->name = prev->name;

	// Read the rest of the row
	std::vector<Instruction*> row = this->read_until_eol();

	// Expect exactly one name
	if (row.size() != 1 || row[0]->instruction != Ins::NAME) {
		std::cout << ": needs to be followed by exactly one NAME (aka the type)";
		exit(0);
	}

	std::string type = row[0]->name;

	if (type == "Number") {
		ins->right.push_back(this->number_init());
	} else if (type == "String") {
		ins->right.push_back(this->string_init());
	} else if (type == "Bool") {
		ins->right.push_back(this->boolean_init());
	} else {
		std::cout << "Does not know how to init type " << type << " after :";
		exit(0);
	}

	return ins;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rsi, %r15
movq %rdi, %r14
movl $0x80, %edi
callq 0x3260
movq %rax, %rbx
movl $0x0, (%rax)
addq $0x18, %rax
movq %rax, 0x8(%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
movb $0x0, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rbx)
movups %xmm0, 0x48(%rbx)
movups %xmm0, 0x58(%rbx)
movups %xmm0, 0x68(%rbx)
movq %rax, 0x78(%rbx)
movl $0x2, 0x30(%rbx)
cmpl $0x3, (%r15)
jne 0xef94
leaq 0x8(%rbx), %rdi
addq $0x8, %r15
movq %r15, %rsi
callq 0x3150
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xdf08
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0xef7f
movq (%rax), %rcx
cmpl $0x3, (%rcx)
jne 0xef7f
movq (%rax), %rax
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x473c
leaq 0x48a1(%rip), %rsi      # 0x13745
leaq 0x8(%rsp), %rdi
callq 0x30a0
testl %eax, %eax
je 0xef04
leaq 0x4893(%rip), %rsi      # 0x1374c
leaq 0x8(%rsp), %rdi
callq 0x30a0
testl %eax, %eax
je 0xef28
leaq 0x53c8(%rip), %rsi      # 0x14296
leaq 0x8(%rsp), %rdi
callq 0x30a0
testl %eax, %eax
jne 0xefae
callq 0x112b4
movq %rax, (%rsp)
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
jne 0xef3b
movq %rbx, %rdi
addq $0x50, %rdi
movq %rsp, %rdx
callq 0x120f8
jmp 0xef43
callq 0xfa70
movq %rax, (%rsp)
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
jne 0xef3b
movq %rbx, %rdi
addq $0x50, %rdi
movq %rsp, %rdx
callq 0x120f8
jmp 0xef43
callq 0x111ee
movq %rax, (%rsp)
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
je 0xef6e
movq %rax, (%rsi)
addq $0x8, 0x58(%rbx)
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xef52
callq 0x3230
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0xef61
callq 0x3230
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rbx, %rdi
addq $0x50, %rdi
movq %rsp, %rdx
callq 0x120f8
jmp 0xef43
movq 0xd04a(%rip), %rdi      # 0x1bfd0
leaq 0x52cf(%rip), %rsi      # 0x1425c
callq 0x3250
jmp 0xefa7
movq 0xd035(%rip), %rdi      # 0x1bfd0
leaq 0x5288(%rip), %rsi      # 0x1422a
callq 0x3250
xorl %edi, %edi
callq 0x32c0
movq 0xd01b(%rip), %rdi      # 0x1bfd0
leaq 0x52df(%rip), %rsi      # 0x1429b
movl $0x1f, %edx
callq 0x32a0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xcff9(%rip), %rdi      # 0x1bfd0
callq 0x32a0
leaq 0x52d8(%rip), %rsi      # 0x142bb
movq %rax, %rdi
callq 0x3250
jmp 0xefa7
jmp 0xeff3
jmp 0xeff3
jmp 0xeff3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xf00c
callq 0x3230
jmp 0xf00c
jmp 0xf009
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0xf01b
callq 0x3230
movq %rbx, %rdi
callq 0x33c0
nop