// File: /workspace/github_c_makefile_star2_O2/intel[P]pf-bb-config/config_app.c
// Function: get_device_id
static bool
get_device_id(hw_device *device, const char *location)
{
	unsigned long vendor_id = -1, device_id = -1;
	struct dirent *dirent;
	DIR *dir;
	char pci_path[PATH_MAX];

	snprintf(pci_path, sizeof(pci_path), "%s/%s", SYS_DIR, location);
	dir = opendir(pci_path);
	if (dir == NULL) {
		LOG(ERR, "Failed to open %s (%s)", pci_path, strerror(errno));
		return false;
	}

	while ((dirent = readdir(dir)) != NULL) {
		char file_path[PATH_MAX];

		/* Omit Current Directory & Previous Directory Lookup */
		if (strncmp(dirent->d_name, CUR_DIR,
				strlen(dirent->d_name)) == 0 ||
				strncmp(dirent->d_name, PREV_DIR,
				strlen(dirent->d_name)) == 0)
			continue;

		/* Set filepath as next PCI folder (xxxx:xx:xx.x) */
		int snprintf_ret =  snprintf(file_path, sizeof(file_path), "%s/%s",
				pci_path, dirent->d_name);
		if (snprintf_ret < 0)
			LOG(ERR, "Failed to format PCI path");

		/* Get Device ID */
		if (strncmp(dirent->d_name, DEVICE_FILE,
				strlen(dirent->d_name)) == 0 &&
				dirent->d_type == DT_REG)
			device_id = get_file_val(file_path);

		/* Get Vendor ID */
		if (strncmp(dirent->d_name, VENDOR_FILE,
				strlen(dirent->d_name)) == 0 &&
				dirent->d_type == DT_REG)
			vendor_id = get_file_val(file_path);
	}

	closedir(dir);
	/* Check if device is found */
	return (vendor_id == device->vendor_id &&
			device_id == device->device_id);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2028, %rsp           # imm = 0x2028
movq %rsi, %r8
movq %rdi, %r15
leaq 0xd183(%rip), %rdx      # 0x1b20e
leaq 0xd182(%rip), %rcx      # 0x1b214
leaq 0x1020(%rsp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd180
movq %rbx, %rdi
callq 0xd100
testq %rax, %rax
je 0xe203
movq %rax, %r14
movq %r15, 0x18(%rsp)
pushq $-0x1
popq %rax
leaq 0xd5bc(%rip), %r12      # 0x1b688
leaq 0xd5b4(%rip), %r13      # 0x1b687
movq %rax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0xd270
testq %rax, %rax
je 0xe1dd
movq %rax, %rbp
leaq 0x13(%rax), %r15
movq %r15, %rdi
callq 0xd110
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xe0dd
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xe0dd
movl $0x1000, %esi           # imm = 0x1000
leaq 0x20(%rsp), %rdi
leaq 0xd0d9(%rip), %rdx      # 0x1b20e
leaq 0x1020(%rsp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xd180
testl %eax, %eax
jns 0xe16f
callq 0xe2eb
leaq 0x26d79(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
xorl %edi, %edi
xorl %esi, %esi
leaq 0xd2e1(%rip), %rdx      # 0x1b446
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movq %r15, %rdi
callq 0xd110
movq %r15, %rdi
leaq 0xd3bf(%rip), %rsi      # 0x1b540
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xe1a2
cmpb $0x8, 0x12(%rbp)
jne 0xe1a2
leaq 0x20(%rsp), %rdi
callq 0xe25f
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0xd110
movq %r15, %rdi
leaq 0xd2b3(%rip), %rsi      # 0x1b467
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xe0dd
cmpb $0x8, 0x12(%rbp)
jne 0xe0dd
leaq 0x20(%rsp), %rdi
callq 0xe25f
jmp 0xe0d8
movq %r14, %rdi
callq 0xd1d0
movq 0x18(%rsp), %rcx
movslq 0x18(%rcx), %rax
cmpq %rax, 0x10(%rsp)
jne 0xe249
movslq 0x1c(%rcx), %rax
cmpq %rax, 0x8(%rsp)
sete %bl
jmp 0xe24b
callq 0xe2eb
movq %rax, %r14
leaq 0x26cbe(%rip), %rax     # 0x34ed0
movq (%rax), %r15
callq 0xd070
movl (%rax), %edi
callq 0xd410
movq %rax, (%rsp)
leaq 0xd1fc(%rip), %rdx      # 0x1b428
xorl %ebx, %ebx
leaq 0x1020(%rsp), %r9
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x19400
jmp 0xe24b
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq