// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
testq %r8, %r8
je 0xae985
movups %xmm0, (%rbx)
movq 0x18(%r15), %rdi
movq %r12, %rsi
callq 0xeed0d
testq %rax, %rax
je 0xaeafb
movq %rax, %r13
leaq 0x86beb(%rip), %rsi     # 0x13558f
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x8(%r14), %eax
cmpl $0x1, %eax
ja 0xaea07
movq %rsp, %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0xea8ff
leaq 0x10(%rsp), %rsi
movl $0x40, %edx
movq %rbp, %rdi
movq %rsi, %rbp
xorl %ecx, %ecx
callq 0xeaf46
leaq 0x86ba4(%rip), %rsi     # 0x135597
movq %r15, %rdi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe8617
movl 0x8(%r14), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0xaea7a
movq 0x18(%r15), %rdi
movq %r12, %rsi
callq 0xeedae
movq %rax, %r13
movq %rsp, %rsi
movq %rax, %rdi
movl $0x1, %edx
callq 0xea7f5
movl 0x8(%r14), %eax
cmpl $0x2, %eax
je 0xaea4c
cmpb $0x0, (%rsp)
je 0xaea7e
movq %rsp, %rdi
callq 0xeacfd
cmpq $0x1c374a80, %rax       # imm = 0x1C374A80
jl 0xaea7a
movq %rsp, %rdi
leaq 0x10(%rsp), %rbp
movl $0x40, %edx
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xeaf46
leaq 0x86b45(%rip), %rsi     # 0x1355af
movq %r15, %rdi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe8617
movl 0x8(%r14), %eax
cmpl $0x3, %eax
je 0xaea87
testl %eax, %eax
jne 0xaeaec
movq 0x18(%r15), %rdi
movq %r12, %rsi
callq 0xeed61
movq %rax, %r12
movq %rsp, %rsi
movq %rax, %rdi
callq 0xea8ff
cmpl $0x3, 0x8(%r14)
je 0xaeabe
cmpb $0x0, (%rsp)
je 0xaeaec
movq %rsp, %rdi
callq 0xeacfd
cmpq $0x1c374a80, %rax       # imm = 0x1C374A80
jl 0xaeaec
movq %rsp, %rdi
leaq 0x10(%rsp), %r13
movl $0x40, %edx
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xeaf46
leaq 0x86aec(%rip), %rsi     # 0x1355c8
movq %r15, %rdi
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0xaeb0f
leaq 0x86a7d(%rip), %rsi     # 0x13557f
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
testq %rbx, %rbx
je 0xaeb22
cmpl $0x0, 0x8(%r14)
je 0xaeb22
movaps (%rsp), %xmm0
movups %xmm0, (%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq