// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movq %r8, 0x170(%rsp)
movq %r9, 0x178(%rsp)
testb %al, %al
je 0xa4ea
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 0xa53c
cmpb $0x0, (%rcx)
je 0xa53c
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), %rbx
movq %rbx, %rdi
movq %rcx, %rsi
callq 0x34f0
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x3290
xorl %eax, %eax
leaq 0x60(%rsp), %r13
movb %al, (%r13)
leaq 0xe0(%rsp), %rcx
movb %al, (%rcx)
leaq 0xb0(%rsp), %rbx
movb %al, (%rbx)
testl %ebp, %ebp
cmovlel %eax, %ebp
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
cmpq %r14, %rbp
je 0xa699
testb $0xf, %r14b
setne %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0xa5a8
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %r13, %rdx
leaq 0xe0(%rsp), %rcx
movq %rbx, %r8
callq 0xa6d5
movl %r14d, 0x4(%rsp)
jmp 0xa5c8
testq %r14, %r14
sete %al
testb $0x7, %r14b
setne %cl
orb %al, %cl
jne 0xa5c8
movq %r13, %rdi
callq 0x3190
movw $0x20, 0x60(%rsp,%rax)
leaq 0x10(%rsp), %rdi
movzbl (%r15,%r14), %edx
leaq 0xa2e4(%rip), %rsi      # 0x148bd
xorl %eax, %eax
callq 0x3530
cmpb $0x0, 0x60(%rsp)
je 0xa5f6
movq %r13, %rdi
callq 0x3190
movw $0x20, 0x60(%rsp,%rax)
movq %r13, %rdi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0x3510
testb $0x1, %r14b
je 0xa66c
leaq 0xe0(%rsp), %r13
movq %rbp, %rbx
movzwl -0x1(%r15,%r14), %ebp
cmpb $0x0, 0xe0(%rsp)
je 0xa639
movq %r13, %rdi
callq 0x3190
movw $0x20, 0xe0(%rsp,%rax)
leaq 0x10(%rsp), %r12
movq %r12, %rdi
leaq 0xa27a(%rip), %rsi      # 0x148c2
movl %ebp, %edx
xorl %eax, %eax
callq 0x3530
movq %r13, %rdi
movq %r12, %rsi
callq 0x3510
movq %rbx, %rbp
leaq 0x60(%rsp), %r13
leaq 0xb0(%rsp), %rbx
movzbl (%r15,%r14), %eax
leal -0x7f(%rax), %ecx
cmpb $-0x5f, %cl
pushq $0x2e
popq %rcx
cmovbl %ecx, %eax
movb %al, 0x10(%rsp)
movb $0x0, 0x11(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3510
incq %r14
jmp 0xa56b
cmpb $0x0, 0x60(%rsp)
je 0xa6c3
leaq 0x60(%rsp), %rdx
leaq 0xe0(%rsp), %rcx
leaq 0xb0(%rsp), %r8
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
callq 0xa6d5
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq