// File: /workspace/github_c_makefile_star2_O0/adamjedlicka[P]blu/src/vm/debug/debug.c
// Function: bluDisassembleInstruction
int32_t bluDisassembleInstruction(bluChunk* chunk, int32_t offset) {
	printf("%04d ", offset);
	if (offset > 0 && chunk->lines.data[offset] == chunk->lines.data[offset - 1]) {
		printf("   | ");
	} else {
		printf("%4d ", chunk->lines.data[offset]);
	}

	uint8_t instruction = chunk->code.data[offset];

	switch (instruction) {

	case OP_CONSTANT: return constantInstruction("OP_CONSTANT", chunk, offset);
	case OP_FALSE: return simpleInstruction("OP_FALSE", offset);
	case OP_NIL: return simpleInstruction("OP_NIL", offset);
	case OP_TRUE: return simpleInstruction("OP_TRUE", offset);
	case OP_ARRAY: return shortInstruction("OP_ARRAY", chunk, offset);

	case OP_POP: return simpleInstruction("OP_POP", offset);

	case OP_GET_LOCAL: return shortInstruction("OP_GET_LOCAL", chunk, offset);
	case OP_SET_LOCAL: return shortInstruction("OP_SET_LOCAL", chunk, offset);
	case OP_DEFINE_GLOBAL: return constantInstruction("OP_DEFINE_GLOBAL", chunk, offset);
	case OP_GET_GLOBAL: return constantInstruction("OP_GET_GLOBAL", chunk, offset);
	case OP_SET_GLOBAL: return constantInstruction("OP_SET_GLOBAL", chunk, offset);
	case OP_GET_UPVALUE: return shortInstruction("OP_GET_UPVALUE", chunk, offset);
	case OP_SET_UPVALUE: return shortInstruction("OP_SET_UPVALUE", chunk, offset);
	case OP_GET_PROPERTY: return shortInstruction("OP_GET_PROPERTY", chunk, offset);
	case OP_SET_PROPERTY: return shortInstruction("OP_SET_PROPERTY", chunk, offset);
	case OP_GET_SUPER: return shortInstruction("OP_GET_SUPER", chunk, offset);
	case OP_SUBSCRIPT_GET: return simpleInstruction("OP_SUBSCRIPT_GET", offset);
	case OP_SUBSCRIPT_SET: return simpleInstruction("OP_SUBSCRIPT_SET", offset);

	case OP_CALL: return byteInstruction("OP_CALL", chunk, offset);
	case OP_INVOKE: return invokeInstruction("OP_INVOKE", chunk, offset);
	case OP_SUPER: return invokeInstruction("OP_SUPER", chunk, offset);
	case OP_JUMP: return jumpInstruction("OP_JUMP", chunk, offset);
	case OP_JUMP_IF_FALSE: return jumpInstruction("OP_JUMP_IF_FALSE", chunk, offset);
	case OP_JUMP_IF_TRUE: return jumpInstruction("OP_JUMP_IF_TRUE", chunk, offset);
	case OP_LOOP: return loopInstruction("OP_LOOP", chunk, offset);

	case OP_EQUAL: return simpleInstruction("OP_EQUAL", offset);
	case OP_NOT_EQUAL: return simpleInstruction("OP_NOT_EQUAL", offset);
	case OP_GREATER: return simpleInstruction("OP_GREATER", offset);
	case OP_GREATER_EQUAL: return simpleInstruction("OP_GREATER_EQUAL", offset);
	case OP_LESS: return simpleInstruction("OP_LESS", offset);
	case OP_LESS_EQUAL: return simpleInstruction("OP_LESS_EQUAL", offset);
	case OP_ADD: return simpleInstruction("OP_ADD", offset);
	case OP_DIVIDE: return simpleInstruction("OP_DIVIDE", offset);
	case OP_REMINDER: return simpleInstruction("OP_REMINDER", offset);
	case OP_SUBTRACT: return simpleInstruction("OP_SUBTRACT", offset);
	case OP_MULTIPLY: return simpleInstruction("OP_MULTIPLY", offset);
	case OP_POWER: return simpleInstruction("OP_POWER", offset);
	case OP_NOT: return simpleInstruction("OP_NOT", offset);
	case OP_NEGATE: return simpleInstruction("OP_NEGATE", offset);

	case OP_CLOSE_OPVALUE: return simpleInstruction("OP_CLOSE_OPVALUE", offset);
	case OP_CLOSURE: {
		uint16_t slot = ((chunk->code.data[offset + 1] << 8) & 0xff) | (chunk->code.data[offset + 2] & 0xff);
		offset += 3;

		printf("%-16s %6d ", "OP_CLOSURE", slot);
		bluPrintValue(chunk->constants.data[slot]);
		printf("\n");

		bluObjFunction* function = AS_FUNCTION(chunk->constants.data[slot]);
		for (uint16_t i = 0; i < function->upvalueCount; i++) {
			bool isLocal = chunk->code.data[offset];
			uint16_t index = ((chunk->code.data[offset + 1] << 8) & 0xff) | (chunk->code.data[offset + 2] & 0xff);
			offset += 3;
			printf("%04d    | %s %d\n", offset - 2, isLocal ? "local" : "upvalue", index);
		}

		return offset;
	}

	case OP_CLASS: return shortInstruction("OP_CLASS", chunk, offset);
	case OP_INHERIT: return simpleInstruction("OP_INHERIT", offset);
	case OP_METHOD: return shortInstruction("OP_METHOD", chunk, offset);
	case OP_METHOD_FOREIGN: return shortInstruction("OP_METHOD_FOREIGN", chunk, offset);
	case OP_METHOD_STATIC: return shortInstruction("OP_METHOD_STATIC", chunk, offset);

	case OP_IMPORT: return constantInstruction("OP_IMPORT", chunk, offset);

	case OP_ECHO: return simpleInstruction("OP_ECHO", offset);
	case OP_RETURN: return simpleInstruction("OP_RETURN", offset);

	case OP_ASSERT: return simpleInstruction("OP_ASSERT", offset);

	default: printf("Unknown opcode %d\n", instruction); return offset + 1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl -0x14(%rbp), %esi
leaq 0x9873(%rip), %rdi      # 0xe77c
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x14(%rbp)
jle 0x4f4b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x14(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x4f4b
leaq 0x9840(%rip), %rdi      # 0xe782
movb $0x0, %al
callq 0x10d0
jmp 0x4f68
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x9827(%rip), %rdi      # 0xe788
movb $0x0, %al
callq 0x10d0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x15(%rbp)
movzbl -0x15(%rbp), %eax
movq %rax, -0x30(%rbp)
subq $0x31, %rax
ja 0x55c4
movq -0x30(%rbp), %rax
leaq 0x971d(%rip), %rcx      # 0xe6b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x97df(%rip), %rdi      # 0xe78d
callq 0x55f0
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x97d4(%rip), %rdi      # 0xe799
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x97c6(%rip), %rdi      # 0xe7a2
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x97b6(%rip), %rdi      # 0xe7a9
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x97a3(%rip), %rdi      # 0xe7b1
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9795(%rip), %rdi      # 0xe7ba
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9781(%rip), %rdi      # 0xe7c1
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9773(%rip), %rdi      # 0xe7ce
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9765(%rip), %rdi      # 0xe7db
callq 0x55f0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x975b(%rip), %rdi      # 0xe7ec
callq 0x55f0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x974e(%rip), %rdi      # 0xe7fa
callq 0x55f0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9741(%rip), %rdi      # 0xe808
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9735(%rip), %rdi      # 0xe817
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9729(%rip), %rdi      # 0xe826
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x971e(%rip), %rdi      # 0xe836
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9713(%rip), %rdi      # 0xe846
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9709(%rip), %rdi      # 0xe853
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9703(%rip), %rdi      # 0xe864
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x96f9(%rip), %rdi      # 0xe875
callq 0x5740
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x96e6(%rip), %rdi      # 0xe87d
callq 0x5790
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x96d5(%rip), %rdi      # 0xe887
callq 0x5790
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x96c3(%rip), %rdi      # 0xe890
callq 0x5820
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x96b0(%rip), %rdi      # 0xe898
callq 0x5820
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x96a6(%rip), %rdi      # 0xe8a9
callq 0x5820
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x969b(%rip), %rdi      # 0xe8b9
callq 0x58a0
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x968c(%rip), %rdi      # 0xe8c1
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x967e(%rip), %rdi      # 0xe8ca
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9674(%rip), %rdi      # 0xe8d7
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9668(%rip), %rdi      # 0xe8e2
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9662(%rip), %rdi      # 0xe8f3
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9653(%rip), %rdi      # 0xe8fb
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x964a(%rip), %rdi      # 0xe909
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x963a(%rip), %rdi      # 0xe910
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x962d(%rip), %rdi      # 0xe91a
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9622(%rip), %rdi      # 0xe926
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9617(%rip), %rdi      # 0xe932
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x960c(%rip), %rdi      # 0xe93e
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x95fe(%rip), %rdi      # 0xe947
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x95ee(%rip), %rdi      # 0xe94e
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x95e1(%rip), %rdi      # 0xe958
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
andl $0xff, %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
andl $0xff, %ecx
orl %ecx, %eax
movw %ax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x14(%rbp)
movzwl -0x18(%rbp), %edx
leaq 0x9593(%rip), %rdi      # 0xe969
leaq 0x9597(%rip), %rsi      # 0xe974
movb $0x0, %al
callq 0x10d0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movzwl -0x18(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %edi
movq 0x8(%rax), %rsi
callq 0x94a0
leaq 0x8c20(%rip), %rdi      # 0xe029
movb $0x0, %al
callq 0x10d0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movzwl -0x18(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movw $0x0, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x22(%rcx), %ecx
cmpl %ecx, %eax
jge 0x54e5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
setne %al
andb $0x1, %al
movb %al, -0x23(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
andl $0xff, %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x14(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
andl $0xff, %ecx
orl %ecx, %eax
movw %ax, -0x26(%rbp)
movl -0x14(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %esi
subl $0x2, %esi
movb -0x23(%rbp), %cl
leaq 0x94e2(%rip), %rdx      # 0xe996
leaq 0x94d5(%rip), %rax      # 0xe990
testb $0x1, %cl
cmovneq %rax, %rdx
movzwl -0x26(%rbp), %ecx
leaq 0x94b2(%rip), %rdi      # 0xe97f
movb $0x0, %al
callq 0x10d0
movw -0x22(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x22(%rbp)
jmp 0x5431
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x94a0(%rip), %rdi      # 0xe99e
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9492(%rip), %rdi      # 0xe9a7
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9482(%rip), %rdi      # 0xe9b2
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9471(%rip), %rdi      # 0xe9bc
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9468(%rip), %rdi      # 0xe9ce
callq 0x56c0
movl %eax, -0x4(%rbp)
jmp 0x55df
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq 0x9461(%rip), %rdi      # 0xe9df
callq 0x55f0
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9457(%rip), %rdi      # 0xe9e9
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x944b(%rip), %rdi      # 0xe9f1
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movl -0x14(%rbp), %esi
leaq 0x9441(%rip), %rdi      # 0xe9fb
callq 0x5690
movl %eax, -0x4(%rbp)
jmp 0x55df
movzbl -0x15(%rbp), %esi
leaq 0x9436(%rip), %rdi      # 0xea05
movb $0x0, %al
callq 0x10d0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)