// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/palmpdb.c
// Function: do_read_pdb_prc_header
static int do_read_pdb_prc_header(deark *c, lctx *d)
{
	i64 pos1 = 0;
	de_ucstring *dname = NULL;
	de_ucstring *attr_descr = NULL;
	u32 attribs;
	u32 version;
	i64 x;
	int retval = 0;

	de_dbg(c, "header at %d", (int)pos1);
	de_dbg_indent(c, 1);

	dname = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos1, 32, dname, DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_PALM);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz(dname));

	attribs = (u32)de_getu16be(pos1+32);
	if(attribs & 0x0001) {
		d->file_fmt = FMT_PRC;
	}
	else {
		d->file_fmt = FMT_PDB;
	}
	attr_descr = ucstring_create(c);
	get_db_attr_descr(attr_descr, attribs);
	de_dbg(c, "attributes: 0x%04x (%s)", (unsigned int)attribs,
		ucstring_getpsz(attr_descr));

	version = (u32)de_getu16be(pos1+34);
	de_dbg(c, "version: 0x%04x", (unsigned int)version);

	handle_palm_timestamp(c, d, pos1+36, "create date", NULL);
	handle_palm_timestamp(c, d, pos1+40, "mod date", &d->mod_time);
	handle_palm_timestamp(c, d, pos1+44, "backup date", NULL);

	x = de_getu32be(pos1+48);
	de_dbg(c, "mod number: %d", (int)x);
	d->appinfo_offs = de_getu32be(pos1+52);
	de_dbg(c, "app info pos: %d", (int)d->appinfo_offs);
	d->sortinfo_offs = de_getu32be(pos1+56);
	de_dbg(c, "sort info pos: %d", (int)d->sortinfo_offs);

	dbuf_read_fourcc(c->infile, pos1+60, &d->dtype4cc, 4, 0x0);
	de_dbg(c, "type: \"%s\"", d->dtype4cc.id_dbgstr);

	dbuf_read_fourcc(c->infile, pos1+64, &d->creator4cc, 4, 0x0);
	de_dbg(c, "creator: \"%s\"", d->creator4cc.id_dbgstr);

	if(d->file_fmt==FMT_PDB) {
		d->fmt_shortname = "PDB";
		if(d->dtype4cc.id==CODE_pqa && d->creator4cc.id==CODE_clpr) {
			d->file_subfmt = SUBFMT_PQA;
			de_declare_fmt(c, "Palm PQA");
		}
		else if(d->dtype4cc.id==CODE_vIMG && d->creator4cc.id==CODE_View) {
			d->file_subfmt = SUBFMT_IMAGEVIEWER;
			de_declare_fmt(c, "Palm Database ImageViewer");
		}
		else {
			de_declare_fmt(c, "Palm PDB");
		}
	}
	else if(d->file_fmt==FMT_PRC) {
		d->fmt_shortname = "PRC";
		de_declare_fmt(c, "Palm PRC");
	}
	else {
		goto done;
	}

	x = de_getu32be(68);
	de_dbg(c, "uniqueIDseed: %u", (unsigned int)x);

	retval = 1;
done:
	de_dbg_indent(c, -1);
	ucstring_destroy(dname);
	ucstring_destroy(attr_descr);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xc631e(%rip), %rsi     # 0x1c4f8e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x20, %edx
movl $0x1, %r8d
movl $0x13, %r9d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rdi
callq 0x172500
movq -0x48(%rbp), %rdi
movq %rax, %rdx
leaq 0xaf4f9(%rip), %rsi     # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
callq 0x1651d0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xfed0d
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
jmp 0xfed17
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xff550
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x172500
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %edx
movq %rax, %rcx
leaq 0xd0665(%rip), %rsi     # 0x1cf3bd
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x22, %rsi
callq 0x1651d0
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
leaq 0xc20be(%rip), %rsi     # 0x1c0e43
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x24, %rdx
leaq 0xad90e(%rip), %rcx     # 0x1ac6b1
xorl %eax, %eax
movl %eax, %r8d
callq 0xff600
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x28, %rdx
movq -0x10(%rbp), %r8
addq $0x80, %r8
leaq 0xad8f8(%rip), %rcx     # 0x1ac6c7
callq 0xff600
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x2c, %rdx
leaq 0xa3c4a(%rip), %rcx     # 0x1a2a35
xorl %eax, %eax
movl %eax, %r8d
callq 0xff600
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x30, %rsi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xc2034(%rip), %rsi     # 0x1c0e53
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x34, %rsi
callq 0x165470
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movl %eax, %edx
leaq 0xc2001(%rip), %rsi     # 0x1c0e62
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
callq 0x165470
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movl %eax, %edx
leaq 0xc1fd0(%rip), %rsi     # 0x1c0e73
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x3c, %rsi
movq -0x10(%rbp), %rdx
addq $0x20, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x20, %rdx
addq $0x10, %rdx
leaq 0xb484d(%rip), %rsi     # 0x1b3733
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x40, %rsi
movq -0x10(%rbp), %rdx
addq $0x50, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x50, %rdx
addq $0x10, %rdx
leaq 0xa37d1(%rip), %rsi     # 0x1a26fa
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0xfefce
movq -0x10(%rbp), %rax
leaq 0xc1f65(%rip), %rcx     # 0x1c0ead
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x70716120, 0x24(%rax) # imm = 0x70716120
jne 0xfef83
movq -0x10(%rbp), %rax
cmpl $0x636c7072, 0x54(%rax) # imm = 0x636C7072
jne 0xfef83
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x8(%rbp), %rdi
leaq 0xc1f09(%rip), %rsi     # 0x1c0e85
callq 0x15e380
jmp 0xfefcc
movq -0x10(%rbp), %rax
cmpl $0x76494d47, 0x24(%rax) # imm = 0x76494D47
jne 0xfefba
movq -0x10(%rbp), %rax
cmpl $0x56696577, 0x54(%rax) # imm = 0x56696577
jne 0xfefba
movq -0x10(%rbp), %rax
movl $0x2, 0x4(%rax)
movq -0x8(%rbp), %rdi
leaq 0xc1edb(%rip), %rsi     # 0x1c0e8e
callq 0x15e380
jmp 0xfefca
movq -0x8(%rbp), %rdi
leaq 0xc1ee3(%rip), %rsi     # 0x1c0ea8
callq 0x15e380
jmp 0xfefcc
jmp 0xfeffc
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0xfeff8
movq -0x10(%rbp), %rax
leaq 0xc1ed4(%rip), %rcx     # 0x1c0eb6
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
leaq 0xc1ec0(%rip), %rsi     # 0x1c0eb1
callq 0x15e380
jmp 0xfeffa
jmp 0xff031
jmp 0xfeffc
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x44, %esi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xc1e97(%rip), %rsi     # 0x1c0eba
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x20(%rbp), %rdi
callq 0x171750
movq -0x28(%rbp), %rdi
callq 0x171750
movl -0x3c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)