// File: /workspace/github_c_makefile_star2_O1/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 0xaf3e3
movups %xmm0, (%rbx)
movq 0x18(%r15), %rdi
movq %r12, %rsi
callq 0xef32a
testq %rax, %rax
je 0xaf554
movq %rax, %r13
leaq 0x85e01(%rip), %rsi     # 0x135203
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r15, %rdi
movl $0x1, %esi
callq 0xe9585
cmpl $0x1, 0x8(%r14)
ja 0xaf45f
movq %rsp, %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0xeae04
leaq 0x10(%rsp), %rsi
movl $0x40, %edx
movq %rbp, %rdi
movq %rsi, %rbp
xorl %ecx, %ecx
callq 0xeb4f8
leaq 0x85dbc(%rip), %rsi     # 0x13520b
movq %r15, %rdi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe9226
testl $0xfffffffd, 0x8(%r14)  # imm = 0xFFFFFFFD
jne 0xaf4d3
movq 0x18(%r15), %rdi
movq %r12, %rsi
callq 0xef3cb
movq %rax, %r13
movq %rsp, %rsi
movq %rax, %rdi
movl $0x1, %edx
callq 0xeace2
cmpl $0x2, 0x8(%r14)
je 0xaf4a5
cmpb $0x0, (%rsp)
je 0xaf4d3
movq %rsp, %rdi
callq 0xeb296
cmpq $0x1c374a80, %rax       # imm = 0x1C374A80
jl 0xaf4d3
movq %rsp, %rdi
leaq 0x10(%rsp), %rbp
movl $0x40, %edx
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
leaq 0x85d60(%rip), %rsi     # 0x135223
movq %r15, %rdi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe9226
movl 0x8(%r14), %eax
cmpl $0x3, %eax
je 0xaf4e0
testl %eax, %eax
jne 0xaf545
movq 0x18(%r15), %rdi
movq %r12, %rsi
callq 0xef37e
movq %rax, %r12
movq %rsp, %rsi
movq %rax, %rdi
callq 0xeae04
cmpl $0x3, 0x8(%r14)
je 0xaf517
cmpb $0x0, (%rsp)
je 0xaf545
movq %rsp, %rdi
callq 0xeb296
cmpq $0x1c374a80, %rax       # imm = 0x1C374A80
jl 0xaf545
movq %rsp, %rdi
leaq 0x10(%rsp), %r13
movl $0x40, %edx
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
leaq 0x85d07(%rip), %rsi     # 0x13523c
movq %r15, %rdi
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
jmp 0xaf568
leaq 0x85c98(%rip), %rsi     # 0x1351f3
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
testq %rbx, %rbx
je 0xaf57b
cmpl $0x0, 0x8(%r14)
je 0xaf57b
movaps (%rsp), %xmm0
movups %xmm0, (%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq