// File: /workspace/github_c_makefile_star2_O0/Encryptr[P]O-plus-plus/opp/ir/ir.c
// Function: init_oppir
struct OppIr* init_oppir()
{
	struct OppIr* ir = (struct OppIr*)malloc(sizeof(struct OppIr));

	if (ir == NULL)
		goto err;

	// Bytecode
	ir->code.bytes = (unsigned char*)malloc(INIT_BYTECODE_SIZE);

	if (ir->code.bytes == NULL)
		goto err;

	ir->code.idx = 0;
	ir->code.allocated = INIT_BYTECODE_SIZE;

	// Local Stack
	ir->local_stack.size = 0;
	ir->local_stack.pos = 0;
	ir->local_stack.frame_ptr = 0;

	// Offset Tables 
	ir->offsets.offset_table = (int32_t*)malloc(sizeof(int32_t)*DEFAULT_OFFSET_TABLE);
	ir->offsets.jmp_table = (struct Jmp_Item*)malloc(sizeof(struct Jmp_Item)*DEFAULT_OFFSET_TABLE);

	if (ir->offsets.offset_table == NULL || ir->offsets.jmp_table == NULL)
		goto err;

	ir->offsets.allocated = DEFAULT_OFFSET_TABLE;
	ir->offsets.jmp_idx = 0;
	memset(ir->offsets.offset_table, 0, sizeof(int32_t)*DEFAULT_OFFSET_TABLE);
	memset(ir->offsets.jmp_table, 0, sizeof(struct Jmp_Item)*DEFAULT_OFFSET_TABLE);

	// Register Allocation
	ir->regalloc.amount = 0;
	ir->regalloc.allocated = DEFAULT_SPILL;
	ir->regalloc.spills = (struct Spill*)
		malloc(sizeof(struct Spill)*DEFAULT_SPILL);
	memset(ir->regalloc.spills, 0, sizeof(struct Spill)*DEFAULT_SPILL);

	if (ir->regalloc.spills == NULL)
		goto err;

	// Reg Stack
	ir->reg_stack.stack = (struct Register*)
		malloc(sizeof(struct Register)*DEFAULT_REG_STACK);
	memset(ir->reg_stack.stack, 0, sizeof(struct Register)*DEFAULT_REG_STACK);

	if (ir->reg_stack.stack == NULL)
		goto err;

	ir->reg_stack.top = ir->reg_stack.stack;
	ir->reg_stack.allocated = DEFAULT_REG_STACK;
	ir->instr = NULL;

	// Data
	ir->data_seg.data = (unsigned char*)
		malloc(INIT_BYTECODE_SIZE);

	if (ir->data_seg.data == NULL)
		goto err;

	ir->data_seg.allocated = INIT_BYTECODE_SIZE;
	ir->data_seg.idx = 0;

	memset(ir->data_seg.data, 0, INIT_BYTECODE_SIZE);

	// End
	return ir;

	err:
		INTERNAL_ERROR("Malloc Fail");
		return NULL;
}

// Assembly:
subq $0x18, %rsp
movl $0x98, %edi
callq 0x1160
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x9100
jmp 0x931c
movl $0x40, %edi
callq 0x1160
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x9125
jmp 0x931c
movq 0x8(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x8(%rsp), %rax
movq $0x40, 0x10(%rax)
movq 0x8(%rsp), %rax
movl $0x0, 0x48(%rax)
movq 0x8(%rsp), %rax
movl $0x0, 0x4c(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x50(%rax)
movl $0x80, %edi
callq 0x1160
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x70(%rax)
movl $0x200, %edi            # imm = 0x200
callq 0x1160
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x78(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x70(%rax)
je 0x91a8
movq 0x8(%rsp), %rax
cmpq $0x0, 0x78(%rax)
jne 0x91ad
jmp 0x931c
movq 0x8(%rsp), %rax
movq $0x20, 0x60(%rax)
movq 0x8(%rsp), %rax
movl $0x0, 0x68(%rax)
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x10f0
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x10f0
movq 0x8(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x8(%rsp), %rax
movq $0x8, 0x20(%rax)
movl $0x40, %edi
callq 0x1160
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10f0
movq 0x8(%rsp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x9246
jmp 0x931c
movl $0x100, %edi            # imm = 0x100
callq 0x1160
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10f0
movq 0x8(%rsp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x9282
jmp 0x931c
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x8(%rsp), %rax
movq $0x10, 0x30(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x58(%rax)
movl $0x40, %edi
callq 0x1160
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x90(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x92d8
jmp 0x931c
movq 0x8(%rsp), %rax
movq $0x40, 0x80(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x88(%rax)
movq 0x8(%rsp), %rax
movq 0x90(%rax), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10f0
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x9338
leaq 0xa2e5(%rip), %rdi      # 0x13608
leaq 0xb0ce(%rip), %rsi      # 0x143f8
callq 0x114a0
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)