// File: /workspace/github_c_makefile_star2_O3/baskerville[P]sxhkd/src/sxhkd.c
// Function: main
int main(int argc, char *argv[])
{
	int opt;
	char *fifo_path = NULL;
	status_fifo = NULL;
	config_path = NULL;
	mapping_count = 0;
	timeout = TIMEOUT;
	grabbed = false;
	redir_fd = -1;
	abort_keysym = ESCAPE_KEYSYM;

	while ((opt = getopt(argc, argv, "hvm:t:c:r:s:a:")) != -1) {
		switch (opt) {
			case 'v':
				printf("%s\n", VERSION);
				exit(EXIT_SUCCESS);
				break;
			case 'h':
				printf("sxhkd [-h|-v|-m COUNT|-t TIMEOUT|-c CONFIG_FILE|-r REDIR_FILE|-s STATUS_FIFO|-a ABORT_KEYSYM] [EXTRA_CONFIG ...]\n");
				exit(EXIT_SUCCESS);
				break;
			case 'm':
				if (sscanf(optarg, "%i", &mapping_count) != 1)
					warn("Can't parse mapping count.\n");
				break;
			case 't':
				timeout = atoi(optarg);
				break;
			case 'c':
				config_path = optarg;
				break;
			case 'r':
				redir_fd = open(optarg, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
				if (redir_fd == -1)
					warn("Failed to open the command redirection file.\n");
				break;
			case 's':
				fifo_path = optarg;
				break;
			case 'a':
				if (!parse_keysym(optarg, &abort_keysym)) {
					warn("Invalid keysym name: %s.\n", optarg);
				}
				break;
		}
	}

	num_extra_confs = argc - optind;
	extra_confs = argv + optind;

	if (config_path == NULL) {
		char *config_home = getenv(CONFIG_HOME_ENV);
		if (config_home != NULL)
			snprintf(config_file, sizeof(config_file), "%s/%s", config_home, CONFIG_PATH);
		else
			snprintf(config_file, sizeof(config_file), "%s/%s/%s", getenv("HOME"), ".config", CONFIG_PATH);
	} else {
		snprintf(config_file, sizeof(config_file), "%s", config_path);
	}

	if (fifo_path != NULL) {
		int fifo_fd = open(fifo_path, O_RDWR | O_NONBLOCK);
		if (fifo_fd != -1) {
			status_fifo = fdopen(fifo_fd, "w");
		} else {
			warn("Couldn't open status fifo.\n");
		}
	}

	signal(SIGINT, hold);
	signal(SIGHUP, hold);
	signal(SIGTERM, hold);
	signal(SIGUSR1, hold);
	signal(SIGUSR2, hold);
	signal(SIGALRM, hold);

	setup();
	get_standard_keysyms();
	get_lock_fields();
	abort_chord = make_chord(abort_keysym, XCB_NONE, 0, XCB_KEY_PRESS, false, false);
	load_config(config_file);
	for (int i = 0; i < num_extra_confs; i++)
		load_config(extra_confs[i]);
	grab();

	xcb_generic_event_t *evt;
	int fd = xcb_get_file_descriptor(dpy);

	fd_set descriptors;

	reload = toggle_grab = bell = chained = locked = false;
	running = true;

	xcb_flush(dpy);

	while (running) {
		FD_ZERO(&descriptors);
		FD_SET(fd, &descriptors);

		if (select(fd + 1, &descriptors, NULL, NULL, NULL) > 0) {
			while ((evt = xcb_poll_for_event(dpy)) != NULL) {
				uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(evt);
				switch (event_type) {
					case XCB_KEY_PRESS:
					case XCB_KEY_RELEASE:
					case XCB_BUTTON_PRESS:
					case XCB_BUTTON_RELEASE:
						key_button_event(evt, event_type);
						break;
					case XCB_MAPPING_NOTIFY:
						mapping_notify(evt);
						break;
					default:
						PRINTF("received event %u\n", event_type);
						break;
				}
				free(evt);
			}
		}

		if (reload) {
			signal(SIGUSR1, hold);
			reload_cmd();
			reload = false;
		}

		if (toggle_grab) {
			signal(SIGUSR2, hold);
			toggle_grab_cmd();
			toggle_grab = false;
		}

		if (bell) {
			signal(SIGALRM, hold);
			put_status(TIMEOUT_PREFIX, "Timeout reached");
			abort_chain();
			bell = false;
		}

		if (xcb_connection_has_error(dpy)) {
			warn("The server closed the connection.\n");
			running = false;
		}
	}

	if (redir_fd != -1) {
		close(redir_fd);
	}

	if (status_fifo != NULL) {
		fclose(status_fifo);
	}

	ungrab();
	cleanup();
	destroy_chord(abort_chord);
	xcb_key_symbols_free(symbols);
	xcb_disconnect(dpy);
	return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r14
movl %edi, %ebp
xorl %eax, %eax
movq %rax, 0x13d85(%rip)     # 0x22340
movq %rax, 0x13d86(%rip)     # 0x22348
movl $0x0, 0x13d84(%rip)     # 0x22350
movl $0x3, 0x13d7e(%rip)     # 0x22354
movb $0x0, 0x13d7b(%rip)     # 0x22358
movl $0xffffffff, 0x13d75(%rip) # imm = 0xFFFFFFFF
movl $0xff1b, 0x13d6f(%rip)  # imm = 0xFF1B
leaq 0x2a84(%rip), %r15      # 0x1107c
movq 0xb9d9(%rip), %r13      # 0x19fd8
leaq 0x29fe(%rip), %r12      # 0x11004
xorl %ebx, %ebx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0xe380
cmpl $0x67, %eax
jle 0xe652
addl $-0x68, %eax
cmpl $0xe, %eax
ja 0xe608
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r13), %rdi
leaq 0x2a66(%rip), %rsi      # 0x1109c
leaq 0x13d13(%rip), %rdx     # 0x22350
xorl %eax, %eax
callq 0xe290
cmpl $0x1, %eax
je 0xe608
leaq 0x2a4f(%rip), %rdi      # 0x1109f
jmp 0xe69e
cmpl $0x61, %eax
je 0xe6be
cmpl $0x63, %eax
jne 0xe6ed
movq (%r13), %rax
movq %rax, 0x13cdd(%rip)     # 0x22348
jmp 0xe608
movq (%r13), %rbx
jmp 0xe608
movq (%r13), %rdi
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0xe320
movl %eax, 0x13cce(%rip)     # 0x2235c
cmpl $-0x1, %eax
jne 0xe608
leaq 0x2a1d(%rip), %rdi      # 0x110bb
xorl %eax, %eax
callq 0xe410
jmp 0xe608
movq (%r13), %rdi
callq 0xe370
movl %eax, 0x13c9b(%rip)     # 0x22354
jmp 0xe608
movq (%r13), %rdi
leaq 0x13c97(%rip), %rsi     # 0x22360
callq 0x103ca
testb %al, %al
jne 0xe608
movq (%r13), %rsi
leaq 0x2a08(%rip), %rdi      # 0x110e9
xorl %eax, %eax
callq 0xe410
jmp 0xe608
cmpl $-0x1, %eax
jne 0xe608
movq 0xb8d3(%rip), %rax      # 0x19fd0
movslq (%rax), %rax
subl %eax, %ebp
movl %ebp, 0x13c5c(%rip)     # 0x22364
leaq (%r14,%rax,8), %rax
movq %rax, 0x13c55(%rip)     # 0x22368
movq 0x13c2e(%rip), %rcx     # 0x22348
testq %rcx, %rcx
je 0xe73b
leaq 0x13c4a(%rip), %rdi     # 0x22370
leaq 0x29fa(%rip), %rdx      # 0x11127
movl $0x100, %esi            # imm = 0x100
xorl %eax, %eax
callq 0xe170
jmp 0xe7a9
leaq 0x29c1(%rip), %rdi      # 0x11103
callq 0xe030
testq %rax, %rax
je 0xe772
leaq 0x13c1d(%rip), %rdi     # 0x22370
leaq 0x29ca(%rip), %rdx      # 0x11124
leaq 0x29b2(%rip), %r8       # 0x11113
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
xorl %eax, %eax
callq 0xe170
jmp 0xe7a9
leaq 0x2995(%rip), %rdi      # 0x1110e
callq 0xe030
leaq 0x13beb(%rip), %rdi     # 0x22370
leaq 0x2995(%rip), %rdx      # 0x11121
leaq 0x2997(%rip), %r8       # 0x1112a
leaq 0x2979(%rip), %r9       # 0x11113
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
xorl %eax, %eax
callq 0xe170
testq %rbx, %rbx
je 0xe7e7
movq %rbx, %rdi
movl $0x802, %esi            # imm = 0x802
xorl %eax, %eax
callq 0xe320
cmpl $-0x1, %eax
je 0xe7d9
leaq 0x5488(%rip), %rsi      # 0x13c51
movl %eax, %edi
callq 0xe2e0
movq %rax, 0x13b69(%rip)     # 0x22340
jmp 0xe7e7
leaq 0x2952(%rip), %rdi      # 0x11132
xorl %eax, %eax
callq 0xe410
leaq 0x309(%rip), %rbx       # 0xeaf7
movl $0x2, %edi
movq %rbx, %rsi
callq 0xe240
movl $0x1, %edi
movq %rbx, %rsi
callq 0xe240
movl $0xf, %edi
movq %rbx, %rsi
callq 0xe240
movl $0xa, %edi
movq %rbx, %rsi
callq 0xe240
movl $0xc, %edi
movq %rbx, %rsi
callq 0xe240
movl $0xe, %edi
movq %rbx, %rsi
callq 0xe240
callq 0xeb2e
callq 0x1050b
callq 0x1069b
movl 0x13b0f(%rip), %edi     # 0x22360
xorl %esi, %esi
xorl %edx, %edx
movl $0x2, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10c64
movq %rax, 0x13c04(%rip)     # 0x22470
leaq 0x13afd(%rip), %rdi     # 0x22370
callq 0xf4b0
cmpl $0x0, 0x13ae5(%rip)     # 0x22364
jle 0xe8a2
xorl %ebx, %ebx
movq 0x13ade(%rip), %rax     # 0x22368
movq (%rax,%rbx,8), %rdi
callq 0xf4b0
incq %rbx
movslq 0x13ac7(%rip), %rax     # 0x22364
cmpq %rax, %rbx
jl 0xe883
callq 0xeeec
movq 0x13bca(%rip), %rdi     # 0x22478
callq 0xe060
movl %eax, %ebx
xorl %eax, %eax
movb %al, 0x13bc3(%rip)      # 0x22480
movb %al, 0x13bbe(%rip)      # 0x22481
movb %al, 0x13bb9(%rip)      # 0x22482
movb %al, 0x13bb4(%rip)      # 0x22483
movb %al, 0x13baf(%rip)      # 0x22484
movb $0x1, 0x13ba9(%rip)     # 0x22485
movq 0x13b95(%rip), %rdi     # 0x22478
callq 0xe140
cmpb $0x1, 0x13b96(%rip)     # 0x22485
jne 0xea78
leal 0x3f(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %ebx, %ecx
subl %edx, %ecx
movl $0x1, %ebp
shlq %cl, %rbp
sarl $0x6, %eax
movslq %eax, %r12
incl %ebx
movq %rsp, %r14
leaq 0x1d7(%rip), %r15       # 0xeaf7
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
orq %rbp, (%rsp,%r12,8)
movl %ebx, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xe260
testl %eax, %eax
jle 0xe9bd
movq 0x13b0e(%rip), %rdi     # 0x22478
callq 0xe2b0
testq %rax, %rax
je 0xe9bd
movq %rax, %r13
movzbl (%r13), %eax
andl $0x7f, %eax
leal -0x2(%rax), %ecx
cmpl $0x4, %ecx
jae 0xe994
movzbl %al, %esi
movq %r13, %rdi
callq 0xec77
jmp 0xe9a1
cmpl $0x22, %eax
jne 0xe9a1
movq %r13, %rdi
callq 0xed9d
movq %r13, %rdi
callq 0xe040
movq 0x13ac8(%rip), %rdi     # 0x22478
callq 0xe2b0
movq %rax, %r13
testq %rax, %rax
jne 0xe977
cmpb $0x1, 0x13ac0(%rip)     # 0x22484
jne 0xe9df
movl $0xa, %edi
movq %r15, %rsi
callq 0xe240
callq 0xee0f
movb $0x0, 0x13aa5(%rip)     # 0x22484
cmpb $0x1, 0x13a9d(%rip)     # 0x22483
jne 0xea11
movl $0xc, %edi
movq %r15, %rsi
callq 0xe240
cmpb $0x1, 0x1395c(%rip)     # 0x22358
jne 0xea05
callq 0xf252
jmp 0xea0a
callq 0xeeec
movb $0x0, 0x13a72(%rip)     # 0x22483
cmpb $0x1, 0x13a6a(%rip)     # 0x22482
jne 0xea44
movl $0xe, %edi
movq %r15, %rsi
callq 0xe240
movl $0x54, %edi
leaq 0x271b(%rip), %rsi      # 0x1114e
callq 0xee68
callq 0x10b4f
movb $0x0, 0x13a3e(%rip)     # 0x22482
movq 0x13a2d(%rip), %rdi     # 0x22478
callq 0xe310
testl %eax, %eax
jne 0xea63
testb $0x1, 0x13a2a(%rip)     # 0x22485
jne 0xe920
jmp 0xea78
leaq 0x26f4(%rip), %rdi      # 0x1115e
xorl %eax, %eax
callq 0xe410
movb $0x0, 0x13a0d(%rip)     # 0x22485
movl 0x138de(%rip), %edi     # 0x2235c
cmpl $-0x1, %edi
je 0xea88
callq 0xe1d0
movq 0x138b1(%rip), %rdi     # 0x22340
testq %rdi, %rdi
je 0xea99
callq 0xe0f0
callq 0xf252
callq 0xee99
movq 0x139c6(%rip), %rdi     # 0x22470
callq 0x10f89
movq 0x139d2(%rip), %rdi     # 0x22488
callq 0xe2c0
movq 0x139b6(%rip), %rdi     # 0x22478
callq 0xe300
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25a9(%rip), %rdi      # 0x1108b
jmp 0xeaeb
leaq 0x270d(%rip), %rdi      # 0x111f8
callq 0xe090
xorl %edi, %edi
callq 0xe3a0