// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pcf.c
// Function: handler_metrics
static void handler_metrics(deark *c, lctx *d, struct table_entry *te)
{
	i64 pos = te->offset;
	int saved_indent_level;
	i64 nmetrics;
	i64 k;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "metrics table at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	if(!read_and_check_format_field(c, d, te, pos)) goto done;
	pos += 4;

	nmetrics = dbuf_getu16x(c->infile, pos, te->fmt.is_le);
	pos += 2;
	de_dbg(c, "number of metrics: %d", (int)nmetrics);

	d->num_chars = nmetrics;

	// Allocate chars array, and set defaults
	d->chars = de_mallocarray(c, d->num_chars, sizeof(struct char_info));
	for(k=0; k<d->num_chars; k++) {
		d->chars[k].codepoint = DE_CODEPOINT_INVALID;
	}

	for(k=0; k<d->num_chars; k++) {
		int leftsb, rightsb;
		int char_width;
		int char_desc;
		unsigned int char_attr;
		struct char_info *ci;

		de_dbg2(c, "char[%d]", (int)k);
		de_dbg_indent(c, 1);
		ci = &d->chars[k];

		if(te->fmt.gross_format==GFMT_COMPRESSED_METRICS) {
			leftsb = (int)de_getbyte_p(&pos) - 0x80;
			rightsb = (int)de_getbyte_p(&pos) - 0x80;
			char_width = (int)de_getbyte_p(&pos) - 0x80;
			ci->ascent = (int)de_getbyte_p(&pos) - 0x80;
			char_desc = (int)de_getbyte_p(&pos) - 0x80;
			char_attr = 0;
		}
		else {
			leftsb = (int)dbuf_geti16x(c->infile, pos, te->fmt.is_le); pos += 2;
			rightsb = (int)dbuf_geti16x(c->infile, pos, te->fmt.is_le); pos += 2;
			char_width = (int)dbuf_geti16x(c->infile, pos, te->fmt.is_le); pos += 2;
			ci->ascent = (int)dbuf_geti16x(c->infile, pos, te->fmt.is_le); pos += 2;
			char_desc = (int)dbuf_geti16x(c->infile, pos, te->fmt.is_le); pos += 2;
			char_attr = (int)dbuf_getu16x(c->infile, pos, te->fmt.is_le); pos += 2;
		}

		if(c->debug_level>=2) {
			de_dbg2(c, "bearing (l, r): %d, %d", leftsb, rightsb);
			de_dbg2(c, "width: %d", char_width);
			de_dbg2(c, "ascent, descent: %d, %d", ci->ascent, char_desc);
			de_dbg2(c, "attributes: %u", char_attr);
		}
		ci->width_raw = rightsb - leftsb;
		ci->height_raw = ci->ascent + char_desc;
		if(c->debug_level>=2) {
			de_dbg(c, "raw bitmap dimensions: %d"DE_CHAR_TIMES"%d",
				ci->width_raw, ci->height_raw);
		}

		// TODO: Are these calculations correct?
		ci->extraspace_l = (i16)leftsb;
		if(ci->extraspace_l<0) ci->extraspace_l=0;
		ci->extraspace_r = (i16)(char_width - ci->width_raw - (int)ci->extraspace_l);
		if(ci->extraspace_r<0) ci->extraspace_r=0;

		de_dbg_indent(c, -1);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0xa9578(%rip), %rsi     # 0x1c5534
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x11cb10
cmpl $0x0, %eax
jne 0x11bff0
jmp 0x11c3c0
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0xa9514(%rip), %rsi     # 0x1c5549
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x18, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x11c0a4
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movl $0xfffffff, 0x4(%rax)   # imm = 0xFFFFFFF
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x11c071
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x11c3be
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xa9490(%rip), %rsi     # 0x1c555f
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x100, 0x4(%rax)       # imm = 0x100
jne 0x11c1a6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
subl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
subl $0x80, %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
subl $0x80, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %ecx
subl $0x80, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
subl $0x80, %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
jmp 0x11c296
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165870
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165870
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165870
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165870
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165870
movl %eax, -0x48(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x165820
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x11c2fd
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
leaq 0xa92b8(%rip), %rsi     # 0x1c5568
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0x8e98e(%rip), %rsi     # 0x1aac53
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x10(%rax), %edx
movl -0x48(%rbp), %ecx
leaq 0xa929e(%rip), %rsi     # 0x1c557f
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %edx
leaq 0xa92a1(%rip), %rsi     # 0x1c5597
movb $0x0, %al
callq 0x15b350
movl -0x40(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
addl -0x48(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x11c344
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0xa9269(%rip), %rsi     # 0x1c55a6
movb $0x0, %al
callq 0x15b0d0
movl -0x3c(%rbp), %eax
movw %ax, %cx
movq -0x58(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x58(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $0x0, %eax
jge 0x11c369
movq -0x58(%rbp), %rax
movw $0x0, 0x14(%rax)
movl -0x44(%rbp), %eax
movq -0x58(%rbp), %rcx
subl 0x8(%rcx), %eax
movq -0x58(%rbp), %rcx
movswl 0x14(%rcx), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x58(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x58(%rbp), %rax
movswl 0x16(%rax), %eax
cmpl $0x0, %eax
jge 0x11c39f
movq -0x58(%rbp), %rax
movw $0x0, 0x16(%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x11c0ac
jmp 0x11c3c0
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x15b5a0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)