// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/wri.c
// Function: do_para_info_page
static void do_para_info_page(deark *c, lctx *d, i64 pos)
{
	i64 fcFirst;
	i64 cfod;
	i64 i;
	i64 fod_array_startpos;
	i64 prevtextpos;
	u8 fprop_seen[128];

	de_zeromem(fprop_seen, sizeof(fprop_seen));
	de_dbg(c, "paragraph info page at %d", (int)pos);
	de_dbg_indent(c, 1);

	cfod = (i64)de_getbyte(pos+127);
	de_dbg(c, "number of FODs on this page: %d", (int)cfod);

	// There are up to 123 bytes available for the FOD array, and each FOD is
	// 6 bytes. So I assume the maximum possible is 20.
	if(cfod>20) cfod=20;

	fcFirst = de_getu32le(pos);
	de_dbg(c, "fcFirst: %d", (int)fcFirst);

	fod_array_startpos = pos + 4;

	prevtextpos = fcFirst;

	for(i=0; i<cfod; i++) {
		struct para_info *pinfo = NULL;
		i64 fcLim_orig, fcLim_adj;
		i64 bfprop;
		i64 fodpos = fod_array_startpos + 6*i;

		pinfo = de_malloc(c, sizeof(struct para_info));

		de_dbg(c, "FOD[%d] at %d", (int)i, (int)fodpos);
		de_dbg_indent(c, 1);

		fcLim_orig = de_getu32le(fodpos);
		fcLim_adj = fcLim_orig;
		if(fcLim_adj > d->fcMac) fcLim_adj = d->fcMac;
		pinfo->thisparapos = prevtextpos;
		pinfo->thisparalen = fcLim_adj - prevtextpos;
		de_dbg(c, "fcLim: %d (paragraph from %d to %d)", (int)fcLim_orig,
			(int)pinfo->thisparapos, (int)(fcLim_adj-1));
		prevtextpos = fcLim_adj;

		bfprop = de_getu16le(fodpos+4);
		if(bfprop==0xffff) {
			de_dbg(c, "bfprop: %d (none)", (int)bfprop);
		}
		else {
			pinfo->bfprop_offset = fod_array_startpos + bfprop;

			de_dbg(c, "bfprop: %d (+ %d = %d)", (int)bfprop,
				(int)fod_array_startpos, (int)pinfo->bfprop_offset);

			de_dbg_indent(c, 1);
			if(bfprop<128) {
				if(fprop_seen[bfprop]) {
					// An FPROP can be referenced multiple times. Only print the
					// debug info for it once.
					de_dbg(c, "[already decoded FPROP at %d on this paragraph info page]", (int)bfprop);
				}
				do_para_fprop(c, d, pinfo, bfprop, fprop_seen[bfprop]);
				fprop_seen[bfprop] = 1;
			}
			de_dbg_indent(c, -1);
		}

		do_paragraph(c, d, pinfo);

		de_free(c, pinfo);
		pinfo = NULL;
		de_dbg_indent(c, -1);
	}

	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x19140
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x91104(%rip), %rsi     # 0x1cd49f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x7f, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x910dc(%rip), %rsi     # 0x1cd4b9
movb $0x0, %al
callq 0x15b0d0
cmpq $0x14, -0x28(%rbp)
jle 0x13c3f3
movq $0x14, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165540
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x910c0(%rip), %rsi     # 0x1cd4d9
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x13c6c7
movq $0x0, -0xc8(%rbp)
movq -0x38(%rbp), %rax
imulq $0x6, -0x30(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x38, %esi
callq 0x15b780
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0xe8(%rbp), %rax
movl %eax, %ecx
leaq 0x9104e(%rip), %rsi     # 0x1cd4e5
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0xe8(%rbp), %rsi
callq 0x165540
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jle 0x13c4f5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x40(%rbp), %rcx
movq -0xc8(%rbp), %rax
movq %rcx, (%rax)
movq -0xd8(%rbp), %rcx
subq -0x40(%rbp), %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rax
movl %eax, %edx
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0xd8(%rbp), %rax
subq $0x1, %rax
movl %eax, %r8d
leaq 0x90fac(%rip), %rsi     # 0x1cd4f3
movb $0x0, %al
callq 0x15b0d0
movq -0xd8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0xe8(%rbp), %rsi
addq $0x4, %rsi
callq 0x165280
movq %rax, -0xe0(%rbp)
cmpq $0xffff, -0xe0(%rbp) # imm = 0xFFFF
jne 0x13c5a5
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movl %eax, %edx
leaq 0x90f7e(%rip), %rsi     # 0x1cd517
movb $0x0, %al
callq 0x15b0d0
jmp 0x13c679
movq -0x38(%rbp), %rcx
addq -0xe0(%rbp), %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %r8d
leaq 0x90f46(%rip), %rsi     # 0x1cd529
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
cmpq $0x80, -0xe0(%rbp)
jge 0x13c66b
movq -0xe0(%rbp), %rax
cmpb $0x0, -0xc0(%rbp,%rax)
je 0x13c631
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movl %eax, %edx
leaq 0x90f16(%rip), %rsi     # 0x1cd540
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
movq -0xe0(%rbp), %rax
movzbl -0xc0(%rbp,%rax), %r8d
callq 0x13c6e0
movq -0xe0(%rbp), %rax
movb $0x1, -0xc0(%rbp,%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x13c8c0
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x15b820
movq $0x0, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x13c43c
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0xf0, %rsp
popq %rbp
retq
nop