// File: /workspace/github_c_makefile_star2_O0/jeff-1amstudios[P]carmageddon-1-cheat-code-disassembly/src/log/zf_log.c
// Function: output_mem
static void output_mem(const zf_log_spec *log, zf_log_message *const msg,
                       const mem_block *const mem)
{
    if (0 == mem->d || 0 == mem->d_sz)
    {
        return;
    }
    const unsigned char *mem_p = (const unsigned char *)mem->d;
    const unsigned char *const mem_e = mem_p + mem->d_sz;
    const unsigned char *mem_cut;
    const ptrdiff_t mem_width = (ptrdiff_t)log->format->mem_width;
    char *const hex_b = msg->msg_b;
    char *const ascii_b = hex_b + 2 * mem_width + 2;
    char *const ascii_e = ascii_b + mem_width;
    if (msg->e < ascii_e)
    {
        return;
    }
    while (mem_p != mem_e)
    {
        char *hex = hex_b;
        char *ascii = ascii_b;
        for (mem_cut = mem_width < mem_e - mem_p? mem_p + mem_width: mem_e;
             mem_cut != mem_p; ++mem_p)
        {
            const unsigned char ch = *mem_p;
            *hex++ = c_hex[(0xf0 & ch) >> 4];
            *hex++ = c_hex[(0x0f & ch)];
            *ascii++ = isprint(ch)? (char)ch: '?';
        }
        while (hex != ascii_b)
        {
            *hex++ = ' ';
        }
        msg->p = ascii;
        log->output->callback(msg, log->output->arg);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpq (%rcx), %rax
je 0x462d
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpl 0x8(%rcx), %eax
jne 0x4632
jmp 0x47fb
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x50(%rbp), %rax
jae 0x469d
jmp 0x47fb
jmp 0x469f
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x47fb
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jge 0x46df
movq -0x20(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x46e7
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x47ac
movq -0x20(%rbp), %rax
movb (%rax), %al
movb %al, -0x61(%rbp)
movzbl -0x61(%rbp), %eax
andl $0xf0, %eax
sarl $0x4, %eax
movslq %eax, %rcx
leaq 0x5b24(%rip), %rax      # 0xa240
movb (%rax,%rcx), %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movzbl -0x61(%rbp), %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0x5aff(%rip), %rax      # 0xa240
movb (%rax,%rcx), %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
callq 0x2260
movq (%rax), %rax
movzbl -0x61(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x477b
movsbl -0x61(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x4785
movl $0x3f, %eax
movl %eax, -0x74(%rbp)
jmp 0x4785
movl -0x74(%rbp), %eax
movb %al, %cl
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x60(%rbp)
movb %cl, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x46ef
jmp 0x47ae
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x47cc
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x20, (%rax)
jmp 0x47ae
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rsi
callq *%rax
jmp 0x469f
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)