// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/exe.c
// Function: do_ne_rsrc_tbl
static void do_ne_rsrc_tbl(deark *c, lctx *d)
{
	i64 pos;
	i64 npos;
	i64 x;
	i64 i;
	i64 j;
	i64 rsrc_count;
	i64 tot_resources = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	pos = d->ne_rsrc_tbl_offset;

	de_dbg(c, "resource table at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	d->ne_rcalign_shift = (UI)de_getu16le(pos);
	de_dbg(c, "rscAlignShift: %u", d->ne_rcalign_shift);
	pos += 2;
	if(d->ne_rcalign_shift>24) {
		de_dbg(c, "[Unknown resource format or bad rscAlignShift; "
			"can't decode this resource table]");
		goto done;
	}

	i = 0;
	while(1) {
		x = de_getu16le(pos);
		if(x==0) {
			// A "type_id" of 0 marks the end of the array
			de_dbg(c, "end of TYPEINFO array found at %"I64_FMT, pos);
			goto done;
		}
		de_dbg(c, "TYPEINFO #%d at %"I64_FMT, (int)i, pos);
		de_dbg_indent(c, 1);

		if(x & 0x8000) {
			d->ne_rsrc_type_id = (u32)(x-0x8000);
			d->ne_rsrc_type_info = get_rsrc_type_info(d->ne_rsrc_type_id);
			d->ne_have_type = 1;
		}
		else {
			// x represents a relative offset to a name in rscResourceNames.
			// TODO: Could the name ever be a standard type (e.g. "ICON"), that
			// we ought to support?
			d->ne_rsrc_type_id = 0;
			d->ne_rsrc_type_info = NULL;
			d->ne_have_type = 0;
			// name_offset = d->ne_rsrc_tbl_offset + x;
		}

		rsrc_count = de_getu16le(pos+2);
		if(d->ne_have_type)
			de_dbg(c, "resource type=%d, count=%d", (int)d->ne_rsrc_type_id, (int)rsrc_count);
		else
			de_dbg(c, "resource type=?, count=%d", (int)rsrc_count);

		tot_resources += rsrc_count;

		if(tot_resources>MAX_RESOURCES) {
			de_err(c, "Too many resources, or invalid resource table.");
			goto done;
		}

		// Read the array of NAMEINFO structures.
		// (NAMEINFO seems like a misnomer to me. It contains data, not names.)
		for(j=0; j<rsrc_count; j++) {
			npos = pos+8 + j*12;
			do_ne_one_nameinfo(c, d, npos);
		}

		de_dbg_indent(c, -1);
		pos += 8 + 12*rsrc_count;
		i++;
	}

done:
	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, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x149aef(%rip), %rsi    # 0x1a91bf
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165280
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x68(%rax), %edx
leaq 0x149905(%rip), %rsi    # 0x1a9016
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x18, 0x68(%rax)
jbe 0x5f745
movq -0x8(%rbp), %rdi
leaq 0x1498ef(%rip), %rsi    # 0x1a9028
movb $0x0, %al
callq 0x15b0d0
jmp 0x5f912
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165280
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x5f784
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x149901(%rip), %rsi    # 0x1a9079
movb $0x0, %al
callq 0x15b0d0
jmp 0x5f912
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rcx
leaq 0x149903(%rip), %rsi    # 0x1a909c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rax
andq $0x8000, %rax           # imm = 0x8000
cmpq $0x0, %rax
je 0x5f7f5
movq -0x28(%rbp), %rax
subq $0x8000, %rax           # imm = 0x8000
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x10(%rbp), %rax
movl 0x70(%rax), %edi
callq 0x62250
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x6c(%rax)
jmp 0x5f817
movq -0x10(%rbp), %rax
movl $0x0, 0x70(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x6c(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
je 0x5f85b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x70(%rax), %edx
movq -0x40(%rbp), %rax
movl %eax, %ecx
leaq 0x14985e(%rip), %rsi    # 0x1a90b0
movb $0x0, %al
callq 0x15b0d0
jmp 0x5f873
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x14985f(%rip), %rsi    # 0x1a90cb
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x2710, -0x48(%rbp)    # imm = 0x2710
jle 0x5f89d
movq -0x8(%rbp), %rdi
leaq 0x149851(%rip), %rsi    # 0x1a90e5
movb $0x0, %al
callq 0x15bfb0
jmp 0x5f912
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x5f8e2
movq -0x18(%rbp), %rax
addq $0x8, %rax
imulq $0xc, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x62dc0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5f8a5
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
imulq $0xc, -0x40(%rbp), %rax
addq $0x8, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5f74d
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)