// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/zoo.c
// Function: do_global_header
static int do_global_header(deark *c, lctx *d, i64 pos1)
{
	i64 pos = pos1;
	int retval = 0;
	UI sig;
	u32 zoo_minus, zoo_minus_expected;
	i64 i;
	de_ucstring *txt = NULL;

	de_dbg(c, "archive header at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	// Intro text, e.g. "ZOO 2.10 Archive."
	// Zoo source code (zoo.h) says "The contents of the text message are [...]
	// not used by Zoo and they may be anything.".
	txt = ucstring_create(c);
	for(i=0; i<20; i++) {
		u8 ch;

		ch = de_getbyte(pos+i);
		if(ch==26 || ch==0) break;
		if(ch<32 || ch>126) ch = '_';
		ucstring_append_char(txt, (de_rune)ch);
	}
	de_dbg(c, "header text: \"%s\"", ucstring_getpsz_d(txt));
	pos += 20;

	sig = (UI)de_getu32le_p(&pos);
	if (sig != ZOO_SIGNATURE) goto done;

	d->first_member_hdr_pos = de_getu32le_p(&pos);
	de_dbg(c, "first entry pos: %"I64_FMT, d->first_member_hdr_pos);

	zoo_minus = (u32)de_getu32le_p(&pos);
	de_dbg(c, "consistency check: 0x%08x", (UI)zoo_minus);
	zoo_minus_expected = (u32)((~(u32)d->first_member_hdr_pos)+(u32)1);
	if(zoo_minus!=zoo_minus_expected) {
		de_warn(c, "Archive header failed consistency check (is 0x%08x, expected 0x%08x)",
			(UI)zoo_minus, (UI)zoo_minus_expected);
	}

	// Note: The version number fields are sometimes erroneously documented as
	// "version made by" and "version needed to extract [all files]".
	d->majver = de_getbyte_p(&pos);
	d->minver = de_getbyte_p(&pos);
	de_dbg(c, "version needed to manipulate archive: %d.%d", (int)d->majver, (int)d->minver);

	// Fields that aren't present in old versions.
	if(d->first_member_hdr_pos > 34) {
		d->type = de_getbyte_p(&pos);
		de_dbg(c, "archive header format version (\"type\"): %u", (UI)d->type);
		// 1 is the only value here with a known meaning, but we'll accept some slightly
		// higher values, and assume they are backward-compatible.
		if(d->type<1 || d->type>5) {
			d->type = 0;
			goto after_ext_hdr;
		}

		d->archive_comment_pos = de_getu32le_p(&pos);
		d->archive_comment_len = de_getu16le_p(&pos);
		de_dbg(c, "archive comment pos: %"I64_FMT", len=%d", d->archive_comment_pos,
			(int)d->archive_comment_len);
		do_comment(c, d, d->archive_comment_pos, d->archive_comment_len, "archive comment",
			1, d->extract_comments_to_files);

		d->vdata = de_getbyte_p(&pos);
		de_dbg(c, "archive-level versioning settings (\"vdata\"): 0x%02x", (UI)d->vdata);
	}
after_ext_hdr:

	retval = 1;

done:
	ucstring_destroy(txt);
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x5feb8(%rip), %rsi     # 0x1aea62
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x14, -0x38(%rbp)
jge 0x14ec38
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq -0x38(%rbp), %rsi
callq 0x165060
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1a, %eax
je 0x14ec05
movzbl -0x41(%rbp), %eax
cmpl $0x0, %eax
jne 0x14ec07
jmp 0x14ec38
movzbl -0x41(%rbp), %eax
cmpl $0x20, %eax
jl 0x14ec19
movzbl -0x41(%rbp), %eax
cmpl $0x7e, %eax
jle 0x14ec1d
movb $0x5f, -0x41(%rbp)
movq -0x40(%rbp), %rdi
movzbl -0x41(%rbp), %esi
callq 0x1714c0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x14ebd4
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172650
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0x81a99(%rip), %rsi     # 0x1d06f0
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movl %eax, -0x28(%rbp)
cmpl $0xfdc4a7dc, -0x28(%rbp) # imm = 0xFDC4A7DC
je 0x14ec8c
jmp 0x14eea9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x81a47(%rip), %rsi     # 0x1d0702
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0x81a33(%rip), %rsi     # 0x1d0717
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
xorl $-0x1, %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x14ed1c
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq 0x81a1c(%rip), %rsi     # 0x1d0731
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x21(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x20(%rax), %edx
movq -0x10(%rbp), %rax
movzbl 0x21(%rax), %ecx
leaq 0x81a0b(%rip), %rsi     # 0x1d0776
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x22, 0x18(%rax)
jle 0x14eea0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x22(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x22(%rax), %edx
leaq 0x819f4(%rip), %rsi     # 0x1d07a2
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movzbl 0x22(%rax), %eax
cmpl $0x1, %eax
jl 0x14edcf
movq -0x10(%rbp), %rax
movzbl 0x22(%rax), %eax
cmpl $0x5, %eax
jle 0x14eddc
movq -0x10(%rbp), %rax
movb $0x0, 0x22(%rax)
jmp 0x14eea2
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
leaq 0x8199c(%rip), %rsi     # 0x1d07cd
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
leaq 0x81cf5(%rip), %r8      # 0x1d0b53
movl $0x1, %r9d
movl %eax, (%rsp)
callq 0x14f270
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x38(%rax), %edx
leaq 0x81955(%rip), %rsi     # 0x1d07ee
movb $0x0, %al
callq 0x15b0d0
jmp 0x14eea2
movl $0x1, -0x24(%rbp)
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x24(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)