// File: /workspace/github_c_makefile_star2_O1/goodpaul6[P]generic/script.c
// Function: script_dissassemble
static void disassemble(script_t* script, FILE* out)
{
	int pc = 0;
	
	const char* file = "unknown";
	int line = 0;
	
	while(pc < script->code.length)
	{
		word code = vec_get_value(&script->code, pc, word);
		++pc;
		
		if(code != OP_FILE && code != OP_LINE)
			fprintf(out, "%d (%s:%i): ", pc, file, line);

		switch(code)
		{
			case OP_PUSH_NULL: fprintf(out, "push_null\n"); break;
			
			case OP_PUSH_TRUE: fprintf(out, "push_true\n"); break;
			case OP_PUSH_FALSE: fprintf(out, "push_false\n"); break;
			
			case OP_PUSH_CHAR:
			{
				int c = read_int_at(script, pc);
				fprintf(out, "push_char '%c'\n", c);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_PUSH_NUMBER:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "push_number %g\n", vec_get_value(&script->numbers, index, double));
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_PUSH_STRING:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "push_string '%s'\n", vec_get_value(&script->strings, index, script_string_t).data);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_PUSH_FUNC:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "push_func %d (pc = %d)\n", index, vec_get_value(&script->function_pcs, index, int));
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_PUSH_EXTERN_FUNC:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "push_extern_func %s (id=%d)\n", vec_get_value(&script->extern_names, index, char*), index);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_PUSH_ARRAY:
			{
				fprintf(out, "push_array\n");
			} break;
			
			case OP_PUSH_ARRAY_BLOCK:
			{
				int length = read_int_at(script, pc);
				fprintf(out, "push_array_block %d\n", length);
				pc += sizeof(int) / sizeof(word);
			} break;
		
			case OP_PUSH_RETVAL:
			{
				fprintf(out, "push_retval\n");
			} break;

			case OP_PUSH_STRUCT:
			{
				int nmem = read_int_at(script, pc);
				pc += sizeof(int) / sizeof(word);
				
				int ninit = read_int_at(script, pc);
				pc += sizeof(int) / sizeof(word);
				
				fprintf(out, "push_struct num_members=%d num_init=%d\n", nmem, ninit);
			} break;
			
			case OP_STRING_LEN:
			{
				fprintf(out, "string_len\n");
			} break;
			
			case OP_ARRAY_LEN:
			{
				fprintf(out, "array_len\n");
			} break;
			
			case OP_STRING_GET:
			{
				fprintf(out, "string_get\n");
			} break;
			
			case OP_ARRAY_GET:
			{
				fprintf(out, "array_get\n");
			} break;
			
			case OP_ARRAY_SET:
			{
				fprintf(out, "array_set\n");
			} break;
			
			case OP_STRUCT_GET:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "struct_get %d\n", index);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_STRUCT_SET:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "struct_set %d\n", index);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_ADD: fprintf(out, "add\n"); break;
			case OP_SUB: fprintf(out, "sub\n"); break;
			case OP_MUL: fprintf(out, "mul\n"); break;
			case OP_DIV: fprintf(out, "div\n"); break;
			case OP_MOD: fprintf(out, "mod\n"); break;

			case OP_LT: fprintf(out, "lt\n"); break;
			case OP_GT: fprintf(out, "gt\n"); break;
			case OP_LTE: fprintf(out, "lte\n"); break;
			case OP_GTE: fprintf(out, "gte\n"); break;
			
			case OP_LAND: fprintf(out, "land\n"); break;
			case OP_LOR: fprintf(out, "lor\n"); break;
			
			case OP_NEG: fprintf(out, "neg\n"); break;
			case OP_NOT: fprintf(out, "not\n"); break;
			
			case OP_EQU: fprintf(out, "equ\n"); break;
			
			case OP_READ: fprintf(out, "read\n"); break;
			case OP_WRITE: fprintf(out, "write\n"); break;
		
			case OP_SET:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "set %d\n", index);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_GET:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "get %d\n", index);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_SETLOCAL:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "setlocal %d\n", index);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_GETLOCAL:
			{
				int index = read_int_at(script, pc);
				fprintf(out, "getlocal %d\n", index);
				pc += sizeof(int) / sizeof(word);
			} break;
		
			case OP_GOTO:
			{
				int g = read_int_at(script, pc);
				fprintf(out, "goto %d\n", g);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_GOTOZ:
			{
				int g = read_int_at(script, pc);
				fprintf(out, "gotoz %d\n", g);
				pc += sizeof(int) / sizeof(word);
			} break;
			
			case OP_CALL:
			{
				word nargs = vec_get_value(&script->code, pc++, word);
				fprintf(out, "call nargs=%d\n", nargs);
			} break;
			
			case OP_RETURN:
			{
				fprintf(out, "return\n");
			} break;
			
			case OP_RETURN_VALUE:
			{
				fprintf(out, "return_value\n");
			} break;
			
			case OP_FILE:
			{
				int index = read_int_at(script, pc);
				const char* str = vec_get_value(&script->strings, index, script_string_t).data;
				pc += sizeof(int) / sizeof(word);
				
				file = str;
			} break;
			
			case OP_LINE:
			{
				int line_no = read_int_at(script, pc);
				pc += sizeof(int) / sizeof(word);
				line = line_no;
			} break;
			
			case OP_ATOMIC_ENABLE:
			{
				fprintf(out, "atomic_enable\n");
			} break;
			
			case OP_ATOMIC_DISABLE:
			{
				fprintf(out, "atomic_disable\n");
			} break;

			case OP_HALT:
			{
				fprintf(out, "halt\n");
			} break;
		}
	}
}

