// File: /workspace/github_c_makefile_star2_O3/tudurom[P]disputils/phd.c
// Function: main
int
main(int argc, char *argv[])
{
#ifdef __OpenBSD__
	if (pledge("stdio rpath unix", NULL) == -1)
		err(1, "pledge");
#endif
	xcb_query_pointer_reply_t *pointer;

	uint16_t pointer_x;
	uint16_t pointer_y;

	xcb_randr_get_output_info_reply_t *output_info = NULL;
	xcb_randr_get_crtc_info_reply_t *output_crtc_info = NULL;
	xcb_randr_output_t output;
	const char *output_name;

	uint16_t output_w;
	uint16_t output_h;
	uint16_t output_x;
	uint16_t output_y;

	if (argc > 1)
		usage(argv[0]);
	init_xcb(&conn);
	get_screen(conn, &scrn);

	/* Get info about the pointer */
	pointer = xcb_query_pointer_reply(conn,
			xcb_query_pointer(conn, scrn->root), NULL);
	pointer_x = pointer->root_x;
	pointer_y = pointer->root_y;

	/* Iterate through outputs */
	xcb_randr_provider_t *providers;
	int p_len = get_providers(conn, scrn, &providers);

	int i = 0;
	output_name = NULL;
	while (i < p_len && output_name == NULL) {
		xcb_randr_output_t *os;
		int o_len = get_outputs(conn, providers[i], &os);

		int j = 0;
		while (j < o_len && output_name == NULL) {
			output = os[j];
			if (get_output_connection(conn, output) == 0) {
				/* Check */
				output_info = get_output_info(conn, output);
				output_crtc_info = get_output_crtc_info(conn, output_info->crtc);
				if (output_crtc_info != NULL) {
					output_w = output_crtc_info->width;
					output_h = output_crtc_info->height;
					output_x = output_crtc_info->x;
					output_y = output_crtc_info->y;

					if (pointer_x >= output_x &&
						pointer_y >= output_y &&
					  pointer_x <= output_x + output_w &&
					  pointer_y <= output_y + output_h) {

						output_name = (const char *)get_output_name(conn, output);
					}
				}
			}
			j++;
		}

		i++;
	}
	if (output_name == NULL)
		errx(1, "Cannot get output name");
	printf("%s\n", output_name);
	free(pointer);
	free(output_info);
	free(output_crtc_info);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, %edi
jge 0x151b
leaq 0x2dc5(%rip), %rdi      # 0x4138
callq 0x1534
movq 0x2db9(%rip), %rdi      # 0x4138
leaq 0x2dba(%rip), %rsi      # 0x4140
callq 0x1572
movq 0x2da6(%rip), %rbx      # 0x4138
movq 0x2da7(%rip), %rax      # 0x4140
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1110
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1120
movzwl 0x10(%rax), %ecx
movl %ecx, 0x4(%rsp)
movq %rax, 0x8(%rsp)
movzwl 0x12(%rax), %eax
movl %eax, (%rsp)
movq 0x2d6e(%rip), %rdi      # 0x4138
movq 0x2d6f(%rip), %rsi      # 0x4140
leaq 0x20(%rsp), %rdx
callq 0x15a0
testl %eax, %eax
jle 0x1508
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x2d3e(%rip), %rdi      # 0x4138
movq 0x20(%rsp), %rax
movl (%rax,%r15,4), %esi
leaq 0x18(%rsp), %rdx
callq 0x15f2
testl %eax, %eax
jle 0x14bb
movl %eax, %ebx
movl $0x1, %r13d
movq 0x18(%rsp), %rax
movl -0x4(%rax,%r13,4), %ebp
movq 0x2d0a(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x16e4
testl %eax, %eax
je 0x144a
xorl %eax, %eax
cmpq %rbx, %r13
jae 0x14bd
incq %r13
testq %rax, %rax
je 0x141d
jmp 0x14bd
movq 0x2ce7(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x1644
movq %rax, %r14
movq 0x2cd6(%rip), %rdi      # 0x4138
movl 0xc(%rax), %esi
callq 0x16f0
testq %rax, %rax
je 0x14b4
movq %rax, %r12
movzwl 0xc(%rax), %ecx
cmpw %cx, 0x4(%rsp)
jb 0x1439
movzwl 0xe(%r12), %eax
cmpw %ax, (%rsp)
jb 0x1439
movzwl 0x10(%r12), %edx
addl %ecx, %edx
cmpl 0x4(%rsp), %edx
jb 0x1439
movzwl 0x12(%r12), %ecx
addl %ecx, %eax
cmpl (%rsp), %eax
jb 0x1439
movq 0x2c8d(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x1675
jmp 0x143b
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x143b
xorl %eax, %eax
incq %r15
cmpq 0x10(%rsp), %r15
jae 0x14d0
testq %rax, %rax
je 0x13f3
testq %rax, %rax
je 0x1508
movq %rax, %rdi
callq 0x1050
movq 0x8(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb01(%rip), %rsi       # 0x2010
movl $0x1, %edi
xorl %eax, %eax
callq 0x10b0
movq (%rsi), %rsi
leaq 0xadf(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1200
nop