// File: /workspace/github_cpp_makefile_star2_O3/ksherlock[P]wdc-utils/zrdz_disassembler.cpp
// Function: zrdz_disassembler::location_name[abi:cxx11](unsigned int, unsigned int) const
std::string zrdz_disassembler::location_name(unsigned section, uint32_t offset) const {

	if (section >= _sections.size()) {
		warnx("Invalid section %d", section);
		return "$";
	}
	auto &e = _sections[section];
	if (!e.valid) {
		warnx("Invalid section %d", section);
		return "$";
	}

	// todo -- need to verify relative/absolute value

	auto iter = std::find_if(_symbols.begin(), _symbols.end(), [=](const symbol &s){
		if (s.type == equ_type) return false;
		if (s.type == S_UND) return false;
		return s.section == section && s.offset == offset;
	});

	if (iter != _symbols.end()) return iter->name;

	//fallback to section name + offset
	std::string tmp = e.name;
	if (tmp.empty()) tmp = "section" + std::to_string(section);
	if (offset) tmp += "+$" + to_x(offset, 4);
	return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movl %edx, %r14d
movq %rdi, %rbx
movl %edx, %ecx
movq 0x50(%rsi), %rax
movq 0x58(%rsi), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
imulq %r8, %rdx
cmpq %rcx, %rdx
jbe 0xb36d
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
cmpb $0x0, 0x2d(%rax,%rcx)
je 0xb36d
movq 0x38(%rsi), %r9
movq 0x40(%rsi), %rdx
movq %rdx, %r10
subq %r9, %r10
movq %r10, %rsi
sarq $0x3, %rsi
imulq %r8, %rsi
sarq $0x2, %rsi
testq %rsi, %rsi
jle 0xb3ad
leaq (%rsi,%rsi,4), %rdi
shlq $0x5, %rdi
addq %r9, %rdi
incq %rsi
addq $0x50, %r9
movzbl -0x30(%r9), %r10d
testl %r10d, %r10d
je 0xb2dc
cmpl $0x91, %r10d
je 0xb2dc
movzbl -0x2e(%r9), %r10d
cmpl %r14d, %r10d
jne 0xb2dc
cmpl %ebp, -0x2c(%r9)
je 0xb42a
movzbl -0x8(%r9), %r10d
testl %r10d, %r10d
je 0xb303
cmpl $0x91, %r10d
je 0xb303
movzbl -0x6(%r9), %r10d
cmpl %r14d, %r10d
jne 0xb303
cmpl %ebp, -0x4(%r9)
je 0xb430
movzbl 0x20(%r9), %r10d
testl %r10d, %r10d
je 0xb32a
cmpl $0x91, %r10d
je 0xb32a
movzbl 0x22(%r9), %r10d
cmpl %r14d, %r10d
jne 0xb32a
cmpl %ebp, 0x24(%r9)
je 0xb43a
movzbl 0x48(%r9), %r10d
testl %r10d, %r10d
je 0xb351
cmpl $0x91, %r10d
je 0xb351
movzbl 0x4a(%r9), %r10d
cmpl %r14d, %r10d
jne 0xb351
cmpl %ebp, 0x4c(%r9)
je 0xb436
decq %rsi
addq $0xa0, %r9
cmpq $0x1, %rsi
jg 0xb2b5
movq %rdx, %r10
subq %rdi, %r10
jmp 0xb3b0
leaq 0x4a64(%rip), %rdi      # 0xfdd8
movl %r14d, %esi
xorl %eax, %eax
callq 0x21d0
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x4a00(%rip), %rsi      # 0xfd8c
leaq 0x49fa(%rip), %rdx      # 0xfd8d
movq %rbx, %rdi
callq 0x6a64
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %rdi
sarq $0x3, %r10
imulq %r8, %r10
cmpq $0x1, %r10
je 0xb3fa
cmpq $0x2, %r10
je 0xb3e6
cmpq $0x3, %r10
jne 0xb460
movzbl 0x20(%rdi), %esi
testl %esi, %esi
je 0xb3e2
cmpl $0x91, %esi
jne 0xb4d0
addq $0x28, %rdi
movzbl 0x20(%rdi), %esi
testl %esi, %esi
je 0xb3f6
cmpl $0x91, %esi
jne 0xb41a
addq $0x28, %rdi
movzbl 0x20(%rdi), %esi
testl %esi, %esi
je 0xb460
cmpl $0x91, %esi
je 0xb460
movzbl 0x22(%rdi), %esi
cmpl %r14d, %esi
jne 0xb460
cmpl %ebp, 0x24(%rdi)
je 0xb43d
jmp 0xb460
movzbl 0x22(%rdi), %esi
cmpl %r14d, %esi
jne 0xb3f6
cmpl %ebp, 0x24(%rdi)
je 0xb43d
jmp 0xb3f6
addq $-0x50, %r9
jmp 0xb43a
addq $-0x28, %r9
jmp 0xb43a
addq $0x28, %r9
movq %r9, %rdi
cmpq %rdx, %rdi
je 0xb460
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x69ce
jmp 0xb39b
addq %rcx, %rax
leaq 0x10(%rbx), %r12
movq %r12, (%rbx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x69ce
cmpq $0x0, 0x8(%rbx)
jne 0xb5b7
movl $0x1, %eax
cmpl $0xa, %r14d
jb 0xb4f2
movl $0x4, %eax
movl $0xd1b71759, %ecx       # imm = 0xD1B71759
movl %r14d, %edx
cmpl $0x63, %edx
jbe 0xb4eb
cmpl $0x3e7, %edx            # imm = 0x3E7
jbe 0xb4f0
cmpl $0x2710, %edx           # imm = 0x2710
jb 0xb4f2
movl %edx, %esi
imulq %rcx, %rsi
shrq $0x2d, %rsi
addl $0x4, %eax
cmpl $0x1869f, %edx          # imm = 0x1869F
movl %esi, %edx
ja 0xb49f
addl $-0x3, %eax
jmp 0xb4f2
movzbl 0x22(%rdi), %esi
cmpl %r14d, %esi
jne 0xb3e2
cmpl %ebp, 0x24(%rdi)
je 0xb43d
jmp 0xb3e2
addl $-0x2, %eax
jmp 0xb4f2
decl %eax
movl %eax, %esi
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x8(%rsp), %rdi
xorl %edx, %edx
callq 0x2200
leaq 0x8(%rsp), %r15
movq (%r15), %rdi
movl 0x8(%r15), %esi
movl %r14d, %edx
callq 0x6961
leaq 0x48ac(%rip), %rcx      # 0xfdd0
movl $0x7, %r8d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21f0
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xb55d
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0xb564
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x28(%rsp), %r14
movq %rdx, 0x8(%r14)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2220
movq (%r14), %rdi
cmpq %r15, %rdi
je 0xb5a0
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0xb5b7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
testl %ebp, %ebp
je 0xb39b
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x73f8
leaq 0x484a(%rip), %rcx      # 0xfe23
leaq 0x8(%rsp), %rdi
movl $0x2, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x21f0
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0xb614
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0xb61e
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq %r15, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
callq 0x2090
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xb655
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb39b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb39b
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
jne 0xb6b7
jmp 0xb6c9
jmp 0xb6c6
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xb6a9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb6a9
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb6c9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb6c9
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r12, %rdi
je 0xb6dd
movq (%r12), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x22c0
nop