// Assembly:
cmpq $0x0, 0x1e8(%rdi)
je 0x452a
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1d8(%rdi), %rax
movq %rax, -0x48(%rbp)
leaq 0x218(%rdi), %rax
movq %rax, -0x38(%rbp)
leaq 0x238(%rdi), %rax
movq %rax, -0x60(%rbp)
leaq 0x298(%rdi), %rax
movq %rax, -0x58(%rbp)
leaq 0x1f8(%rdi), %rax
movq %rax, -0x50(%rbp)
leaq 0xb601(%rip), %rax      # 0xf6b5
movq %rax, -0x40(%rbp)
xorl %esi, %esi
xorl %r13d, %r13d
movl $0x0, -0x2c(%rbp)
movq -0x48(%rbp), %rdi
callq 0xdf24
movzbl (%rax), %r15d
leal 0x1(%r13), %r12d
leal -0x2e(%r15), %eax
cmpb $-0x3, %al
ja 0x40f9
movq %rbx, %rdi
leaq 0xd5cd(%rip), %rsi      # 0x116b4
movl %r12d, %edx
movq -0x40(%rbp), %rcx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x2170
cmpl $0x30, %r15d
ja 0x44f9
movl %r15d, %eax
leaq 0xaf77(%rip), %rcx      # 0xf084
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xd5a4(%rip), %rdi      # 0x116c1
jmp 0x43c5
leaq 0xd760(%rip), %rdi      # 0x11889
movl $0xd, %esi
jmp 0x44ec
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd6aa(%rip), %rsi      # 0x117ef
jmp 0x44cb
leaq 0xd755(%rip), %rdi      # 0x118a6
movl $0xf, %esi
jmp 0x44ec
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd6f2(%rip), %rsi      # 0x1185f
jmp 0x44cb
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd6e4(%rip), %rsi      # 0x11868
jmp 0x44cb
leaq 0xd689(%rip), %rdi      # 0x11819
jmp 0x44e7
leaq 0xd6a2(%rip), %rdi      # 0x1183e
movl $0x6, %esi
jmp 0x44ec
leaq 0xd621(%rip), %rdi      # 0x117ce
jmp 0x43c5
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movslq %eax, %rsi
movq -0x38(%rbp), %rdi
callq 0xdf24
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x44d7
leaq 0xd5da(%rip), %rdi      # 0x117b7
jmp 0x4433
leaq 0xd64f(%rip), %rdi      # 0x11838
jmp 0x44a9
leaq 0xd6c1(%rip), %rdi      # 0x118b6
jmp 0x44a9
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movl %eax, %r12d
leal 0x5(%r13), %esi
movq %r14, %rdi
callq 0xd806
addl $0x9, %r13d
leaq 0xd559(%rip), %rsi      # 0x11778
movq %rbx, %rdi
movl %r12d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x2170
jmp 0x44db
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movslq %eax, %rsi
movq -0x50(%rbp), %rdi
callq 0xdf24
movsd (%rax), %xmm0
leaq 0xd49e(%rip), %rsi      # 0x116f3
movq %rbx, %rdi
movb $0x1, %al
callq 0x2170
jmp 0x44d7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd5dc(%rip), %rsi      # 0x11852
jmp 0x44cb
leaq 0xd51e(%rip), %rdi      # 0x117a0
jmp 0x4433
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd4bd(%rip), %rsi      # 0x11756
jmp 0x44cb
leaq 0xd56b(%rip), %rdi      # 0x11810
jmp 0x42ae
leaq 0xd60a(%rip), %rdi      # 0x118b8
movl $0x3, %esi
jmp 0x44ec
leaq 0xd418(%rip), %rdi      # 0x116d7
jmp 0x4433
leaq 0xd4f8(%rip), %rdi      # 0x117c3
jmp 0x43c5
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd401(%rip), %rsi      # 0x116e3
jmp 0x44cb
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movslq %eax, %r12
movq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0xdf24
movq (%rax), %rdx
leaq 0xd422(%rip), %rsi      # 0x1172d
movq %rbx, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2170
jmp 0x44d7
leaq 0xd3a8(%rip), %rdi      # 0x116cc
jmp 0x43c5
leaq 0xd4fe(%rip), %rdi      # 0x1182e
jmp 0x44e7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd492(%rip), %rsi      # 0x117d9
jmp 0x44cb
addl $0x2, %r13d
movslq %r12d, %rsi
movq -0x48(%rbp), %rdi
callq 0xdf24
movzbl (%rax), %edx
leaq 0xd50c(%rip), %rsi      # 0x11872
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2170
jmp 0x44db
leaq 0xd480(%rip), %rdi      # 0x117fc
jmp 0x44e7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movslq %eax, %rsi
movq -0x38(%rbp), %rdi
callq 0xdf24
movq 0x8(%rax), %rdx
leaq 0xd360(%rip), %rsi      # 0x11703
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2170
jmp 0x44d7
leaq 0xd448(%rip), %rdi      # 0x11801
jmp 0x44e7
leaq 0xd3e7(%rip), %rdi      # 0x117ac
movl $0xa, %esi
jmp 0x44ec
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movslq %eax, %r12
movq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0xdf24
movl (%rax), %ecx
leaq 0xd323(%rip), %rsi      # 0x11715
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2170
jmp 0x44d7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd3d2(%rip), %rsi      # 0x117e8
jmp 0x44cb
leaq 0xd349(%rip), %rdi      # 0x1176b
movl $0xc, %esi
jmp 0x44ec
leaq 0xd317(%rip), %rdi      # 0x1174a
movl $0xb, %esi
jmp 0x44ec
leaq 0xd3e5(%rip), %rdi      # 0x11829
jmp 0x44e7
leaq 0xd3e3(%rip), %rdi      # 0x11833
jmp 0x44e7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
movl %eax, -0x2c(%rbp)
jmp 0x44d7
leaq 0xd39a(%rip), %rdi      # 0x11806
jmp 0x44e7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd3c5(%rip), %rsi      # 0x11845
jmp 0x44cb
leaq 0xd36e(%rip), %rdi      # 0x117f7
jmp 0x44e7
leaq 0xd3ef(%rip), %rdi      # 0x11881
movl $0x7, %esi
jmp 0x44ec
leaq 0xd36b(%rip), %rdi      # 0x1180b
jmp 0x44e7
leaq 0xd375(%rip), %rdi      # 0x1181e
movl $0x5, %esi
jmp 0x44ec
leaq 0xd36d(%rip), %rdi      # 0x11824
jmp 0x44e7
movq %r14, %rdi
movl %r12d, %esi
callq 0xd806
leaq 0xd315(%rip), %rsi      # 0x117e0
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x2170
addl $0x5, %r13d
movl %r13d, %r12d
jmp 0x44f9
leaq 0xd32d(%rip), %rdi      # 0x11814
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2240
movslq %r12d, %rsi
movl %r12d, %r13d
cmpq %rsi, 0x1e8(%r14)
ja 0x40c4
jmp 0x451c
leaq 0xd382(%rip), %rdi      # 0x11897
movl $0xe, %esi
jmp 0x44ec
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq