// File: /workspace/github_c_makefile_star2_O1/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 0x152f
leaq 0x2dc5(%rip), %rdi      # 0x4138
callq 0x155c
movq 0x2db9(%rip), %rdi      # 0x4138
leaq 0x2dba(%rip), %rsi      # 0x4140
callq 0x159a
movq 0x2da6(%rip), %rbx      # 0x4138
movq 0x2da7(%rip), %rax      # 0x4140
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1110
xorl %r13d, %r13d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1120
movzwl 0x10(%rax), %ecx
movl %ecx, 0xc(%rsp)
movq %rax, 0x10(%rsp)
movzwl 0x12(%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x2d6a(%rip), %rdi      # 0x4138
movq 0x2d6b(%rip), %rsi      # 0x4140
leaq 0x30(%rsp), %rdx
callq 0x15c8
testl %eax, %eax
jle 0x14f0
movl %eax, %eax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x2d3b(%rip), %rdi      # 0x4138
movq 0x30(%rsp), %rax
movq %rcx, 0x20(%rsp)
movl (%rax,%rcx,4), %esi
leaq 0x28(%rsp), %rdx
callq 0x161a
testl %eax, %eax
jle 0x14cd
movl %eax, %ebx
movl $0x1, %r12d
movq 0x28(%rsp), %rax
movl -0x4(%rax,%r12,4), %ebp
movq 0x2d03(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x170c
testl %eax, %eax
je 0x1456
xorl %r13d, %r13d
cmpq %rbx, %r12
jae 0x14d0
incq %r12
testq %r13, %r13
je 0x1424
jmp 0x14d0
movq 0x2cdb(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x166c
movq %rax, %r14
movq 0x2cca(%rip), %rdi      # 0x4138
movl 0xc(%rax), %esi
callq 0x1718
testq %rax, %rax
je 0x14c2
movq %rax, %r15
movzwl 0xc(%rax), %ecx
cmpw %cx, 0xc(%rsp)
jb 0x1440
movzwl 0xe(%r15), %eax
cmpw %ax, 0x8(%rsp)
jb 0x1440
movzwl 0x10(%r15), %edx
addl %ecx, %edx
cmpl 0xc(%rsp), %edx
jb 0x1440
movzwl 0x12(%r15), %ecx
addl %ecx, %eax
cmpl 0x8(%rsp), %eax
jb 0x1440
movq 0x2c82(%rip), %rdi      # 0x4138
movl %ebp, %esi
callq 0x169d
movq %rax, %r13
jmp 0x1443
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x1443
xorl %r13d, %r13d
movq 0x20(%rsp), %rcx
incq %rcx
testq %r13, %r13
sete %al
cmpq 0x18(%rsp), %rcx
jae 0x14f8
testq %r13, %r13
je 0x13f6
jmp 0x14f8
movb $0x1, %al
xorl %r15d, %r15d
xorl %r14d, %r14d
testb %al, %al
jne 0x1547
movq %r13, %rdi
callq 0x1050
movq 0x10(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsi), %rsi
leaq 0xacb(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1200
leaq 0xac2(%rip), %rsi       # 0x2010
movl $0x1, %edi
xorl %eax, %eax
callq 0x10b0
nop