// File: /workspace/github_c_makefile_star2_O1/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 0x1628
movq 0x2da1(%rip), %rdi      # 0x4130
leaq 0x2da2(%rip), %rsi      # 0x4138
callq 0x1666
movq 0x2d8e(%rip), %rdi      # 0x4130
callq 0x17fc
movl %eax, %r15d
movq (%rbx), %r14
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x1465
movb 0x1(%rdi), %al
testb %al, %al
je 0x1465
cmpb $0x2d, (%rdi)
jne 0x1465
cmpb $0x2d, %al
jne 0x13d8
cmpb $0x0, 0x2(%rdi)
je 0x1456
leaq 0x1(%rdi), %rax
movq %rax, 0x8(%rbx)
movb (%rax), %cl
movb $0x1, %bpl
testb %cl, %cl
je 0x1450
movl $0x8, %r12d
xorl %eax, %eax
cmpb $0x77, %cl
jne 0x142e
movb 0x2(%rdi), %al
addq $0x2, %rdi
testb %al, %al
jne 0x141a
cmpq $0x0, 0x8(%rbx,%r12)
je 0x1602
testb %al, %al
jne 0x141a
movq 0x8(%rbx,%r12), %rdi
addq $0x8, %r12
xorl %esi, %esi
movl $0x10, %edx
callq 0x11c0
movq %rax, %r15
movl $0x1, %eax
movq (%rbx,%r12), %rdi
leaq 0x1(%rdi), %rcx
movq %rcx, (%rbx,%r12)
cmpq $0x8, %r12
jne 0x144b
movb 0x1(%rdi), %cl
testb %cl, %cl
je 0x144b
testl %eax, %eax
je 0x13f1
addq %r12, %rbx
jmp 0x145c
addq $0x8, %rbx
jmp 0x145c
addq $0x10, %rbx
xorl %ebp, %ebp
testb %bpl, %bpl
jne 0x13ad
movq 0x2cc4(%rip), %rbx      # 0x4130
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1110
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
testq %rax, %rax
je 0x160a
movq 0x2c9d(%rip), %rdi      # 0x4130
movl %r15d, %esi
callq 0x1838
movzwl 0xc(%rax), %ecx
movl %ecx, 0x4(%rsp)
movq %rax, 0x8(%rsp)
movzwl 0xe(%rax), %eax
movl %eax, (%rsp)
movq 0x2c7a(%rip), %rdi      # 0x4130
movq 0x2c7b(%rip), %rsi      # 0x4138
leaq 0x20(%rsp), %rdx
callq 0x1694
testl %eax, %eax
jle 0x15c1
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x2c4a(%rip), %rdi      # 0x4130
movq 0x20(%rsp), %rax
movl (%rax,%r12,4), %esi
leaq 0x18(%rsp), %rdx
callq 0x16e6
testl %eax, %eax
jle 0x15a4
movl %eax, %ebx
movl $0x1, %r13d
movq 0x18(%rsp), %rax
movl -0x4(%rax,%r13,4), %ebp
movq 0x2c16(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x17d8
testl %eax, %eax
je 0x1536
xorl %eax, %eax
cmpq %rbx, %r13
jae 0x15a6
incq %r13
testq %rax, %rax
je 0x1509
jmp 0x15a6
movq 0x2bf3(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x1738
movq %rax, %r14
movq 0x2be2(%rip), %rdi      # 0x4130
movl 0xc(%rax), %esi
callq 0x17e4
testq %rax, %rax
je 0x159d
movq %rax, %r15
movzwl 0xc(%rax), %ecx
cmpw %cx, 0x4(%rsp)
jb 0x1525
movzwl 0xe(%r15), %eax
cmpw %ax, (%rsp)
jb 0x1525
movzwl 0x10(%r15), %edx
addl %ecx, %edx
cmpl 0x4(%rsp), %edx
jbe 0x1525
movzwl 0x12(%r15), %ecx
addl %ecx, %eax
cmpl (%rsp), %eax
jbe 0x1525
movq 0x2b9c(%rip), %rdi      # 0x4130
movl %ebp, %esi
callq 0x1769
jmp 0x1527
xorl %eax, %eax
xorl %r15d, %r15d
jmp 0x1527
xorl %eax, %eax
incq %r12
testq %rax, %rax
sete %cl
cmpq 0x10(%rsp), %r12
jae 0x15cb
testq %rax, %rax
je 0x14df
jmp 0x15cb
movb $0x1, %cl
xorl %eax, %eax
xorl %r15d, %r15d
xorl %r14d, %r14d
testb %cl, %cl
jne 0x1613
movq %rax, %rdi
callq 0x1050
movq 0x8(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x132c
leaq 0xa07(%rip), %rsi       # 0x2018
jmp 0x161a
leaq 0xa14(%rip), %rsi       # 0x202e
movl $0x1, %edi
xorl %eax, %eax
callq 0x10b0
nop