// File: /workspace/github_c_makefile_star2_O0/goodpaul6[P]generic/script.c
// Function: print_stack_trace
static void print_stack_trace(script_t* script)
{
	fprintf(stderr, "Trace:\n");
	for(int i = script->call_records.length - 1; i >= 0; --i)
	{
		script_call_record_t* record = vec_get(&script->call_records, i);

		fprintf(stderr, "(%s, %d): ", record->file, record->line);
		
		if (record->function.is_extern)
			fprintf(stderr, "extern %s(", vec_get_value(&script->extern_names, record->function.index, char*));
		else
			fprintf(stderr, "%s(", vec_get_value(&script->function_names, record->function.index, char*));
		
		if (record->nargs > 0)
		{
			// NOTE: arguments started at exactly record->stackSize - record->nargs
			int args_start = record->stack_size - record->nargs;

			// NOTE: Print all arguments to this function
			// TODO: Have write_value take in a FILE* so we can route this
			// to stderr
			for (int i = args_start; i < args_start + record->nargs; ++i)
			{
				write_value(vec_get_value(&script->stack, i, script_value_t*), 1);
				if (i + 1 < args_start + record->nargs)
					fprintf(stderr, ", ");
			}
		}

		fprintf(stderr, ")\n");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq 0xddd5(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
leaq 0x8c11(%rip), %rsi      # 0x14e3e
movb $0x0, %al
callq 0x2150
movq -0x8(%rbp), %rax
movq 0x140(%rax), %rax
subq $0x1, %rax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0xc3cd
movq -0x8(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movslq -0xc(%rbp), %rsi
callq 0x11890
movq %rax, -0x18(%rbp)
movq 0xdd89(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x18(%rbp), %rax
movl 0x28(%rax), %ecx
leaq 0x8bbe(%rip), %rsi      # 0x14e46
movb $0x0, %al
callq 0x2150
movq -0x18(%rbp), %rax
cmpb $0x0, 0x14(%rax)
je 0xc2d6
movq 0xdd58(%rip), %rax      # 0x19ff8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x238, %rdi            # imm = 0x238
movq -0x18(%rbp), %rax
movslq 0x18(%rax), %rsi
callq 0x11890
movq -0x28(%rbp), %rdi
movq (%rax), %rdx
leaq 0x8b84(%rip), %rsi      # 0x14e51
movb $0x0, %al
callq 0x2150
jmp 0xc311
movq 0xdd1b(%rip), %rax      # 0x19ff8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x278, %rdi            # imm = 0x278
movq -0x18(%rbp), %rax
movslq 0x18(%rax), %rsi
callq 0x11890
movq -0x30(%rbp), %rdi
movq (%rax), %rdx
leaq 0x8b4e(%rip), %rsi      # 0x14e58
movb $0x0, %al
callq 0x2150
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0xc3a7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rdx
addl 0x10(%rdx), %ecx
cmpl %ecx, %eax
jge 0xc3a5
movq -0x8(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
movslq -0x20(%rbp), %rsi
callq 0x11890
movq (%rax), %rdi
movl $0x1, %esi
callq 0xc3e0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rdx
addl 0x10(%rdx), %ecx
cmpl %ecx, %eax
jge 0xc398
movq 0xdc71(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
leaq 0x8acb(%rip), %rsi      # 0x14e5c
movb $0x0, %al
callq 0x2150
jmp 0xc39a
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xc33a
jmp 0xc3a7
movq 0xdc4a(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
leaq 0x9489(%rip), %rsi      # 0x15841
movb $0x0, %al
callq 0x2150
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xc246
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)