// File: /workspace/github_cpp_makefile_star2_O1/kusumi[P]procstat/main.cc
// Function: main
int main(int argc, char *argv[])
{
	int i, c;
	struct option lo[] = {
		{"fg", 1, 0, 'F'},
		{"bg", 1, 0, 'B'},
		{"noblink", 0, 0, 'N'},
		{"usedelay", 0, 0, 'T'},
		{0, 0, 0, 0},
	};

	while ((c = getopt_long(argc, argv, "c:t:mnfrhu", lo, &i)) != -1) {
		switch (c) {
		case 'c':
			_layout = optarg;
			break;
		case 't':
			sinterval = atoi(optarg);
			break;
		case 'F':
			fgcolor = string_to_color(optarg);
			break;
		case 'B':
			bgcolor = string_to_color(optarg);
			break;
		case 'm':
			_usemsec = true;
			break;
		case 'n':
			showlnum = true;
			break;
		case 'f':
			foldline = true;
			break;
		case 'N':
			blinkline = false;
			break;
		case 'r':
			rotatecol = true;
			break;
		case 'T':
			usedelay = true;
			break;
		case 'h':
		case 'u':
			usage(argv[0]);
			exit(1);
		}
	}

	if (_usemsec) {
		unsigned int x = sinterval;
		sinterval = x / 1000;
		ninterval = (x % 1000) * 1000 * 1000;
	}

	if (!sinterval && !ninterval) {
		sinterval = 1;
		ninterval = 0;
	}

	if (_layout.empty()) {
		_layout = std::string(argc - optind, '1');
		if (_layout.empty())
			_layout = "1";
	}
	for (size_t i = 0; i < _layout.size(); i++) {
		int x = toupper(_layout[i]);
		if (x >= '1' && x <= '9')
			layout.push_back(x - '0');
		else if (x >= 'A' && x <= 'F')
			layout.push_back(x - 'A' + 10);
		else
			layout.push_back(-1);
	}

	init_lock();
	init_log(argv[0]);
	init_watch(true);

	int ret = init_screen(fgcolor, bgcolor);
	if (ret) {
		log("failed to init screen %d", ret);
		exit(1);
	}

	if (atexit(atexit_handler)) {
		perror("atexit");
		exit(1);
	}

	struct sigaction sa;
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = sigint_handler;
	if (sigemptyset(&sa.sa_mask) == -1) {
		perror("sigemptyset");
		exit(1);
	}
	if (sigaction(SIGINT, &sa, NULL) == -1) {
		perror("sigaction");
		exit(1);
	}

	try {
		Container co(argc - optind, &argv[optind]);
		if (co.thread_create())
			exit(1);
		while (!interrupted)
			co.parse_event(read_incoming());
		co.thread_join();
	} catch (const std::exception &e) {
		_what = e.what();
		exit(1);
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x8227(%rip), %rsi      # 0xbc00
leaq 0xd0(%rsp), %r14
movl $0xa0, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x4672(%rip), %r15      # 0x8067
leaq 0x14(%rsp), %r12
movq 0x8597(%rip), %r13      # 0xbf98
movq %rbx, 0x8(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %r12, %r8
callq 0x3610
cmpl $0x4d, %eax
jle 0x3a7c
leal -0x63(%rax), %ecx
cmpl $0x12, %ecx
ja 0x3ab0
leaq 0x45d3(%rip), %rdx      # 0x8004
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl %ebp, %ebx
movq (%r13), %rbp
movq %r14, %r15
movq 0x89b6(%rip), %r14      # 0xc400
movq %rbp, %rdi
callq 0x3180
leaq 0x899f(%rip), %rdi      # 0xc3f8
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %r14
movq %rbp, %rcx
movl %ebx, %ebp
movq 0x8(%rsp), %rbx
leaq 0x45f5(%rip), %r15      # 0x8067
movq %rax, %r8
callq 0x35a0
jmp 0x3a06
cmpl $0x42, %eax
je 0x3a9b
cmpl $0x46, %eax
jne 0x3aca
movq (%r13), %rdi
callq 0x6a14
movw %ax, 0x88fc(%rip)       # 0xc392
jmp 0x3a06
movq (%r13), %rdi
callq 0x6a14
movw %ax, 0x88e9(%rip)       # 0xc394
jmp 0x3a06
cmpl $0x4e, %eax
je 0x3b1c
cmpl $0x54, %eax
jne 0x3a06
movb $0x1, 0x892e(%rip)      # 0xc3f3
jmp 0x3a06
cmpl $-0x1, %eax
jne 0x3a06
jmp 0x3b28
movb $0x1, 0x8916(%rip)      # 0xc3f2
jmp 0x3a06
movb $0x1, 0x8908(%rip)      # 0xc3f0
jmp 0x3a06
movb $0x1, 0x8924(%rip)      # 0xc418
jmp 0x3a06
movb $0x1, 0x88f1(%rip)      # 0xc3f1
jmp 0x3a06
movq (%r13), %rdi
callq 0x35c0
cltq
movq %rax, 0x88c9(%rip)      # 0xc3e0
jmp 0x3a06
movb $0x0, 0x886d(%rip)      # 0xc390
jmp 0x3a06
cmpb $0x1, 0x88e9(%rip)      # 0xc418
jne 0x3b5e
movl 0x88a9(%rip), %eax      # 0xc3e0
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
shrq $0x26, %rcx
movq %rcx, 0x8897(%rip)      # 0xc3e0
imull $0x3e8, %ecx, %ecx      # imm = 0x3E8
subl %ecx, %eax
imull $0xf4240, %eax, %eax    # imm = 0xF4240
movq %rax, 0x888a(%rip)      # 0xc3e8
movq %rbx, %r13
movq 0x8880(%rip), %rax      # 0xc3e8
orq 0x8871(%rip), %rax      # 0xc3e0
jne 0x3b87
movq $0x1, 0x8864(%rip) # 0xc3e0
movq $0x0, 0x8861(%rip) # 0xc3e8
cmpq $0x0, 0x8871(%rip)      # 0xc400
jne 0x3c07
movq 0x8430(%rip), %rax      # 0xbfc8
movslq (%rax), %rax
movslq %ebp, %rsi
subq %rax, %rsi
leaq 0x48(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movl $0x31, %edx
callq 0x3440
leaq 0x8835(%rip), %rdi      # 0xc3f8
movq %r14, %rsi
callq 0x34a0
movq (%r14), %rdi
cmpq %rbx, %rdi
je 0x3be0
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3380
movq 0x8819(%rip), %rdx      # 0xc400
testq %rdx, %rdx
jne 0x3c07
leaq 0x8805(%rip), %rdi      # 0xc3f8
leaq 0x4478(%rip), %rcx      # 0x8072
movl $0x1, %r8d
xorl %esi, %esi
callq 0x35a0
cmpq $0x0, 0x87f1(%rip)      # 0xc400
je 0x3ca9
xorl %ebx, %ebx
leaq 0x87aa(%rip), %r15      # 0xc3c8
leaq 0x38(%rsp), %r12
movq 0x87ce(%rip), %rax      # 0xc3f8
movsbl (%rax,%rbx), %edi
callq 0x36d0
leal -0x31(%rax), %ecx
cmpl $0x8, %ecx
ja 0x3c40
addl $-0x30, %eax
jmp 0x3c4b
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3c63
addl $-0x37, %eax
movl %eax, 0x38(%rsp)
movq 0x877a(%rip), %rsi      # 0xc3d0
cmpq 0x877b(%rip), %rsi      # 0xc3d8
je 0x3c8e
movl %eax, (%rsi)
jmp 0x3c81
movl $0xffffffff, 0x38(%rsp) # imm = 0xFFFFFFFF
movq 0x875e(%rip), %rsi      # 0xc3d0
cmpq 0x875f(%rip), %rsi      # 0xc3d8
je 0x3c8e
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x8744(%rip)      # 0xc3d0
jmp 0x3c99
movq %r15, %rdi
movq %r12, %rdx
callq 0x459c
incq %rbx
cmpq 0x875d(%rip), %rbx      # 0xc400
jb 0x3c23
callq 0x6960
movl $0x1, %edi
callq 0x6fcc
movswl 0x86d3(%rip), %edi      # 0xc392
movswl 0x86ce(%rip), %esi      # 0xc394
callq 0x6b2c
testl %eax, %eax
jne 0x3dff
leaq 0x82d(%rip), %rdi       # 0x4507
callq 0x73d0
testl %eax, %eax
jne 0x3db8
leaq 0x38(%rsp), %r14
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x3200
leaq 0x877(%rip), %rax       # 0x4579
movq %rax, (%r14)
leaq 0x40(%rsp), %rdi
callq 0x34b0
cmpl $-0x1, %eax
je 0x3dbd
leaq 0x38(%rsp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x34c0
cmpl $-0x1, %eax
je 0x3dc2
movq 0x828f(%rip), %rax      # 0xbfc8
movslq (%rax), %rax
subl %eax, %ebp
leaq (,%rax,8), %rdx
addq %r13, %rdx
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x46d8
leaq 0x18(%rsp), %rdi
callq 0x4e3a
testl %eax, %eax
jne 0x3dff
leaq 0x18(%rsp), %rbx
cmpl $0x0, 0x8651(%rip)      # 0xc3c4
jne 0x3d86
callq 0x6c72
movq %rbx, %rdi
movl %eax, %esi
callq 0x4cd2
jmp 0x3d6c
leaq 0x18(%rsp), %rdi
callq 0x4f86
leaq 0x18(%rsp), %rdi
callq 0x4878
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
callq 0x3e0e
jmp 0x3dff
callq 0x3710
callq 0x373a
callq 0x3725
movq %rdx, %r14
movq %rax, %rbx
jmp 0x3de1
jmp 0x3dd1
movq %rdx, %r14
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4878
movq %rbx, %rdi
cmpl $0x1, %r14d
jne 0x3e09
callq 0x3160
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq %rax, 0x8621(%rip)      # 0xc420
movl $0x1, %edi
callq 0x3480
callq 0x3680