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

	uint16_t window_x;
	uint16_t window_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;

	char *argv0;

	init_xcb(&conn);
	get_screen(conn, &scrn);

	f_window = get_focused_window(conn);
	/* Get info about the focused window */
	ARGBEGIN {
		case 'w':
			f_window = strtoul(EARGF(usage(argv0)), NULL, 16);
	} ARGEND

	if (!window_exists(f_window))
		errx(1, "Window does not exist");
	window_geometry = get_window_geometry(conn, f_window);
	window_x = window_geometry->x;
	window_y = window_geometry->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 (window_x >= output_x &&
						window_y >= output_y &&
					  window_x < output_x + output_w &&
					  window_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(window_geometry);
	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
movq %rsi, %rbx
leaq 0x2dad(%rip), %rdi      # 0x4130
callq 0x161c
movq 0x2da1(%rip), %rdi      # 0x4130
leaq 0x2da2(%rip), %rsi      # 0x4138
callq 0x165a
movq 0x2d8e(%rip), %rdi      # 0x4130
callq 0x17f0
movl %eax, %r14d
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1467
movq (%rbx), %r15
leaq 0x8(%rbx), %rcx
movb 0x1(%rax), %dl
testb %dl, %dl
je 0x1467
cmpb $0x2d, (%rax)
jne 0x1467
cmpb $0x2d, %dl
jne 0x13e1
cmpb $0x0, 0x2(%rax)
je 0x1467
incq %rax
movq %rax, (%rcx)
movq 0x8(%rbx), %rdi
movb (%rdi), %bpl
testb %bpl, %bpl
je 0x1452
movl $0x8, %r12d
cmpb $0x77, %bpl
jne 0x142c
cmpb $0x0, 0x1(%rdi)
je 0x140a
incq %rdi
jmp 0x141d
movq 0x10(%rbx), %rdi
movl $0x10, %r12d
testq %rdi, %rdi
je 0x15f6
xorl %esi, %esi
movl $0x10, %edx
callq 0x11c0
movq %rax, %r14
movq (%rbx,%r12), %rax
leaq 0x1(%rax), %rdi
movq %rdi, (%rbx,%r12)
movb 0x1(%rax), %al
testb %al, %al
je 0x144d
cmpl $0x8, %r12d
jne 0x144d
cmpb $0x77, %bpl
movl %eax, %ebp
jne 0x13f3
addq %r12, %rbx
jmp 0x1456
addq $0x8, %rbx
leaq 0x8(%rbx), %rcx
movq 0x8(%rbx), %rax
testq %rax, %rax
jne 0x13be
movq 0x2cc2(%rip), %rbx      # 0x4130
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1110
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
testq %rax, %rax
je 0x1607
movq 0x2c9b(%rip), %rdi      # 0x4130
movl %r14d, %esi
callq 0x182c
movzwl 0xc(%rax), %ecx
movl %ecx, 0x4(%rsp)
movq %rax, 0x8(%rsp)
movzwl 0xe(%rax), %eax
movl %eax, (%rsp)
movq 0x2c78(%rip), %rdi      # 0x4130
movq 0x2c79(%rip), %rsi      # 0x4138
leaq 0x20(%rsp), %rdx
callq 0x1688
testl %eax, %eax
jle 0x15fe
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x2c48(%rip), %rdi      # 0x4130
movq 0x20(%rsp), %rax
movl (%rax,%r15,4), %esi
leaq 0x18(%rsp), %rdx
callq 0x16da
testl %eax, %eax
jle 0x15a9
movl %eax, %ebx
movl $0x1, %r13d
movq 0x18(%rsp), %rax
movl -0x4(%rax,%r13,4), %ebp
movq 0x2c14(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x17cc
testl %eax, %eax
je 0x1538
xorl %eax, %eax
cmpq %rbx, %r13
jae 0x15ab
incq %r13
testq %rax, %rax
je 0x150b
jmp 0x15ab
movq 0x2bf1(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x172c
movq %rax, %r14
movq 0x2be0(%rip), %rdi      # 0x4130
movl 0xc(%rax), %esi
callq 0x17d8
testq %rax, %rax
je 0x15a2
movq %rax, %r12
movzwl 0xc(%rax), %ecx
cmpw %cx, 0x4(%rsp)
jb 0x1527
movzwl 0xe(%r12), %eax
cmpw %ax, (%rsp)
jb 0x1527
movzwl 0x10(%r12), %edx
addl %ecx, %edx
cmpl 0x4(%rsp), %edx
jbe 0x1527
movzwl 0x12(%r12), %ecx
addl %ecx, %eax
cmpl (%rsp), %eax
jbe 0x1527
movq 0x2b97(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x175d
jmp 0x1529
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x1529
xorl %eax, %eax
incq %r15
cmpq 0x10(%rsp), %r15
jae 0x15be
testq %rax, %rax
je 0x14e1
testq %rax, %rax
je 0x15fe
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
movq %r15, %rdi
callq 0x132c
leaq 0xa29(%rip), %rsi       # 0x202e
jmp 0x160e
leaq 0xa0a(%rip), %rsi       # 0x2018
movl $0x1, %edi
xorl %eax, %eax
callq 0x10b0
nop