// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x13e28(%rip)     # 0x22340
movl %edi, %ebp
andq $0x0, 0x13e26(%rip)     # 0x22348
andl $0x0, 0x13e27(%rip)     # 0x22350
movl $0x3, 0x13e21(%rip)     # 0x22354
movb $0x0, 0x13e1e(%rip)     # 0x22358
orl $-0x1, 0x13e1b(%rip)    # 0x2235c
movl $0xff1b, 0x13e15(%rip)  # imm = 0xFF1B
leaq 0x2b2a(%rip), %r15      # 0x1107c
movq 0xba7f(%rip), %r12      # 0x19fd8
leaq 0x2aa4(%rip), %r13      # 0x11004
xorl %ebx, %ebx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0xe380
leal -0x68(%rax), %ecx
cmpl $0xe, %ecx
ja 0xe5a8
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r12), %rdi
leaq 0x2b10(%rip), %rsi      # 0x1109c
leaq 0x13dbd(%rip), %rdx     # 0x22350
xorl %eax, %eax
callq 0xe290
cmpl $0x1, %eax
je 0xe562
leaq 0x2af9(%rip), %rdi      # 0x1109f
jmp 0xe5e1
cmpl $0x61, %eax
je 0xe61a
cmpl $0x63, %eax
je 0xe60a
cmpl $-0x1, %eax
jne 0xe562
jmp 0xe649
movq (%r12), %rdi
pushq $0x41
popq %rsi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0xe320
movl %eax, 0x13d87(%rip)     # 0x2235c
cmpl $-0x1, %eax
jne 0xe562
leaq 0x2ada(%rip), %rdi      # 0x110bb
xorl %eax, %eax
callq 0xf160
jmp 0xe562
movq (%r12), %rdi
callq 0xe370
movl %eax, 0x13d58(%rip)     # 0x22354
jmp 0xe562
movq (%r12), %rbx
jmp 0xe562
movq (%r12), %rax
movq %rax, 0x13d33(%rip)     # 0x22348
jmp 0xe562
movq (%r12), %rdi
leaq 0x13d3b(%rip), %rsi     # 0x22360
callq 0x10201
testb %al, %al
jne 0xe562
movq (%r12), %rsi
leaq 0x2aac(%rip), %rdi      # 0x110e9
xorl %eax, %eax
callq 0xf160
jmp 0xe562
movq 0xb980(%rip), %rax      # 0x19fd0
movslq (%rax), %rax
subl %eax, %ebp
movl %ebp, 0x13d09(%rip)     # 0x22364
leaq (%r14,%rax,8), %rax
movq %rax, 0x13d02(%rip)     # 0x22368
movq 0x13cdb(%rip), %rcx     # 0x22348
testq %rcx, %rcx
je 0xe68e
leaq 0x13cf7(%rip), %rdi     # 0x22370
leaq 0x2aa7(%rip), %rdx      # 0x11127
movl $0x100, %esi            # imm = 0x100
xorl %eax, %eax
callq 0xe170
jmp 0xe6fc
leaq 0x2a6e(%rip), %rdi      # 0x11103
callq 0xe030
testq %rax, %rax
je 0xe6c5
leaq 0x13cca(%rip), %rdi     # 0x22370
leaq 0x2a77(%rip), %rdx      # 0x11124
leaq 0x2a5f(%rip), %r8       # 0x11113
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
xorl %eax, %eax
callq 0xe170
jmp 0xe6fc
leaq 0x2a42(%rip), %rdi      # 0x1110e
callq 0xe030
leaq 0x13c98(%rip), %rdi     # 0x22370
leaq 0x2a42(%rip), %rdx      # 0x11121
leaq 0x2a44(%rip), %r8       # 0x1112a
leaq 0x2a26(%rip), %r9       # 0x11113
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
xorl %eax, %eax
callq 0xe170
testq %rbx, %rbx
je 0xe73a
movq %rbx, %rdi
movl $0x802, %esi            # imm = 0x802
xorl %eax, %eax
callq 0xe320
cmpl $-0x1, %eax
je 0xe72c
leaq 0x5535(%rip), %rsi      # 0x13c51
movl %eax, %edi
callq 0xe2e0
movq %rax, 0x13c16(%rip)     # 0x22340
jmp 0xe73a
leaq 0x29ff(%rip), %rdi      # 0x11132
xorl %eax, %eax
callq 0xf160
leaq 0x2aa(%rip), %r14       # 0xe9eb
pushq $0x2
popq %rbx
movl %ebx, %edi
movq %r14, %rsi
callq 0xe240
pushq $0x1
popq %rdi
movq %r14, %rsi
callq 0xe240
pushq $0xf
popq %rdi
movq %r14, %rsi
callq 0xe240
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0xe240
pushq $0xc
popq %rdi
movq %r14, %rsi
callq 0xe240
pushq $0xe
popq %rdi
movq %r14, %rsi
callq 0xe240
callq 0xea22
callq 0x10313
callq 0x104a3
movl 0x13bc6(%rip), %edi     # 0x22360
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x109d8
movq %rax, 0x13cbb(%rip)     # 0x22470
leaq 0x13bb4(%rip), %rdi     # 0x22370
callq 0xf3fc
movslq 0x13b9c(%rip), %rax     # 0x22364
cmpq %rax, %r14
jge 0xe7e2
movq 0x13b94(%rip), %rax     # 0x22368
movq (%rax,%r14,8), %rdi
callq 0xf3fc
incq %r14
jmp 0xe7c1
callq 0xedbc
movq 0x13c8a(%rip), %rdi     # 0x22478
callq 0xe060
movl %eax, %ebx
xorl %eax, %eax
movb %al, 0x13c83(%rip)      # 0x22480
movb %al, 0x13c7e(%rip)      # 0x22481
movb %al, 0x13c79(%rip)      # 0x22482
movb %al, 0x13c74(%rip)      # 0x22483
movb %al, 0x13c6f(%rip)      # 0x22484
movb $0x1, 0x13c69(%rip)     # 0x22485
movq 0x13c55(%rip), %rdi     # 0x22478
callq 0xe140
pushq $0x40
popq %rcx
movl %ebx, %eax
cltd
idivl %ecx
movslq %eax, %r12
shll $0x6, %eax
movl %ebx, %ecx
subl %eax, %ecx
pushq $0x1
popq %r13
shlq %cl, %r13
incl %ebx
leaq 0x8(%rsp), %r14
leaq 0x19c(%rip), %r15       # 0xe9eb
cmpb $0x1, 0x13c2f(%rip)     # 0x22485
jne 0xe96c
xorl %eax, %eax
cmpq $0x10, %rax
je 0xe86f
andq $0x0, 0x8(%rsp,%rax,8)
incq %rax
jmp 0xe85e
orq %r13, 0x8(%rsp,%r12,8)
movl %ebx, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xe260
testl %eax, %eax
jle 0xe8cf
movq 0x13be8(%rip), %rdi     # 0x22478
callq 0xe2b0
testq %rax, %rax
je 0xe8cf
movq %rax, %rbp
movzbl (%rax), %eax
andl $0x7f, %eax
leal -0x2(%rax), %ecx
cmpl $0x4, %ecx
jae 0xe8c0
movzbl %al, %esi
movq %rbp, %rdi
callq 0xeb63
movq %rbp, %rdi
callq 0xe040
jmp 0xe889
cmpl $0x22, %eax
jne 0xe8b6
movq %rbp, %rdi
callq 0xec78
jmp 0xe8b6
cmpb $0x1, 0x13bae(%rip)     # 0x22484
jne 0xe8ef
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0xe240
callq 0xece8
movb $0x0, 0x13b95(%rip)     # 0x22484
cmpb $0x1, 0x13b8d(%rip)     # 0x22483
jne 0xe90f
pushq $0xc
popq %rdi
movq %r15, %rsi
callq 0xe240
callq 0xed28
movb $0x0, 0x13b74(%rip)     # 0x22483
cmpb $0x1, 0x13b6c(%rip)     # 0x22482
jne 0xe93e
pushq $0xe
popq %rdi
movq %r15, %rsi
callq 0xe240
pushq $0x54
popq %rdi
leaq 0x2821(%rip), %rsi      # 0x1114e
callq 0xed3a
callq 0x108f5
movb $0x0, 0x13b44(%rip)     # 0x22482
movq 0x13b33(%rip), %rdi     # 0x22478
callq 0xe310
testl %eax, %eax
je 0xe84f
leaq 0x2805(%rip), %rdi      # 0x1115e
xorl %eax, %eax
callq 0xf160
movb $0x0, 0x13b1e(%rip)     # 0x22485
jmp 0xe84f
movl 0x139ea(%rip), %edi     # 0x2235c
cmpl $-0x1, %edi
je 0xe97c
callq 0xe1d0
movq 0x139bd(%rip), %rdi     # 0x22340
testq %rdi, %rdi
je 0xe98d
callq 0xe0f0
callq 0xf10d
callq 0xed6b
movq 0x13ad2(%rip), %rdi     # 0x22470
callq 0x10cdd
movq 0x13ade(%rip), %rdi     # 0x22488
callq 0xe2c0
movq 0x13ac2(%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 0x26b5(%rip), %rdi      # 0x1108b
jmp 0xe9df
leaq 0x2819(%rip), %rdi      # 0x111f8
callq 0xe090
xorl %edi, %edi
callq 0xe3a0