// File: /workspace/github_c_makefile_star2_O1/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 $0x218, %rsp            # imm = 0x218
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movq %r8, 0x180(%rsp)
movq %r9, 0x188(%rsp)
testb %al, %al
je 0xae6a
movaps %xmm0, 0x190(%rsp)
movaps %xmm1, 0x1a0(%rsp)
movaps %xmm2, 0x1b0(%rsp)
movaps %xmm3, 0x1c0(%rsp)
movaps %xmm4, 0x1d0(%rsp)
movaps %xmm5, 0x1e0(%rsp)
movaps %xmm6, 0x1f0(%rsp)
movaps %xmm7, 0x200(%rsp)
testq %rcx, %rcx
je 0xaebe
cmpb $0x0, (%rcx)
je 0xaebe
leaq 0x160(%rsp), %rax
leaq 0x140(%rsp), %rdx
movq %rax, 0x10(%rdx)
leaq 0x250(%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 0x3500
movl $0xa, %edi
movq %r15, %rsi
callq 0x32a0
xorl %r12d, %r12d
movb %r12b, 0x50(%rsp)
movb %r12b, 0xf0(%rsp)
movb %r12b, 0x20(%rsp)
testl %ebx, %ebx
jle 0xb022
movl %ebx, %eax
movq %rax, 0x18(%rsp)
leaq 0x50(%rsp), %r15
leaq 0xf0(%rsp), %rbx
xorl %r13d, %r13d
xorl %r12d, %r12d
testb $0xf, %r13b
setne %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0xaf23
movq 0x8(%rsp), %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rbx, %rcx
leaq 0x20(%rsp), %r8
callq 0xb05a
movl %r13d, %r12d
jmp 0xaf43
testq %r13, %r13
sete %al
testb $0x7, %r13b
setne %cl
orb %al, %cl
jne 0xaf43
movq %r15, %rdi
callq 0x31a0
movw $0x20, 0x50(%rsp,%rax)
leaq 0xa0(%rsp), %rdi
movzbl (%r14,%r13), %edx
leaq 0xa92a(%rip), %rsi      # 0x15881
xorl %eax, %eax
callq 0x3540
cmpb $0x0, 0x50(%rsp)
je 0xaf74
movq %r15, %rdi
callq 0x31a0
movw $0x20, 0x50(%rsp,%rax)
movq %r15, %rdi
leaq 0xa0(%rsp), %rbp
movq %rbp, %rsi
callq 0x3520
testb $0x1, %r13b
je 0xafe5
movl %r12d, 0x14(%rsp)
movzwl -0x1(%r14,%r13), %r12d
cmpb $0x0, 0xf0(%rsp)
je 0xafb4
movq %rbx, %rdi
callq 0x31a0
movw $0x20, 0xf0(%rsp,%rax)
leaq 0xa0(%rsp), %rbp
movq %rbp, %rdi
leaq 0xa8c0(%rip), %rsi      # 0x15886
movl %r12d, %edx
xorl %eax, %eax
callq 0x3540
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3520
leaq 0x50(%rsp), %r15
movl 0x14(%rsp), %r12d
movzbl (%r14,%r13), %eax
leal -0x7f(%rax), %ecx
cmpb $-0x5f, %cl
movl $0x2e, %ecx
cmovbl %ecx, %eax
movb %al, 0xa0(%rsp)
movb $0x0, 0xa1(%rsp)
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x3520
incq %r13
cmpq %r13, 0x18(%rsp)
jne 0xaef5
cmpb $0x0, 0x50(%rsp)
je 0xb048
leaq 0x50(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0xb05a
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq