// File: /workspace/github_c_makefile_star2_O1/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, 0x14d85(%rip)     # 0x23340
movq %rax, 0x14d86(%rip)     # 0x23348
movl $0x0, 0x14d84(%rip)     # 0x23350
movl $0x3, 0x14d7e(%rip)     # 0x23354
movb $0x0, 0x14d7b(%rip)     # 0x23358
movl $0xffffffff, 0x14d75(%rip) # imm = 0xFFFFFFFF
movl $0xff1b, 0x14d6f(%rip)  # imm = 0xFF1B
leaq 0x3a84(%rip), %r15      # 0x1207c
movq 0xc9d9(%rip), %r13      # 0x1afd8
leaq 0x39fe(%rip), %r12      # 0x12004
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 0x3a66(%rip), %rsi      # 0x1209c
leaq 0x14d13(%rip), %rdx     # 0x23350
xorl %eax, %eax
callq 0xe290
cmpl $0x1, %eax
je 0xe608
leaq 0x3a4f(%rip), %rdi      # 0x1209f
jmp 0xe69e
cmpl $0x61, %eax
je 0xe6be
cmpl $0x63, %eax
jne 0xe6ed
movq (%r13), %rax
movq %rax, 0x14cdd(%rip)     # 0x23348
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, 0x14cce(%rip)     # 0x2335c
cmpl $-0x1, %eax
jne 0xe608
leaq 0x3a1d(%rip), %rdi      # 0x120bb
xorl %eax, %eax
callq 0xe410
jmp 0xe608
movq (%r13), %rdi
callq 0xe370
movl %eax, 0x14c9b(%rip)     # 0x23354
jmp 0xe608
movq (%r13), %rdi
leaq 0x14c97(%rip), %rsi     # 0x23360
callq 0x104be
testb %al, %al
jne 0xe608
movq (%r13), %rsi
leaq 0x3a08(%rip), %rdi      # 0x120e9
xorl %eax, %eax
callq 0xe410
jmp 0xe608
cmpl $-0x1, %eax
jne 0xe608
movq 0xc8d3(%rip), %rax      # 0x1afd0
movslq (%rax), %rax
subl %eax, %ebp
movl %ebp, 0x14c5c(%rip)     # 0x23364
leaq (%r14,%rax,8), %rax
movq %rax, 0x14c55(%rip)     # 0x23368
movq 0x14c2e(%rip), %rcx     # 0x23348
testq %rcx, %rcx
je 0xe73b
leaq 0x14c4a(%rip), %rdi     # 0x23370
leaq 0x39fa(%rip), %rdx      # 0x12127
movl $0x100, %esi            # imm = 0x100
xorl %eax, %eax
callq 0xe170
jmp 0xe7a9
leaq 0x39c1(%rip), %rdi      # 0x12103
callq 0xe030
testq %rax, %rax
je 0xe772
leaq 0x14c1d(%rip), %rdi     # 0x23370
leaq 0x39ca(%rip), %rdx      # 0x12124
leaq 0x39b2(%rip), %r8       # 0x12113
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
xorl %eax, %eax
callq 0xe170
jmp 0xe7a9
leaq 0x3995(%rip), %rdi      # 0x1210e
callq 0xe030
leaq 0x14beb(%rip), %rdi     # 0x23370
leaq 0x3995(%rip), %rdx      # 0x12121
leaq 0x3997(%rip), %r8       # 0x1212a
leaq 0x3979(%rip), %r9       # 0x12113
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 0x6488(%rip), %rsi      # 0x14c51
movl %eax, %edi
callq 0xe2e0
movq %rax, 0x14b69(%rip)     # 0x23340
jmp 0xe7e7
leaq 0x3952(%rip), %rdi      # 0x12132
xorl %eax, %eax
callq 0xe410
leaq 0x307(%rip), %rbx       # 0xeaf5
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 0xeb2c
callq 0x105f8
callq 0x10788
movl 0x14b0f(%rip), %edi     # 0x23360
xorl %esi, %esi
xorl %edx, %edx
movl $0x2, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10e11
movq %rax, 0x14c04(%rip)     # 0x23470
leaq 0x14afd(%rip), %rdi     # 0x23370
callq 0xf4bc
cmpl $0x0, 0x14ae5(%rip)     # 0x23364
jle 0xe8a2
xorl %ebx, %ebx
movq 0x14ade(%rip), %rax     # 0x23368
movq (%rax,%rbx,8), %rdi
callq 0xf4bc
incq %rbx
movslq 0x14ac7(%rip), %rax     # 0x23364
cmpq %rax, %rbx
jl 0xe883
callq 0xeef8
movq 0x14bca(%rip), %rdi     # 0x23478
callq 0xe060
movl %eax, %ebx
xorl %eax, %eax
movb %al, 0x14bc3(%rip)      # 0x23480
movb %al, 0x14bbe(%rip)      # 0x23481
movb %al, 0x14bb9(%rip)      # 0x23482
movb %al, 0x14bb4(%rip)      # 0x23483
movb %al, 0x14baf(%rip)      # 0x23484
movb $0x1, 0x14ba9(%rip)     # 0x23485
movq 0x14b95(%rip), %rdi     # 0x23478
callq 0xe140
cmpb $0x1, 0x14b96(%rip)     # 0x23485
jne 0xea76
leal 0x3f(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %ebx, %ecx
subl %edx, %ecx
movl $0x1, %r12d
shlq %cl, %r12
sarl $0x6, %eax
movslq %eax, %r13
incl %ebx
movq %rsp, %r14
leaq 0x1d4(%rip), %r15       # 0xeaf5
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 %r12, (%rsp,%r13,8)
movl %ebx, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xe260
testl %eax, %eax
jle 0xe9bd
movq 0x14b0d(%rip), %rdi     # 0x23478
callq 0xe2b0
testq %rax, %rax
je 0xe9bd
movq %rax, %rbp
movzbl (%rbp), %eax
andl $0x7f, %eax
leal -0x2(%rax), %ecx
cmpl $0x4, %ecx
jae 0xe994
movzbl %al, %esi
movq %rbp, %rdi
callq 0xec82
jmp 0xe9a1
cmpl $0x22, %eax
jne 0xe9a1
movq %rbp, %rdi
callq 0xeda8
movq %rbp, %rdi
callq 0xe040
movq 0x14ac8(%rip), %rdi     # 0x23478
callq 0xe2b0
movq %rax, %rbp
testq %rax, %rax
jne 0xe978
cmpb $0x1, 0x14ac0(%rip)     # 0x23484
jne 0xe9df
movl $0xa, %edi
movq %r15, %rsi
callq 0xe240
callq 0xee1a
movb $0x0, 0x14aa5(%rip)     # 0x23484
cmpb $0x1, 0x14a9d(%rip)     # 0x23483
jne 0xea11
movl $0xc, %edi
movq %r15, %rsi
callq 0xe240
cmpb $0x1, 0x1495c(%rip)     # 0x23358
jne 0xea05
callq 0xf25d
jmp 0xea0a
callq 0xeef8
movb $0x0, 0x14a72(%rip)     # 0x23483
cmpb $0x1, 0x14a6a(%rip)     # 0x23482
jne 0xea44
movl $0xe, %edi
movq %r15, %rsi
callq 0xe240
movl $0x54, %edi
leaq 0x371b(%rip), %rsi      # 0x1214e
callq 0xee73
callq 0x10ce8
movb $0x0, 0x14a3e(%rip)     # 0x23482
movq 0x14a2d(%rip), %rdi     # 0x23478
callq 0xe310
testl %eax, %eax
je 0xea69
leaq 0x3703(%rip), %rdi      # 0x1215e
xorl %eax, %eax
callq 0xe410
movb $0x0, 0x14a1c(%rip)     # 0x23485
cmpb $0x0, 0x14a15(%rip)     # 0x23485
jne 0xe921
movl 0x148e0(%rip), %edi     # 0x2335c
cmpl $-0x1, %edi
je 0xea86
callq 0xe1d0
movq 0x148b3(%rip), %rdi     # 0x23340
testq %rdi, %rdi
je 0xea97
callq 0xe0f0
callq 0xf25d
callq 0xeea4
movq 0x149c8(%rip), %rdi     # 0x23470
callq 0x11179
movq 0x149d4(%rip), %rdi     # 0x23488
callq 0xe2c0
movq 0x149b8(%rip), %rdi     # 0x23478
callq 0xe300
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x35ab(%rip), %rdi      # 0x1208b
jmp 0xeae9
leaq 0x370f(%rip), %rdi      # 0x121f8
callq 0xe090
xorl %edi, %edi
callq 0xe3a0