// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/palmpdb.c
// Function: handle_palm_timestamp
static void handle_palm_timestamp(deark *c, lctx *d, i64 pos, const char *name,
	struct de_timestamp *returned_ts)
{
	struct de_timestamp ts;
	char timestamp_buf[64];
	i64 ts_int;

	de_zeromem(&ts, sizeof(struct de_timestamp));
	if(returned_ts) {
		de_zeromem(returned_ts, sizeof(struct de_timestamp));
	}

	ts_int = de_getu32be(pos);
	if(ts_int==0) {
		de_dbg(c, "%s: 0 (not set)", name);
		goto done;
	}

	de_dbg(c, "%s: ...", name);
	de_dbg_indent(c, 1);

	// I've seen three different ways to interpret this 32-bit timestamp, and
	// I don't know how to guess the correct one.

	if(d->timestampfmt==TIMESTAMPFMT_MACBE || d->timestampfmt==TIMESTAMPFMT_UNKNOWN) {
		de_mac_time_to_timestamp(ts_int, &ts);
		de_timestamp_to_string(&ts, timestamp_buf, sizeof(timestamp_buf), 0);
		de_dbg(c, "... if Mac-BE: %"I64_FMT" (%s)", ts_int, timestamp_buf);
	}

	if(d->timestampfmt==TIMESTAMPFMT_UNIXBE || d->timestampfmt==TIMESTAMPFMT_UNKNOWN) {
		ts_int = de_geti32be(pos);
		de_unix_time_to_timestamp(ts_int, &ts, 0x1);
		if(d->timestampfmt==TIMESTAMPFMT_UNIXBE || timestamp_is_plausible(&ts)) {
			de_timestamp_to_string(&ts, timestamp_buf, sizeof(timestamp_buf), 0);
			de_dbg(c, "... if Unix-BE: %"I64_FMT" (%s)", ts_int, timestamp_buf);
		}
	}

	if(d->timestampfmt==TIMESTAMPFMT_MACLE || d->timestampfmt==TIMESTAMPFMT_UNKNOWN) {
		ts_int = de_getu32le(pos);
		de_mac_time_to_timestamp(ts_int, &ts);
		if(d->timestampfmt==TIMESTAMPFMT_MACLE || timestamp_is_plausible(&ts)) {
			de_timestamp_to_string(&ts, timestamp_buf, sizeof(timestamp_buf), 0);
			de_dbg(c, "... if Mac-LE: %"I64_FMT" (%s)", ts_int, timestamp_buf);
		}
	}

	de_dbg_indent(c, -1);

done:
	if(returned_ts && d->timestampfmt!=TIMESTAMPFMT_UNKNOWN) {
		*returned_ts = ts;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x19140
cmpq $0x0, -0x28(%rbp)
je 0xff646
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x19140
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165470
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jne 0xff683
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0xc1952(%rip), %rsi     # 0x1c0fc9
movb $0x0, %al
callq 0x15b0d0
jmp 0xff81d
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0xc1947(%rip), %rsi     # 0x1c0fd9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
cmpl $0x1, 0x8(%rax)
je 0xff6bb
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xff6fc
movq -0x88(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x15d720
leaq -0x80(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0x15e130
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0xc18ec(%rip), %rsi     # 0x1c0fe1
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x8(%rax)
je 0xff710
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xff788
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x1655d0
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x15d530
movq -0x10(%rbp), %rax
cmpl $0x2, 0x8(%rax)
je 0xff755
leaq -0x38(%rbp), %rdi
callq 0xff850
cmpl $0x0, %eax
je 0xff786
leaq -0x80(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0x15e130
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0xc187a(%rip), %rsi     # 0x1c0ff9
movb $0x0, %al
callq 0x15b0d0
jmp 0xff788
movq -0x10(%rbp), %rax
cmpl $0x3, 0x8(%rax)
je 0xff79c
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xff80f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165540
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x15d720
movq -0x10(%rbp), %rax
cmpl $0x3, 0x8(%rax)
je 0xff7dc
leaq -0x38(%rbp), %rdi
callq 0xff850
cmpl $0x0, %eax
je 0xff80d
leaq -0x80(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0x15e130
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0xc180c(%rip), %rsi     # 0x1c1012
movb $0x0, %al
callq 0x15b0d0
jmp 0xff80f
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpq $0x0, -0x28(%rbp)
je 0xff841
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xff841
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x8(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)