// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/exe.c
// Function: do_pe_resource_dir_table
static void do_pe_resource_dir_table(deark *c, lctx *d, i64 rel_pos, int level)
{
	i64 named_node_count;
	i64 unnamed_node_count;
	i64 node_count;
	i64 i;

	// 16-byte "Resource node header" a.k.a "Resource directory table"

	if(d->rsrc_errflag) goto done;

	if(level>3) {
		de_warn(c, "Resource tree too deep");
		goto done;
	}

	de_dbg(c, "resource directory table at %"I64_FMT"(%"I64_FMT"), level=%d",
		(i64)(d->pe_cur_base_addr+rel_pos), rel_pos, level);

	named_node_count = de_getu16le(d->pe_cur_base_addr+rel_pos+12);
	unnamed_node_count = de_getu16le(d->pe_cur_base_addr+rel_pos+14);
	de_dbg(c, "number of node entries: named=%u, unnamed=%u", (UI)named_node_count,
		(UI)unnamed_node_count);

	node_count = named_node_count + unnamed_node_count;

	// An array of 8-byte "Resource node entries" follows the Resource node header.
	for(i=0; i<node_count; i++) {
		if(d->rsrc_errflag) goto done;
		do_pe_resource_node(c, d, rel_pos+16+8*i, level);
	}

done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x18(%rsp)
cmpb $0x0, 0x6(%rsi)
je 0x4704b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbp
movq 0x18(%rsp), %r8
cmpl $0x4, %r8d
jl 0x47078
leaq 0xd6165(%rip), %rsi     # 0x11d1c5
movq %rbp, %rdi
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8faa
movq %rdx, %r15
movq %rsi, %r12
movq 0xe8(%rsi), %rdx
addq %r15, %rdx
leaq 0xd614d(%rip), %rsi     # 0x11d1dc
movq %rbp, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbp), %rdi
movq 0xe8(%r12), %rax
leaq (%r15,%rax), %rsi
addq $0xc, %rsi
callq 0xeebc8
movq %rax, %r14
movq 0x18(%rbp), %rdi
movq 0xe8(%r12), %rax
leaq (%r15,%rax), %rsi
addq $0xe, %rsi
callq 0xeebc8
movq %rax, %rbx
leaq 0xd6130(%rip), %rsi     # 0x11d20b
movq %rbp, %rdi
movl %r14d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0xe8617
addq %r14, %rbx
movq %rbx, 0x30(%rsp)
jle 0x4703c
addq $0x10, %r15
movq 0x18(%rsp), %rax
incl %eax
movl %eax, 0x28(%rsp)
xorl %ebx, %ebx
movq %rbp, 0x20(%rsp)
movq %r15, 0x10(%rsp)
cmpb $0x0, 0x6(%r12)
jne 0x4703c
movq %rbp, %rdi
leaq 0x2c(%rsp), %rsi
callq 0xe8a1c
movq 0x118(%r12), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x118(%r12)
cmpq $0x2710, %rax           # imm = 0x2710
jl 0x47164
movq %rbp, %rdi
leaq 0xd60e6(%rip), %rsi     # 0x11d238
xorl %eax, %eax
callq 0xe9295
movb $0x1, 0x6(%r12)
jmp 0x47510
leaq (%r15,%rbx,8), %r14
movq 0x18(%rbp), %rdi
movq 0xe8(%r12), %rsi
addq %r14, %rsi
callq 0xeed61
movq %rax, %r15
movl %r15d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
testl %r15d, %r15d
cmovnsl %r15d, %r13d
movq 0x18(%rbp), %rdi
movq 0xe8(%r12), %rax
leaq (%r14,%rax), %rsi
addq $0x4, %rsi
callq 0xeed61
movq %rax, %rbp
addq $-0x80000000, %rax      # imm = 0x80000000
testl %ebp, %ebp
movq %rbp, %r10
movq %rax, 0x8(%rsp)
cmovsq %rax, %r10
movq 0x18(%rsp), %rdx
cmpl $0x1, %edx
jne 0x471fc
movl %r13d, 0x108(%r12)
xorl %eax, %eax
leaq 0x13a475(%rip), %rcx    # 0x181650
cmpl %r13d, (%rax,%rcx)
je 0x471f1
addq $0x18, %rax
cmpq $0x198, %rax            # imm = 0x198
jne 0x471db
xorl %eax, %eax
jmp 0x471f4
addq %rcx, %rax
movq %rax, 0x110(%r12)
movl %r15d, %r11d
shrl $0x1f, %r11d
movq %rbp, (%rsp)
shrl $0x1f, %ebp
movq 0xe8(%r12), %rcx
addq %r14, %rcx
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
leaq 0xd6026(%rip), %rsi     # 0x11d24b
movq %r14, %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %rbp
movq %rdi, %rbp
pushq %r11
pushq %r10
callq 0xe8617
addq $0x20, %rsp
addq 0xe8(%r12), %r14
movq 0x18(%rbp), %rax
cmpq 0x18(%rax), %r14
jle 0x47260
movb $0x1, 0x6(%r12)
movq 0x10(%rsp), %r15
jmp 0x47510
movq %rbp, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x108(%r12), %edx
cmpl $0x18, %edx
ja 0x47456
movl $0x100010e, %eax        # imm = 0x100010E
btl %edx, %eax
jae 0x47456
cmpl $0x2, 0x18(%rsp)
jne 0x472cd
testl %r15d, %r15d
movq (%rsp), %r14
jns 0x472d3
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
addq 0xf8(%r12), %r15
movq %r15, 0x100(%r12)
movq %rbp, %rdi
leaq 0xd5ffb(%rip), %rsi     # 0x11d2b8
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq (%rsp), %r14
jmp 0x472df
movq (%rsp), %r14
jge 0x472df
movq $0x0, 0x100(%r12)
testl %r14d, %r14d
movq 0x10(%rsp), %r15
jns 0x47302
movq %rbp, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
movl 0x28(%rsp), %ecx
callq 0x47023
jmp 0x47510
movq 0x110(%r12), %rax
testq %rax, %rax
je 0x47318
movq 0x8(%rax), %r9
testq %r9, %r9
jne 0x4731f
leaq 0xe4e32(%rip), %r9      # 0x12c151
movl 0x108(%r12), %r8d
movq 0xe8(%r12), %rdx
addq %r14, %rdx
movq %rbp, %rdi
leaq 0xd60a2(%rip), %rsi     # 0x11d3de
movq %r14, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbp, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbp), %rdi
movq 0xe8(%r12), %rsi
addq %r14, %rsi
callq 0xeed61
movq %rax, %r13
movq 0x18(%rbp), %rdi
movq 0xe8(%r12), %rax
leaq (%r14,%rax), %rsi
addq $0x4, %rsi
callq 0xeed61
movq %rbp, %rdi
leaq 0xd6083(%rip), %rsi     # 0x11d410
movq %r13, %rdx
movl %r13d, %ecx
movq %rax, (%rsp)
movq %rax, %r8
xorl %eax, %eax
callq 0xe8617
subq 0xf0(%r12), %r13
addq 0xf8(%r12), %r13
movq %rbp, %rdi
leaq 0xd6085(%rip), %rsi     # 0x11d440
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbp, %rdi
callq 0xea504
movq 0x100(%r12), %r14
testq %r14, %r14
je 0x474ab
movq %rax, 0x8(%rsp)
cmpb $0x0, 0xd0(%rbp)
je 0x4748e
movq 0x18(%rbp), %rdi
movq %r14, %rsi
callq 0xeebc8
movq %rbp, %rcx
testq %rax, %rax
jle 0x47493
movq %rax, %rbp
movq %rcx, %rdi
callq 0xf6410
movq %rax, %r15
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdi
addq $0x2, %r14
addq %rbp, %rbp
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
movl $0x3, %r9d
callq 0xefbd7
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xea53f
jmp 0x47499
movq 0x110(%r12), %rax
testq %rax, %rax
movq 0x10(%rsp), %r15
je 0x47471
movq 0x8(%rax), %rcx
testq %rcx, %rcx
jne 0x47478
leaq 0xe4cd9(%rip), %rcx     # 0x12c151
movq %rbp, %rdi
leaq 0xd5e12(%rip), %rsi     # 0x11d294
xorl %eax, %eax
callq 0xe8617
jmp 0x47510
xorl %r15d, %r15d
jmp 0x47499
xorl %r15d, %r15d
movq %rcx, %rbp
movq %r15, %rdi
callq 0xf6753
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rax
cmpb $0x0, 0x4(%r12)
je 0x474f8
movq 0x110(%r12), %rsi
movq (%rsp), %rcx
decq %rcx
cmpq $0x5f5e100, %rcx        # imm = 0x5F5E100
setae %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
jne 0x474f8
movq 0x10(%rsi), %r9
testq %r9, %r9
je 0x474f8
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq (%rsp), %rcx
movq %rax, %r14
movq %rax, %r8
callq *%r9
movq %r14, %rax
movq %rbp, %rdi
movq %rax, %rsi
callq 0xea50e
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movl 0x2c(%rsp), %esi
movq %rbp, %rdi
callq 0xe8a25
incq %rbx
cmpq 0x30(%rsp), %rbx
jne 0x47113
jmp 0x4703c