// File: /workspace/github_c_makefile_star2_O3/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 0xd130(%rip), %rdx      # 0x1b20e
leaq 0xd12f(%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 0xe24b
movq %rax, %r14
movq %r15, 0x18(%rsp)
movq %rax, %rdi
callq 0xd260
testq %rax, %rax
je 0xe291
movq %rax, %rbp
movq $-0x1, 0x10(%rsp)
leaq 0xd54f(%rip), %r12      # 0x1b688
leaq 0xd547(%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 0xe235
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xd0a0
testl %eax, %eax
je 0xe235
movl $0x1000, %esi           # imm = 0x1000
leaq 0x20(%rsp), %rdi
leaq 0xd079(%rip), %rdx      # 0x1b20e
leaq 0x1020(%rsp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xd170
testl %eax, %eax
jns 0xe1cf
callq 0xe36f
leaq 0x25d19(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
xorl %edi, %edi
xorl %esi, %esi
leaq 0xd281(%rip), %rdx      # 0x1b446
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movq %r15, %rdi
callq 0xd110
movq %r15, %rdi
leaq 0xd35f(%rip), %rsi      # 0x1b540
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xe202
cmpb $0x8, 0x12(%rbp)
jne 0xe202
leaq 0x20(%rsp), %rdi
callq 0xe2df
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0xd110
movq %r15, %rdi
leaq 0xd253(%rip), %rsi      # 0x1b467
movq %rax, %rdx
callq 0xd0a0
testl %eax, %eax
jne 0xe235
cmpb $0x8, 0x12(%rbp)
jne 0xe235
leaq 0x20(%rsp), %rdi
callq 0xe2df
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0xd260
movq %rax, %rbp
testq %rax, %rax
jne 0xe149
jmp 0xe2a3
callq 0xe36f
movq %rax, %r14
leaq 0x25c76(%rip), %rax     # 0x33ed0
movq (%rax), %r15
callq 0xd070
movl (%rax), %edi
callq 0xd400
movq %rax, (%rsp)
leaq 0xd1b4(%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 0x199b4
jmp 0xe2cb
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 0xe2c9
movslq 0x1c(%rcx), %rax
cmpq %rax, 0x8(%rsp)
sete %bl
jmp 0xe2cb
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq