// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/installshld.c
// Function: is_sfx_main
static void is_sfx_main(deark *c, struct ishieldsfxdata *d)
{
	de_finfo *fi = NULL;
	i64 i;
	i64 pos;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "rsrc pos: %"I64_FMT", len=%"I64_FMT, d->rsrc_pos, d->rsrc_len);
	if(d->rsrc_len<16) goto done;
	de_dbg_indent(c, 1);
	d->data_pos = de_getu32le(d->rsrc_pos+8);
	de_dbg(c, "data seg pos: %"I64_FMT, d->data_pos);
	d->num_member_files = de_getu32le(d->rsrc_pos+12);
	de_dbg(c, "num members: %"I64_FMT, d->num_member_files);

	// Sometimes @+16 is file size (or more likely, the data segment end pos).
	// But not always.
	d->data_endpos = c->infile->len;
	if(d->data_endpos > c->infile->len) {
		d->need_errmsg = 1;
		goto done;
	}
	de_dbg_indent(c, -1);

	fi = de_finfo_create(c);
	fi->original_filename_flag = 1;
	pos = d->data_pos;

	for(i=0; i<d->num_member_files; i++) {
		i64 hdr1_dlen;
		i64 member_dlen;
		i64 member_dpos;

		de_dbg(c, "member %u at %"I64_FMT, (UI)i, pos);
		de_dbg_indent(c, 1);

		if(pos+12 > d->data_endpos) {
			d->need_errmsg = 1;
			goto done;
		}

		hdr1_dlen = de_getu32le_p(&pos);
		de_dbg(c, "hdr1 dlen: %"I64_FMT, hdr1_dlen);
		// If this is large, assume we've gone off the rails.
		// Have observed values from 9 to 77.
		if(hdr1_dlen > 1024) {
			d->need_errmsg = 1;
			goto done;
		}

		pos += hdr1_dlen;
		pos += 4; // unknown
		member_dlen = de_getu32le_p(&pos);
		member_dpos = pos;
		de_dbg(c, "member dpos: %"I64_FMT, member_dpos);
		de_dbg(c, "member dlen: %"I64_FMT, member_dlen);

		pos = member_dpos + member_dlen;
		if(pos > d->data_endpos) {
			d->need_errmsg = 1;
			goto done;
		}

		is_sfx_acquire_filename(c, d, i, member_dpos, member_dlen, fi);

		dbuf_create_file_from_slice(c->infile, member_dpos, member_dlen, NULL, fi, 0);
		de_dbg_indent(c, -1);
	}

done:
	de_finfo_destroy(c, fi);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0xce7ee(%rip), %rsi     # 0x1be3fe
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x10, 0x10(%rax)
jge 0xefc27
jmp 0xefe9b
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x8, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0xce7a9(%rip), %rsi     # 0x1be415
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0xc, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0xce77d(%rip), %rsi     # 0x1be427
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xefce7
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0xefe9b
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jge 0xefe99
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x28(%rbp), %rcx
leaq 0xce6f3(%rip), %rsi     # 0x1be438
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rax
addq $0xc, %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jle 0xefd78
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0xefe9b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0xce6ad(%rip), %rsi     # 0x1be449
movb $0x0, %al
callq 0x15b0d0
cmpq $0x400, -0x38(%rbp)     # imm = 0x400
jle 0xefdb9
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0xefe9b
movq -0x38(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
leaq 0xce65b(%rip), %rsi     # 0x1be458
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xce656(%rip), %rsi     # 0x1be469
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jle 0xefe3d
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0xefe9b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x18(%rbp), %r9
callq 0xefec0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x18(%rbp), %r8
xorl %eax, %eax
movl %eax, %ecx
xorl %r9d, %r9d
callq 0x166be0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xefd1e
jmp 0xefe9b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)