// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rsi, %rbx
leaq 0x2dad(%rip), %rdi      # 0x4130
callq 0x15f0
movq 0x2da1(%rip), %rdi      # 0x4130
leaq 0x2da2(%rip), %rsi      # 0x4138
callq 0x162c
movq 0x2d8e(%rip), %rdi      # 0x4130
callq 0x17b0
movl %eax, %r15d
movq (%rbx), %rax
movq %rax, 0x8(%rsp)
pushq $0x8
popq %r13
pushq $0x10
popq %rbp
pushq $0x1
popq %r14
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x144f
movb 0x1(%rdi), %al
testb %al, %al
je 0x144f
cmpb $0x2d, (%rdi)
jne 0x144f
cmpb $0x2d, %al
jne 0x13e0
cmpb $0x0, 0x2(%rdi)
je 0x144f
incq %rdi
movq %rdi, 0x8(%rbx)
xorl %eax, %eax
movq %r13, %r12
leaq (%rbx,%r12), %rcx
movb (%rdi), %dl
cmpq $0x8, %r12
jne 0x1447
testl %eax, %eax
jne 0x1447
testb %dl, %dl
je 0x1447
xorl %eax, %eax
movq %r13, %r12
cmpb $0x77, %dl
jne 0x143a
cmpb $0x0, 0x1(%rdi)
je 0x1418
incq %rdi
movq %r13, %r12
jmp 0x142b
cmpq $0x0, 0x8(%rcx)
je 0x15cb
movq 0x10(%rbx), %rdi
pushq $0x10
popq %r12
xorl %esi, %esi
movl %ebp, %edx
callq 0x11c0
movq %rax, %r15
movl %r14d, %eax
movq (%rbx,%r12), %rdi
incq %rdi
movq %rdi, (%rbx,%r12)
jmp 0x13ec
movq %rcx, %rbx
jmp 0x13bd
movl %r15d, %edi
callq 0x1345
testb %al, %al
je 0x15d5
movq 0x2cca(%rip), %rdi      # 0x4130
movl %r15d, %esi
callq 0x17ea
movzwl 0xc(%rax), %r13d
movq %rax, 0x10(%rsp)
movzwl 0xe(%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x2ca9(%rip), %rdi      # 0x4130
movq 0x2caa(%rip), %rsi      # 0x4138
leaq 0x30(%rsp), %rdx
callq 0x1658
cltq
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpq 0x18(%rsp), %rcx
jge 0x1593
testq %rax, %rax
jne 0x1593
movq 0x2c6c(%rip), %rdi      # 0x4130
movq 0x30(%rsp), %rax
movq %rcx, 0x20(%rsp)
movl (%rax,%rcx,4), %esi
leaq 0x28(%rsp), %rdx
callq 0x16a8
movslq %eax, %r15
xorl %ebx, %ebx
xorl %eax, %eax
cmpq %r15, %rbx
jge 0x1586
testq %rax, %rax
jne 0x1586
movq 0x28(%rsp), %rax
movl (%rax,%rbx,4), %ebp
movq 0x2c2d(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x178c
testl %eax, %eax
je 0x1515
xorl %eax, %eax
incq %rbx
jmp 0x14e2
movq 0x2c14(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x16f8
movq %rax, %r14
movq 0x2c03(%rip), %rdi      # 0x4130
movl 0xc(%rax), %esi
callq 0x1798
testq %rax, %rax
je 0x157f
movq %rax, %r12
movzwl 0xc(%rax), %ecx
cmpw %cx, %r13w
jb 0x150e
movzwl 0xe(%r12), %eax
cmpw %ax, 0x8(%rsp)
jb 0x150e
movzwl 0x10(%r12), %edx
addl %ecx, %edx
cmpl %r13d, %edx
jbe 0x150e
movzwl 0x12(%r12), %ecx
addl %ecx, %eax
cmpl 0x8(%rsp), %eax
jbe 0x150e
movq 0x2bba(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x1727
jmp 0x1510
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x1510
movq 0x20(%rsp), %rcx
incq %rcx
jmp 0x14a9
testq %rax, %rax
je 0x15de
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 0x8(%rsp), %rdi
callq 0x132c
leaq 0xa3c(%rip), %rsi       # 0x2018
jmp 0x15e5
leaq 0xa49(%rip), %rsi       # 0x202e
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10b0
nop