// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/palmpdb.c
// Function: do_read_prc_record
static int do_read_prc_record(deark *c, lctx *d, i64 rec_idx, i64 pos1)
{
	u32 id;
	struct de_fourcc rsrc_type_4cc;
	i64 data_offs;
	i64 data_len;
	int always_extract = 0;
	de_ucstring *ext_ucstring = NULL;
	int ext_set = 0;
	const char *rsrc_type_descr;
	const struct rsrc_type_info_struct *rti;

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

	dbuf_read_fourcc(c->infile, pos1, &rsrc_type_4cc, 4, 0x0);
	rti = get_rsrc_type_info(rsrc_type_4cc.id);
	if(rti && rti->descr) rsrc_type_descr = rti->descr;
	else rsrc_type_descr = "?";
	de_dbg(c, "resource type: '%s' (%s)", rsrc_type_4cc.id_dbgstr, rsrc_type_descr);

	ext_ucstring = ucstring_create(c);
	// The "filename" always starts with the fourcc.
	ucstring_append_sz(ext_ucstring, rsrc_type_4cc.id_sanitized_sz, DE_ENCODING_LATIN1);

	id = (u32)de_getu16be(pos1+4);
	de_dbg(c, "id: %d", (int)id);

	data_offs = (i64)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);

	switch(rsrc_type_4cc.id) {
	case CODE_Tbmp:
		ucstring_append_sz(ext_ucstring, ".palm", DE_ENCODING_LATIN1);
		ext_set = 1;
		always_extract = 1;
		break;
		// TODO: tbmf, taif
	case CODE_tAIB:
		if(d->icon_name && c->filenames_from_file) {
			ucstring_append_sz(ext_ucstring, ".", DE_ENCODING_LATIN1);
			ucstring_append_ucstring(ext_ucstring, d->icon_name);
		}
		ucstring_append_sz(ext_ucstring, ".palm", DE_ENCODING_LATIN1);
		ext_set = 1;
		always_extract = 1;
		break;
	case CODE_tAIN:
		do_string_rsrc(c, d, data_offs, data_len, rti,
			(d->rec_list.icon_name_count==1)?0x1:0x0);
		break;
	case CODE_tAIS:
	case CODE_tSTR:
	case CODE_tver:
		do_string_rsrc(c, d, data_offs, data_len, rti, 0);
		break;
	}

	if(!ext_set) {
		ucstring_append_sz(ext_ucstring, ".bin", DE_ENCODING_LATIN1);
	}
	extract_item(c, d, data_offs, data_len, NULL, ext_ucstring, 0, always_extract);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x6c(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0xbfb83(%rip), %rsi     # 0x1bf7cb
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
leaq -0x54(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movl -0x50(%rbp), %edi
callq 0x1002f0
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0xffcb5
movq -0x90(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xffcb5
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0xffcc3
leaq 0xb7f71(%rip), %rax     # 0x1b7c2d
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rdx
movq -0x88(%rbp), %rcx
leaq 0xc1460(%rip), %rsi     # 0x1c1139
xorl %eax, %eax
movb %al, -0x95(%rbp)
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
movl $0x5, %edx
callq 0x1715e0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x1651d0
movq %rax, %rcx
movb -0x95(%rbp), %al
movl %ecx, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0xb6a39(%rip), %rsi     # 0x1b676d
callq 0x15b0d0
movb -0x95(%rbp), %al
movq -0x10(%rbp), %rcx
movq 0xa8(%rcx), %rcx
movq -0x18(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movq %rcx, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %edx
leaq 0x9fd48(%rip), %rsi     # 0x19faab
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x100350
movq %rax, %rcx
movb -0x95(%rbp), %al
movq %rcx, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movl -0x68(%rbp), %edx
leaq 0xc13be(%rip), %rsi     # 0x1c1152
callq 0x15b0d0
movl -0x50(%rbp), %eax
movl %eax, -0x94(%rbp)
subl $0x54626d70, %eax       # imm = 0x54626D70
je 0xffe09
jmp 0xffdab
movl -0x94(%rbp), %eax
subl $0x74414942, %eax       # imm = 0x74414942
je 0xffe31
jmp 0xffdba
movl -0x94(%rbp), %eax
subl $0x7441494e, %eax       # imm = 0x7441494E
je 0xffe9d
jmp 0xffdcd
movl -0x94(%rbp), %eax
subl $0x74414953, %eax       # imm = 0x74414953
je 0xffed6
jmp 0xffde0
movl -0x94(%rbp), %eax
subl $0x74535452, %eax       # imm = 0x74535452
je 0xffed6
jmp 0xffdf3
movl -0x94(%rbp), %eax
subl $0x74766572, %eax       # imm = 0x74766572
je 0xffed6
jmp 0xffef5
movq -0x78(%rbp), %rdi
leaq 0xc1597(%rip), %rsi     # 0x1c13ab
movl $0x5, %edx
callq 0x1715e0
movl $0x1, -0x7c(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0xffef5
movq -0x10(%rbp), %rax
cmpq $0x0, 0xc0(%rax)
je 0xffe78
movq -0x8(%rbp), %rax
movzbl 0xd0(%rax), %eax
cmpl $0x0, %eax
je 0xffe78
movq -0x78(%rbp), %rdi
leaq 0xc7349(%rip), %rsi     # 0x1c71a3
movl $0x5, %edx
callq 0x1715e0
movq -0x78(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xc0(%rax), %rsi
callq 0x171460
movq -0x78(%rbp), %rdi
leaq 0xc1528(%rip), %rsi     # 0x1c13ab
movl $0x5, %edx
callq 0x1715e0
movl $0x1, -0x7c(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0xffef5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x90(%rbp), %r8
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %r10
xorl %r9d, %r9d
movl $0x1, %eax
cmpq $0x1, %r10
cmovel %eax, %r9d
callq 0x1003d0
jmp 0xffef5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x90(%rbp), %r8
xorl %r9d, %r9d
callq 0x1003d0
cmpl $0x0, -0x7c(%rbp)
jne 0xfff10
movq -0x78(%rbp), %rdi
leaq 0xc1300(%rip), %rsi     # 0x1c1206
movl $0x5, %edx
callq 0x1715e0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x78(%rbp), %r9
movl -0x6c(%rbp), %eax
xorl %r8d, %r8d
xorl %r10d, %r10d
movl $0x0, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x100500
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x78(%rbp), %rdi
callq 0x171750
movl $0x1, %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)