// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, 0x14e14(%rip) # 0x23350
movq $0x0, 0x14e11(%rip) # 0x23358
movl $0x0, 0x14e0f(%rip)     # 0x23360
movl $0x3, 0x14e09(%rip)     # 0x23364
movb $0x0, 0x14e06(%rip)     # 0x23368
movl $0xffffffff, 0x14e00(%rip) # imm = 0xFFFFFFFF
movl $0xff1b, 0x14dfa(%rip)  # imm = 0xFF1B
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x4ad8(%rip), %rdx      # 0x1305c
callq 0xe380
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0xe6dc
movl -0x14(%rbp), %eax
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, -0xe0(%rbp)
subl $0x15, %eax
ja 0xe6d7
movq -0xe0(%rbp), %rax
leaq 0x4a49(%rip), %rcx      # 0x13004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4c7b(%rip), %rdi      # 0x13246
leaq 0x4a99(%rip), %rsi      # 0x1306b
movb $0x0, %al
callq 0xe160
xorl %edi, %edi
callq 0xe3a0
leaq 0x4a95(%rip), %rdi      # 0x1307c
movb $0x0, %al
callq 0xe160
xorl %edi, %edi
callq 0xe3a0
movq 0xc9dc(%rip), %rax      # 0x1afd8
movq (%rax), %rdi
leaq 0x4ae8(%rip), %rsi      # 0x130ee
leaq 0x14d53(%rip), %rdx     # 0x23360
movb $0x0, %al
callq 0xe290
cmpl $0x1, %eax
je 0xe627
leaq 0x4ad1(%rip), %rdi      # 0x130f1
movb $0x0, %al
callq 0xf640
jmp 0xe6d7
movq 0xc9a5(%rip), %rax      # 0x1afd8
movq (%rax), %rdi
callq 0xe370
movl %eax, 0x14d23(%rip)     # 0x23364
jmp 0xe6d7
movq 0xc98b(%rip), %rax      # 0x1afd8
movq (%rax), %rax
movq %rax, 0x14d01(%rip)     # 0x23358
jmp 0xe6d7
movq 0xc978(%rip), %rax      # 0x1afd8
movq (%rax), %rdi
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0xe320
movl %eax, 0x14cf2(%rip)     # 0x2336c
cmpl $-0x1, 0x14ceb(%rip)    # 0x2336c
jne 0xe691
leaq 0x4a83(%rip), %rdi      # 0x1310d
movb $0x0, %al
callq 0xf640
jmp 0xe6d7
movq 0xc93e(%rip), %rax      # 0x1afd8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xe6d7
movq 0xc92e(%rip), %rax      # 0x1afd8
movq (%rax), %rdi
leaq 0x14cbc(%rip), %rsi     # 0x23370
callq 0x110e0
testb $0x1, %al
jne 0xe6d5
movq 0xc914(%rip), %rax      # 0x1afd8
movq (%rax), %rsi
leaq 0x4a6d(%rip), %rdi      # 0x1313b
movb $0x0, %al
callq 0xf640
jmp 0xe6d7
jmp 0xe576
movl -0x8(%rbp), %eax
movq 0xc8ea(%rip), %rcx      # 0x1afd0
subl (%rcx), %eax
movl %eax, 0x14c86(%rip)     # 0x23374
movq -0x10(%rbp), %rax
movq 0xc8d7(%rip), %rcx      # 0x1afd0
movslq (%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x14c6e(%rip)     # 0x23378
cmpq $0x0, 0x14c46(%rip)     # 0x23358
jne 0xe78b
leaq 0x4a3a(%rip), %rdi      # 0x13155
callq 0xe030
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xe752
movq -0x28(%rbp), %rcx
leaq 0x14c4a(%rip), %rdi     # 0x23380
movl $0x100, %esi            # imm = 0x100
leaq 0x4a34(%rip), %rdx      # 0x13176
leaq 0x4a1c(%rip), %r8       # 0x13165
movb $0x0, %al
callq 0xe170
jmp 0xe789
leaq 0x4a07(%rip), %rdi      # 0x13160
callq 0xe030
movq %rax, %rcx
leaq 0x14c18(%rip), %rdi     # 0x23380
movl $0x100, %esi            # imm = 0x100
leaq 0x49ff(%rip), %rdx      # 0x13173
leaq 0x4a01(%rip), %r8       # 0x1317c
leaq 0x49e3(%rip), %r9       # 0x13165
movb $0x0, %al
callq 0xe170
jmp 0xe7ac
movq 0x14bc6(%rip), %rcx     # 0x23358
leaq 0x14be7(%rip), %rdi     # 0x23380
movl $0x100, %esi            # imm = 0x100
leaq 0x49d4(%rip), %rdx      # 0x13179
movb $0x0, %al
callq 0xe170
cmpq $0x0, -0x20(%rbp)
je 0xe7f4
movq -0x20(%rbp), %rdi
movl $0x802, %esi            # imm = 0x802
movb $0x0, %al
callq 0xe320
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
je 0xe7e4
movl -0x2c(%rbp), %edi
leaq 0x7449(%rip), %rsi      # 0x15c1f
callq 0xe2e0
movq %rax, 0x14b6e(%rip)     # 0x23350
jmp 0xe7f2
leaq 0x4999(%rip), %rdi      # 0x13184
movb $0x0, %al
callq 0xf640
jmp 0xe7f4
movl $0x2, %edi
leaq 0x350(%rip), %rsi       # 0xeb50
callq 0xe240
movl $0x1, %edi
leaq 0x33f(%rip), %rsi       # 0xeb50
callq 0xe240
movl $0xf, %edi
leaq 0x32e(%rip), %rsi       # 0xeb50
callq 0xe240
movl $0xa, %edi
leaq 0x31d(%rip), %rsi       # 0xeb50
callq 0xe240
movl $0xc, %edi
leaq 0x30c(%rip), %rsi       # 0xeb50
callq 0xe240
movl $0xe, %edi
leaq 0x2fb(%rip), %rsi       # 0xeb50
callq 0xe240
callq 0xebb0
callq 0x112f0
callq 0x114b0
movl 0x14b01(%rip), %edi     # 0x23370
xorl %r9d, %r9d
movl $0x2, %ecx
movl %r9d, %esi
movl %r9d, %edx
movl %r9d, %r8d
callq 0x11ca0
movq %rax, 0x14bf4(%rip)     # 0x23480
leaq 0x14aed(%rip), %rdi     # 0x23380
callq 0xfa10
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl 0x14acc(%rip), %eax     # 0x23374
jge 0xe8c9
movq 0x14ac7(%rip), %rax     # 0x23378
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xfa10
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xe89f
callq 0xf090
movq 0x14bb3(%rip), %rdi     # 0x23488
callq 0xe060
movl %eax, -0x3c(%rbp)
movb $0x0, 0x14bac(%rip)     # 0x23490
movb $0x0, 0x14ba6(%rip)     # 0x23491
movb $0x0, 0x14ba0(%rip)     # 0x23492
movb $0x0, 0x14b9a(%rip)     # 0x23493
movb $0x0, 0x14b94(%rip)     # 0x23494
movb $0x1, 0x14b8e(%rip)     # 0x23495
movq 0x14b7a(%rip), %rdi     # 0x23488
callq 0xe130
testb $0x1, 0x14b7b(%rip)     # 0x23495
je 0xeaeb
jmp 0xe922
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpq $0x10, %rax
jae 0xe96c
movq -0xd0(%rbp), %rax
movl -0xc4(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xe93a
jmp 0xe96e
movl -0x3c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x3c(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xc0(%rbp,%rax,8), %rcx
movq %rcx, -0xc0(%rbp,%rax,8)
movl -0x3c(%rbp), %edi
addl $0x1, %edi
leaq -0xc0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rdx
movq %r8, %rcx
callq 0xe260
cmpl $0x0, %eax
jle 0xea3d
jmp 0xe9c9
movq 0x14ab8(%rip), %rdi     # 0x23488
callq 0xe2b0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0xea3b
movq -0x38(%rbp), %rax
movb (%rax), %al
andb $0x7f, %al
movb %al, -0xd1(%rbp)
movzbl -0xd1(%rbp), %eax
movl %eax, -0xe4(%rbp)
addl $-0x2, %eax
subl $0x4, %eax
jb 0xea11
jmp 0xea04
movl -0xe4(%rbp), %eax
subl $0x22, %eax
je 0xea23
jmp 0xea2e
movq -0x38(%rbp), %rdi
movzbl -0xd1(%rbp), %esi
callq 0xed20
jmp 0xea30
movq -0x38(%rbp), %rdi
callq 0xeea0
jmp 0xea30
jmp 0xea30
movq -0x38(%rbp), %rdi
callq 0xe040
jmp 0xe9c9
jmp 0xea3d
testb $0x1, 0x14a50(%rip)     # 0x23494
je 0xea63
movl $0xa, %edi
leaq 0xfe(%rip), %rsi        # 0xeb50
callq 0xe240
callq 0xef40
movb $0x0, 0x14a31(%rip)     # 0x23494
testb $0x1, 0x14a29(%rip)     # 0x23493
je 0xea89
movl $0xc, %edi
leaq 0xd8(%rip), %rsi        # 0xeb50
callq 0xe240
callq 0xefa0
movb $0x0, 0x14a0a(%rip)     # 0x23493
testb $0x1, 0x14a02(%rip)     # 0x23492
je 0xeac0
movl $0xe, %edi
leaq 0xb2(%rip), %rsi        # 0xeb50
callq 0xe240
movl $0x54, %edi
leaq 0x46f1(%rip), %rsi      # 0x131a0
callq 0xefc0
callq 0x11b00
movb $0x0, 0x149d2(%rip)     # 0x23492
movq 0x149c1(%rip), %rdi     # 0x23488
callq 0xe310
cmpl $0x0, %eax
je 0xeae6
leaq 0x46d8(%rip), %rdi      # 0x131b0
movb $0x0, %al
callq 0xf640
movb $0x0, 0x149af(%rip)     # 0x23495
jmp 0xe913
cmpl $-0x1, 0x1487a(%rip)    # 0x2336c
je 0xeaff
movl 0x14872(%rip), %edi     # 0x2336c
callq 0xe1d0
cmpq $0x0, 0x14849(%rip)     # 0x23350
je 0xeb15
movq 0x14840(%rip), %rdi     # 0x23350
callq 0xe0e0
callq 0xf5d0
callq 0xf010
movq 0x1495a(%rip), %rdi     # 0x23480
callq 0x12260
movq 0x14966(%rip), %rdi     # 0x23498
callq 0xe2c0
movq 0x1494a(%rip), %rdi     # 0x23488
callq 0xe300
xorl %eax, %eax
addq $0xf0, %rsp
popq %rbp
retq
nop