// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/yaft.c
// Function: main
int main(int argc, char *const argv[])
{
	extern const char *shell_cmd; /* defined in conf.h */
	const char *cmd;
	uint8_t buf[BUFSIZE];
	ssize_t size;
	fd_set fds;
	struct timeval tv;
	struct framebuffer_t fb;
	struct terminal_t term;
	/* global */
	extern volatile sig_atomic_t need_redraw;
	extern volatile sig_atomic_t child_alive;
	extern struct termios termios_orig;

	/* init */
	if (setlocale(LC_ALL, "") == NULL) /* for wcwidth() */
		logging(WARN, "setlocale falied\n");

	if (!fb_init(&fb)) {
		logging(FATAL, "framebuffer initialize failed\n");
		goto fb_init_failed;
	}

	if (!term_init(&term, fb.info.width, fb.info.height)) {
		logging(FATAL, "terminal initialize failed\n");
		goto term_init_failed;
	}

	if (!tty_init(&termios_orig)) {
		logging(FATAL, "tty initialize failed\n");
		goto tty_init_failed;
	}

	/* fork and exec shell */
	cmd = (argc < 2) ? shell_cmd: argv[1];
	if (!fork_and_exec(&term.fd, cmd, argv + 1, term.lines, term.cols)) {
		logging(FATAL, "forkpty failed\n");
		goto tty_init_failed;
	}
	child_alive = true;

	/* main loop */
	while (child_alive) {
		if (need_redraw) {
			need_redraw = false;
			cmap_update(fb.fd, fb.cmap); /* after VT switching, need to restore cmap (in 8bpp mode) */
			redraw(&term);
			refresh(&fb, &term);
		}

		if (check_fds(&fds, &tv, STDIN_FILENO, term.fd) == -1)
			continue;

		if (FD_ISSET(STDIN_FILENO, &fds)) {
			if ((size = read(STDIN_FILENO, buf, BUFSIZE)) > 0)
				ewrite(term.fd, buf, size);
		}
		if (FD_ISSET(term.fd, &fds)) {
			if ((size = read(term.fd, buf, BUFSIZE)) > 0) {
				if (VERBOSE)
					ewrite(STDOUT_FILENO, buf, size);
				parse(&term, buf, size);
				if (LAZY_DRAW && size == BUFSIZE)
					continue; /* maybe more data arrives soon */
				refresh(&fb, &term);
			}
		}
	}

	/* normal exit */
	tty_die(&termios_orig);
	term_die(&term);
	fb_die(&fb);
	return EXIT_SUCCESS;

	/* error exit */
tty_init_failed:
	term_die(&term);
term_init_failed:
	fb_die(&fb);
fb_init_failed:
	return EXIT_FAILURE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xbc2e0, %rsp          # imm = 0xBC2E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x6, %edi
leaq 0x4bc0a(%rip), %rsi     # 0x5577f
callq 0x2230
cmpq $0x0, %rax
jne 0x9b93
movl $0x1, %edi
leaq 0x4c496(%rip), %rsi     # 0x56022
movb $0x0, %al
callq 0x2450
leaq -0x928(%rbp), %rdi
callq 0x3e90
testb $0x1, %al
jne 0x9bbb
movl $0x3, %edi
leaq 0x4c485(%rip), %rsi     # 0x56034
movb $0x0, %al
callq 0x2450
jmp 0x9e50
movl -0x4f0(%rbp), %esi
movl -0x4ec(%rbp), %edx
leaq -0xbc2d0(%rbp), %rdi
callq 0x55e0
testb $0x1, %al
jne 0x9bef
movl $0x3, %edi
leaq 0x4c470(%rip), %rsi     # 0x56053
movb $0x0, %al
callq 0x2450
jmp 0x9e44
leaq 0x50016(%rip), %rdi     # 0x59c0c
callq 0x9760
testb $0x1, %al
jne 0x9c17
movl $0x3, %edi
leaq 0x4c464(%rip), %rsi     # 0x5606f
movb $0x0, %al
callq 0x2450
jmp 0x9e38
cmpl $0x2, -0x8(%rbp)
jge 0x9c2d
movq 0x4f5b4(%rip), %rax     # 0x591d8
movq %rax, -0xbc2d8(%rbp)
jmp 0x9c3c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xbc2d8(%rbp)
movq -0xbc2d8(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq -0xbc2d0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movl -0xbc2c0(%rbp), %ecx
movl -0xbc2c4(%rbp), %r8d
callq 0x9990
testb $0x1, %al
jne 0x9c88
movl $0x3, %edi
leaq 0x4c40a(%rip), %rsi     # 0x56086
movb $0x0, %al
callq 0x2450
jmp 0x9e38
movl $0x1, 0x4ff76(%rip)     # 0x59c08
movl 0x4ff70(%rip), %eax     # 0x59c08
cmpl $0x0, %eax
je 0x9e0b
movl 0x4ff5d(%rip), %eax     # 0x59c04
cmpl $0x0, %eax
je 0x9ce7
movl $0x0, 0x4ff4e(%rip)     # 0x59c04
movl -0x928(%rbp), %edi
movq -0x4c8(%rbp), %rsi
callq 0x3760
leaq -0xbc2d0(%rbp), %rdi
callq 0x5510
leaq -0x928(%rbp), %rdi
leaq -0xbc2d0(%rbp), %rsi
callq 0x42b0
movl -0xbc2d0(%rbp), %ecx
leaq -0x4a8(%rbp), %rdi
leaq -0x4b8(%rbp), %rsi
xorl %edx, %edx
callq 0x9a40
cmpl $-0x1, %eax
jne 0x9d09
jmp 0x9c92
movq -0x4a8(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x9d55
leaq -0x420(%rbp), %rsi
xorl %edi, %edi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rax, -0x428(%rbp)
cmpq $0x0, %rax
jle 0x9d53
movl -0xbc2d0(%rbp), %edi
leaq -0x420(%rbp), %rsi
movq -0x428(%rbp), %rdx
callq 0x2930
jmp 0x9d55
movl -0xbc2d0(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x4a8(%rbp,%rax,8), %rax
movq %rax, -0xbc2e0(%rbp)
movl -0xbc2d0(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xbc2e0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x9e06
movl -0xbc2d0(%rbp), %edi
leaq -0x420(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
movq %rax, -0x428(%rbp)
cmpq $0x0, %rax
jle 0x9e04
leaq -0x420(%rbp), %rsi
movq -0x428(%rbp), %rax
movl %eax, %edx
leaq -0xbc2d0(%rbp), %rdi
callq 0x9490
cmpq $0x400, -0x428(%rbp) # imm = 0x400
jne 0x9df1
jmp 0x9c92
leaq -0x928(%rbp), %rdi
leaq -0xbc2d0(%rbp), %rsi
callq 0x42b0
jmp 0x9e06
jmp 0x9c92
leaq 0x4fdfa(%rip), %rdi     # 0x59c0c
callq 0x9890
leaq -0xbc2d0(%rbp), %rdi
callq 0x5550
leaq -0x928(%rbp), %rdi
callq 0x4210
movl $0x0, -0x4(%rbp)
jmp 0x9e57
leaq -0xbc2d0(%rbp), %rdi
callq 0x5550
leaq -0x928(%rbp), %rdi
callq 0x4210
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xbc2e0, %rsp          # imm = 0xBC2E0
popq %rbp
retq
nopw %cs:(%rax,%rax)