// File: /workspace/github_c_makefile_star2_O0/michaelforney[P]wld/drm.c
// Function: find_driver
static const struct drm_driver *
find_driver(int fd)
{
	char path[64], id[32];
	uint32_t vendor_id, device_id;
	char *path_part;
	struct stat st;
	FILE *file;
	uint32_t index;
	int n;

	if (fstat(fd, &st) == -1)
		return NULL;

	n = snprintf(path, sizeof(path), "/sys/dev/char/%u:%u/device/", major(st.st_rdev), minor(st.st_rdev));
	if (n + 6 >= sizeof(path))
		return NULL;
	path_part = path + n;

	strcpy(path_part, "vendor");
	file = fopen(path, "r");
	if (!file)
		return NULL;
	fgets(id, sizeof id, file);
	fclose(file);
	vendor_id = strtoul(id, NULL, 0);

	strcpy(path_part, "device");
	file = fopen(path, "r");
	if (!file)
		return NULL;
	fgets(id, sizeof id, file);
	fclose(file);
	device_id = strtoul(id, NULL, 0);

	for (index = 0; index < ARRAY_LENGTH(drivers); ++index) {
		DEBUG("Trying DRM driver `%s'\n", drivers[index]->name);
		if (drivers[index]->device_supported(vendor_id, device_id))
			return drivers[index];
	}

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl %edi, -0xc(%rbp)
movl -0xc(%rbp), %edi
leaq -0x110(%rbp), %rsi
callq 0x98a0
cmpl $-0x1, %eax
jne 0xb21f
movq $0x0, -0x8(%rbp)
jmp 0xb42e
leaq -0x50(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x9610
movl %eax, -0x124(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x9790
movq -0x130(%rbp), %rdi
movl -0x124(%rbp), %ecx
movl %eax, %r8d
movl $0x40, %esi
leaq 0x9a1a(%rip), %rdx      # 0x14c7e
movb $0x0, %al
callq 0x9310
movl %eax, -0x120(%rbp)
movl -0x120(%rbp), %eax
addl $0x6, %eax
cltq
cmpq $0x40, %rax
jb 0xb28f
movq $0x0, -0x8(%rbp)
jmp 0xb42e
leaq -0x50(%rbp), %rax
movslq -0x120(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
leaq 0x99ee(%rip), %rsi      # 0x14c9a
callq 0x90f0
leaq -0x50(%rbp), %rdi
leaq 0x8bf1(%rip), %rsi      # 0x13ead
callq 0x96f0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0xb2df
movq $0x0, -0x8(%rbp)
jmp 0xb42e
leaq -0x70(%rbp), %rdi
movq -0x118(%rbp), %rdx
movl $0x20, %esi
callq 0x9440
movq -0x118(%rbp), %rdi
callq 0x91e0
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x97a0
movl %eax, -0x74(%rbp)
movq -0x80(%rbp), %rdi
leaq 0xa00a(%rip), %rsi      # 0x15327
callq 0x90f0
leaq -0x50(%rbp), %rdi
leaq 0x8b80(%rip), %rsi      # 0x13ead
callq 0x96f0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0xb350
movq $0x0, -0x8(%rbp)
jmp 0xb42e
leaq -0x70(%rbp), %rdi
movq -0x118(%rbp), %rdx
movl $0x20, %esi
callq 0x9440
movq -0x118(%rbp), %rdi
callq 0x91e0
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x97a0
movl %eax, -0x78(%rbp)
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpq $0x3, %rax
jae 0xb426
movq 0x10c4c(%rip), %rax     # 0x1bff0
movq (%rax), %rdi
movl -0x11c(%rbp), %eax
movl %eax, %ecx
leaq 0x110ca(%rip), %rax     # 0x1c480
movq (%rax,%rcx,8), %rax
movq (%rax), %rcx
leaq 0x98dd(%rip), %rsi      # 0x14ca1
leaq 0x98f4(%rip), %rdx      # 0x14cbf
movb $0x0, %al
callq 0x94a0
movl -0x11c(%rbp), %eax
movl %eax, %ecx
leaq 0x1109f(%rip), %rax     # 0x1c480
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl -0x74(%rbp), %edi
movl -0x78(%rbp), %esi
callq *%rax
testb $0x1, %al
jne 0xb3f7
jmp 0xb410
movl -0x11c(%rbp), %eax
movl %eax, %ecx
leaq 0x1107a(%rip), %rax     # 0x1c480
movq (%rax,%rcx,8), %rax
movq %rax, -0x8(%rbp)
jmp 0xb42e
jmp 0xb412
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0xb38d
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax,%rax)