// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
cmpl $0x2, %edi
jge 0x150d
leaq 0x2dc5(%rip), %rdi      # 0x4138
callq 0x1528
movq 0x2db9(%rip), %rdi      # 0x4138
leaq 0x2dba(%rip), %rsi      # 0x4140
callq 0x1564
movq 0x2da6(%rip), %rbx      # 0x4138
movq 0x2da7(%rip), %rax      # 0x4140
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1110
xorl %r15d, %r15d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1120
movzwl 0x10(%rax), %ebx
movq %rax, 0x10(%rsp)
movzwl 0x12(%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x2d6e(%rip), %rdi      # 0x4138
movq 0x2d6f(%rip), %rsi      # 0x4140
leaq 0x30(%rsp), %rdx
callq 0x1590
cltq
movq %rax, 0x18(%rsp)
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpq 0x18(%rsp), %r15
jge 0x14d5
testq %rax, %rax
jne 0x14d5
movq 0x2d33(%rip), %rdi      # 0x4138
movq 0x30(%rsp), %rax
movq %r15, 0x20(%rsp)
movl (%rax,%r15,4), %esi
leaq 0x28(%rsp), %rdx
callq 0x15e0
movslq %eax, %r13
xorl %r15d, %r15d
xorl %eax, %eax
cmpq %r13, %r15
jge 0x14c8
testq %rax, %rax
jne 0x14c8
movq 0x28(%rsp), %rax
movl (%rax,%r15,4), %ebp
movq 0x2cf1(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x16c4
testl %eax, %eax
je 0x1459
xorl %eax, %eax
incq %r15
jmp 0x1425
movq 0x2cd8(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x1630
movq %rax, %r14
movq 0x2cc7(%rip), %rdi      # 0x4138
movl 0xc(%rax), %esi
callq 0x16d0
testq %rax, %rax
je 0x14c1
movq %rax, %r12
movzwl 0xc(%rax), %ecx
cmpw %cx, %bx
jb 0x1452
movzwl 0xe(%r12), %eax
cmpw %ax, 0xc(%rsp)
jb 0x1452
movzwl 0x10(%r12), %edx
addl %ecx, %edx
cmpl %ebx, %edx
jb 0x1452
movzwl 0x12(%r12), %ecx
addl %ecx, %eax
cmpl 0xc(%rsp), %eax
jb 0x1452
movq 0x2c80(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x165f
jmp 0x1454
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x1454
movq 0x20(%rsp), %r15
incq %r15
jmp 0x13ea
testq %rax, %rax
je 0x1515
movq %rax, %rdi
callq 0x1050
movq 0x10(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsi), %rdi
callq 0x133c
leaq 0xaf4(%rip), %rsi       # 0x2010
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10b0
nop