// File: /workspace/github_cpp_makefile_star2_O3/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 0x6a00
movw %ax, 0x88fc(%rip)       # 0xc392
jmp 0x3a06
movq (%r13), %rdi
callq 0x6a00
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
movq 0x88b1(%rip), %rax      # 0xc3e0
cmpb $0x0, 0x88e2(%rip)      # 0xc418
je 0x3b66
movl %eax, %ecx
imulq $0x10624dd3, %rcx, %rdx # imm = 0x10624DD3
shrq $0x26, %rdx
movq %rdx, 0x8894(%rip)      # 0xc3e0
imull $0x3e8, %edx, %ecx      # imm = 0x3E8
subl %ecx, %eax
imull $0xf4240, %eax, %ecx    # imm = 0xF4240
movq %rcx, 0x8887(%rip)      # 0xc3e8
movq %rdx, %rax
jmp 0x3b6d
movq 0x887b(%rip), %rcx      # 0xc3e8
movq %rbx, %r13
orq %rax, %rcx
jne 0x3b8b
movq $0x1, 0x8860(%rip) # 0xc3e0
movq $0x0, 0x885d(%rip) # 0xc3e8
cmpq $0x0, 0x886d(%rip)      # 0xc400
jne 0x3c1d
movq 0x8428(%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 0x882d(%rip), %rdi      # 0xc3f8
movq %r14, %rsi
callq 0x34a0
movq (%r14), %rdi
cmpq %rbx, %rdi
je 0x3be8
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3380
cmpq $0x0, 0x8810(%rip)      # 0xc400
jne 0x3c1d
leaq 0x87ff(%rip), %rdi      # 0xc3f8
leaq 0x4472(%rip), %rcx      # 0x8072
movl $0x1, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x35a0
cmpq $0x0, 0x87e9(%rip)      # 0xc400
je 0x3cb1
xorl %ebx, %ebx
leaq 0x87a2(%rip), %r15      # 0xc3c8
leaq 0x38(%rsp), %r12
movq 0x87c6(%rip), %rax      # 0xc3f8
movsbl (%rax,%rbx), %edi
callq 0x36d0
leal -0x31(%rax), %ecx
cmpl $0x8, %ecx
ja 0x3c48
addl $-0x30, %eax
jmp 0x3c53
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3c6b
addl $-0x37, %eax
movl %eax, 0x38(%rsp)
movq 0x8772(%rip), %rsi      # 0xc3d0
cmpq 0x8773(%rip), %rsi      # 0xc3d8
je 0x3c96
movl %eax, (%rsi)
jmp 0x3c89
movl $0xffffffff, 0x38(%rsp) # imm = 0xFFFFFFFF
movq 0x8756(%rip), %rsi      # 0xc3d0
cmpq 0x8757(%rip), %rsi      # 0xc3d8
je 0x3c96
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x873c(%rip)      # 0xc3d0
jmp 0x3ca1
movq %r15, %rdi
movq %r12, %rdx
callq 0x45a4
incq %rbx
cmpq 0x8755(%rip), %rbx      # 0xc400
jb 0x3c2b
callq 0x694c
movl $0x1, %edi
callq 0x6fb8
movswl 0x86cb(%rip), %edi      # 0xc392
movswl 0x86c6(%rip), %esi      # 0xc394
callq 0x6b18
testl %eax, %eax
jne 0x3e06
leaq 0x82c(%rip), %rdi       # 0x450e
callq 0x73b0
testl %eax, %eax
jne 0x3dbf
leaq 0x40(%rsp), %r14
movl $0x90, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x3200
leaq 0x876(%rip), %rax       # 0x4580
movq %rax, -0x8(%r14)
movq %r14, %rdi
callq 0x34b0
cmpl $-0x1, %eax
je 0x3dc4
leaq 0x38(%rsp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x34c0
cmpl $-0x1, %eax
je 0x3dc9
movq 0x8288(%rip), %rax      # 0xbfc8
movslq (%rax), %rax
subl %eax, %ebp
leaq (,%rax,8), %rdx
addq %r13, %rdx
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x46e0
leaq 0x18(%rsp), %rdi
callq 0x4e34
testl %eax, %eax
jne 0x3e06
leaq 0x18(%rsp), %rbx
cmpl $0x0, 0x864a(%rip)      # 0xc3c4
jne 0x3d8d
callq 0x6c5e
movq %rbx, %rdi
movl %eax, %esi
callq 0x4ccc
jmp 0x3d73
leaq 0x18(%rsp), %rdi
callq 0x4f80
leaq 0x18(%rsp), %rdi
callq 0x4880
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 0x3e15
jmp 0x3e06
callq 0x3710
callq 0x373a
callq 0x3725
movq %rdx, %r14
movq %rax, %rbx
jmp 0x3de8
jmp 0x3dd8
movq %rdx, %r14
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4880
movq %rbx, %rdi
cmpl $0x1, %r14d
jne 0x3e10
callq 0x3160
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq %rax, 0x861a(%rip)      # 0xc420
movl $0x1, %edi
callq 0x3480
callq 0x3680