// File: /workspace/github_c_makefile_star2_O1/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 0xd10a(%rip), %rdx      # 0x1b20e
leaq 0xd109(%rip), %rcx      # 0x1b214
leaq 0x1020(%rsp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd170
movq %rbx, %rdi
callq 0xd100
testq %rax, %rax
je 0xe271
movq %rax, %r14
movq %r15, 0x18(%rsp)
movq %rax, %rdi
callq 0xd270
testq %rax, %rax
je 0xe2b7
movq %rax, %rbp
movq $-0x1, 0x10(%rsp)
leaq 0xd529(%rip), %r12      # 0x1b688
leaq 0xd521(%rip), %r13      # 0x1b687
movq $-0x1, 0x8(%rsp)
leaq 0x13(%rbp), %r15
movq %r15, %rdi
callq 0xd110
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xe25b
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xe25b
movl $0x1000, %esi           # imm = 0x1000
leaq 0x20(%rsp), %rdi
leaq 0xd053(%rip), %rdx      # 0x1b20e
leaq 0x1020(%rsp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xd170
testl %eax, %eax
jns 0xe1f5
callq 0xe395
leaq 0x25cf3(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
xorl %edi, %edi
xorl %esi, %esi
leaq 0xd25b(%rip), %rdx      # 0x1b446
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
movq %r15, %rdi
callq 0xd110
movq %r15, %rdi
leaq 0xd339(%rip), %rsi      # 0x1b540
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xe228
cmpb $0x8, 0x12(%rbp)
jne 0xe228
leaq 0x20(%rsp), %rdi
callq 0xe305
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0xd110
movq %r15, %rdi
leaq 0xd22d(%rip), %rsi      # 0x1b467
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xe25b
cmpb $0x8, 0x12(%rbp)
jne 0xe25b
leaq 0x20(%rsp), %rdi
callq 0xe305
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0xd270
movq %rax, %rbp
testq %rax, %rax
jne 0xe16f
jmp 0xe2c9
callq 0xe395
movq %rax, %r14
leaq 0x25c50(%rip), %rax     # 0x33ed0
movq (%rax), %r15
callq 0xd070
movl (%rax), %edi
callq 0xd410
movq %rax, (%rsp)
leaq 0xd18e(%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 0x19ca8
jmp 0xe2f1
movq $-0x1, 0x8(%rsp)
movq $-0x1, 0x10(%rsp)
movq %r14, %rdi
callq 0xd1c0
movq 0x18(%rsp), %rcx
movslq 0x18(%rcx), %rax
cmpq %rax, 0x10(%rsp)
jne 0xe2ef
movslq 0x1c(%rcx), %rax
cmpq %rax, 0x8(%rsp)
sete %bl
jmp 0xe2f1
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq