// File: /workspace/github_c_makefile_star2_O3/j-hoppe[P]tu58fs/utils.c
// Function: hexdump
void hexdump(FILE *stream, uint8_t *data, int size, char *fmt, ...) {
	va_list args;
	int i, startaddr;
	char line_hexb[80]; // buffer for hex bytes
	char line_hexw[80]; // buffer for hex words
	char line_ascii[40]; // buffer for ASCII chars

	if (fmt && strlen(fmt)) {
		va_start(args, fmt);
		vfprintf(stream, fmt, args);
		fprintf(stream, "\n");
		va_end(args);
	}
	line_hexb[0] = 0; // clear output
	line_hexw[0] = 0;
	line_ascii[0] = 0;
	for (startaddr = i = 0; i < size; i++) {
		char buff[80];
		char c;
		if ((i % HEXDUMP_BYTESPERLINE) == 0 && i > 0) { // dump cur line
			hexdump_put(stream, startaddr, line_hexb, line_hexw, line_ascii);
			startaddr = i; // label for next line
		} else if ((i % 8) == 0 && i > 0) { // 8er col separator
			strcat(line_hexb, " ");
		}
		// append cur byte to hex and char display line
		sprintf(buff, "%02x", (unsigned) data[i]);
		if (strlen(line_hexb))
			strcat(line_hexb, " ");
		strcat(line_hexb, buff);
		if (i % 2) { // odd: mount word. LSB first
			unsigned w = data[i];
			w = (w << 8) | data[i - 1];
			if (strlen(line_hexw))
				strcat(line_hexw, " ");
			sprintf(buff, "%04x", w);
			strcat(line_hexw, buff);
		}

		c = data[i];
		if (c < 0x20 || c >= 0x7f)
			c = '.';
		sprintf(buff, "%c", c);
		strcat(line_ascii, buff);
	}    // dump rest of lines
	if (strlen(line_hexb))
		hexdump_put(stream, startaddr, line_hexb, line_hexw, line_ascii);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movq %r8, 0x170(%rsp)
movq %r9, 0x178(%rsp)
testb %al, %al
je 0xae04
movaps %xmm0, 0x180(%rsp)
movaps %xmm1, 0x190(%rsp)
movaps %xmm2, 0x1a0(%rsp)
movaps %xmm3, 0x1b0(%rsp)
movaps %xmm4, 0x1c0(%rsp)
movaps %xmm5, 0x1d0(%rsp)
movaps %xmm6, 0x1e0(%rsp)
movaps %xmm7, 0x1f0(%rsp)
testq %rcx, %rcx
je 0xae58
cmpb $0x0, (%rcx)
je 0xae58
leaq 0x150(%rsp), %rax
leaq 0x130(%rsp), %rdx
movq %rax, 0x10(%rdx)
leaq 0x240(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000020, %rax     # imm = 0x3000000020
movq %rax, (%rdx)
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rcx, %rsi
callq 0x34f0
movl $0xa, %edi
movq %r15, %rsi
callq 0x3290
xorl %eax, %eax
movb %al, 0x40(%rsp)
movb %al, 0xe0(%rsp)
movb %al, 0x10(%rsp)
testl %ebx, %ebx
jle 0xafe8
movl %ebx, %r12d
leaq 0x40(%rsp), %rbp
leaq 0x10(%rsp), %rbx
xorl %r13d, %r13d
movl $0x0, 0x4(%rsp)
testb $0xf, %r13b
setne %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0xaebd
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbp, %rdx
leaq 0xe0(%rsp), %rcx
movq %rbx, %r8
callq 0xaffa
movl %r13d, 0x4(%rsp)
jmp 0xaedd
testq %r13, %r13
sete %al
testb $0x7, %r13b
setne %cl
orb %al, %cl
jne 0xaedd
movq %rbp, %rdi
callq 0x3190
movw $0x20, 0x40(%rsp,%rax)
leaq 0x90(%rsp), %rdi
movzbl (%r14,%r13), %edx
leaq 0xa9f4(%rip), %rsi      # 0x158e5
xorl %eax, %eax
callq 0x3530
cmpb $0x0, 0x40(%rsp)
je 0xaf0e
movq %rbp, %rdi
callq 0x3190
movw $0x20, 0x40(%rsp,%rax)
movq %rbp, %rdi
leaq 0x90(%rsp), %r15
movq %r15, %rsi
callq 0x3510
testb $0x1, %r13b
je 0xaf88
leaq 0xe0(%rsp), %rbp
movq %r12, %rbx
movzwl -0x1(%r14,%r13), %r12d
cmpb $0x0, 0xe0(%rsp)
je 0xaf54
movq %rbp, %rdi
callq 0x3190
movw $0x20, 0xe0(%rsp,%rax)
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0xa984(%rip), %rsi      # 0x158ea
movl %r12d, %edx
xorl %eax, %eax
callq 0x3530
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3510
movq %rbx, %r12
leaq 0x40(%rsp), %rbp
leaq 0x10(%rsp), %rbx
movzbl (%r14,%r13), %eax
leal -0x7f(%rax), %ecx
cmpb $-0x5f, %cl
movl $0x2e, %ecx
cmovbl %ecx, %eax
movb %al, 0x90(%rsp)
movb $0x0, 0x91(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3510
incq %r13
cmpq %r13, %r12
jne 0xae89
cmpb $0x0, 0x40(%rsp)
je 0xafe8
leaq 0x40(%rsp), %rdx
leaq 0xe0(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
callq 0xaffa
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq