// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/palmpdb.c
// Function: do_read_pdb_record
static int do_read_pdb_record(deark *c, lctx *d, i64 rec_idx, i64 pos1)
{
	i64 data_offs;
	u8 attribs;
	u32 id;
	i64 data_len;
	de_ucstring *attr_descr = NULL;
	char extfull[80];

	de_dbg(c, "record[%d] at %d", (int)rec_idx, (int)pos1);
	de_dbg_indent(c, 1);

	data_offs = (int)d->rec_list.rec_data[rec_idx].offset;
	de_dbg(c, "data pos: %d", (int)data_offs);

	data_len = calc_rec_len(c, d, rec_idx);
	de_dbg(c, "calculated len: %d", (int)data_len);

	de_snprintf(extfull, sizeof(extfull), "rec%d.bin", (int)rec_idx); // May be overridden

	{
		const char *idname = NULL;
		char tmpstr[80];

		attribs = de_getbyte(pos1+4);
		attr_descr = ucstring_create(c);
		get_rec_attr_descr(attr_descr, attribs);
		de_dbg(c, "attributes: 0x%02x (%s)", (unsigned int)attribs,
			ucstring_getpsz(attr_descr));

		id = (de_getbyte(pos1+5)<<16) |
			(de_getbyte(pos1+6)<<8) |
			(de_getbyte(pos1+7));

		if(d->file_subfmt==SUBFMT_IMAGEVIEWER) {
			if(id==0x6f8000) idname = "image record";
			else if(id==0x6f8001) idname = "text record";
			else idname = "?";
		}
		if(idname)
			de_snprintf(tmpstr, sizeof(tmpstr), " (%s)", idname);
		else
			tmpstr[0] = '\0';

		de_dbg(c, "id: %u (0x%06x)%s", (unsigned int)id, (unsigned int)id, tmpstr);

		if(d->has_nonzero_ids) {
			de_snprintf(extfull, sizeof(extfull), "%06x.bin", (unsigned int)id);
		}

		if(d->file_subfmt==SUBFMT_IMAGEVIEWER) {
			if(id==0x6f8000) do_imgview_image(c, d, data_offs, data_len);
			else if(id==0x6f8001) do_imgview_text(c, d, data_offs, data_len);
		}
	}

	extract_item(c, d, data_offs, data_len, extfull, NULL, 0, 0);

	de_dbg_indent(c, -1);
	ucstring_destroy(attr_descr);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0xbf821(%rip), %rsi     # 0x1bf7cb
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x9fac4(%rip), %rsi     # 0x19faab
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x100350
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xc113e(%rip), %rsi     # 0x1c1152
movb $0x0, %al
callq 0x15b0d0
leaq -0x90(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %ecx
movl $0x50, %esi
leaq 0xc11cd(%rip), %rdx     # 0x1c1201
movb $0x0, %al
callq 0x15a980
movq $0x0, -0x98(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movzbl -0x29(%rbp), %esi
callq 0x1005f0
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
movzbl -0x29(%rbp), %eax
movl %eax, -0xfc(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172500
movq -0x108(%rbp), %rdi
movl -0xfc(%rbp), %edx
movq %rax, %rcx
leaq 0xba7df(%rip), %rsi     # 0x1ba88c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x5, %rsi
callq 0x165060
movzbl %al, %eax
shll $0x10, %eax
movl %eax, -0xf8(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
callq 0x165060
movb %al, %cl
movl -0xf8(%rbp), %eax
movzbl %cl, %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, -0xf4(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x7, %rsi
callq 0x165060
movb %al, %cl
movl -0xf4(%rbp), %eax
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x100173
cmpl $0x6f8000, -0x30(%rbp)  # imm = 0x6F8000
jne 0x100148
leaq 0xc10cc(%rip), %rax     # 0x1c120b
movq %rax, -0x98(%rbp)
jmp 0x100171
cmpl $0x6f8001, -0x30(%rbp)  # imm = 0x6F8001
jne 0x100161
leaq 0xc10c0(%rip), %rax     # 0x1c1218
movq %rax, -0x98(%rbp)
jmp 0x10016f
leaq 0xb7ac5(%rip), %rax     # 0x1b7c2d
movq %rax, -0x98(%rbp)
jmp 0x100171
jmp 0x100173
cmpq $0x0, -0x98(%rbp)
je 0x1001a0
leaq -0xf0(%rbp), %rdi
movq -0x98(%rbp), %rcx
movl $0x50, %esi
leaq 0xb7753(%rip), %rdx     # 0x1b78ea
movb $0x0, %al
callq 0x15a980
jmp 0x1001a7
movb $0x0, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq -0xf0(%rbp), %r8
leaq 0xc1065(%rip), %rsi     # 0x1c1224
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1001ed
leaq -0x90(%rbp), %rdi
movl -0x30(%rbp), %ecx
movl $0x50, %esi
leaq 0xc1050(%rip), %rdx     # 0x1c1236
movb $0x0, %al
callq 0x15a980
movq -0x10(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x100239
cmpl $0x6f8000, -0x30(%rbp)  # imm = 0x6F8000
jne 0x100217
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x1006a0
jmp 0x100237
cmpl $0x6f8001, -0x30(%rbp)  # imm = 0x6F8001
jne 0x100235
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x100be0
jmp 0x100237
jmp 0x100239
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x90(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
xorl %eax, %eax
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x100500
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x40(%rbp), %rdi
callq 0x171750
movl $0x1, %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq