// File: /workspace/github_cpp_makefile_star2_O2/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 $0x168, %rsp            # imm = 0x168
movq %rsi, %r14
movl %edi, %ebx
leaq 0x7297(%rip), %rsi      # 0xbc10
leaq 0xc0(%rsp), %r15
movl $0xa0, %edx
movq %r15, %rdi
callq 0x4310
leaq 0x36d2(%rip), %r12      # 0x8067
leaq 0x4(%rsp), %r13
leaq 0x3663(%rip), %rbp      # 0x8004
movl %ebx, %edi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r8
callq 0x4640
leal -0x63(%rax), %ecx
cmpl $0x12, %ecx
ja 0x49de
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
movq 0x75d3(%rip), %rax      # 0xbfa0
movq (%rax), %rsi
leaq 0x7a39(%rip), %rdi      # 0xc410
callq 0x46f0
jmp 0x49a1
cmpl $0x42, %eax
je 0x4a77
cmpl $0x46, %eax
je 0x4a50
cmpl $0x4e, %eax
je 0x4a44
cmpl $0x54, %eax
je 0x4a6b
cmpl $-0x1, %eax
jne 0x49a1
jmp 0x4a92
movb $0x1, 0x7a03(%rip)      # 0xc40a
jmp 0x49a1
movb $0x1, 0x79f8(%rip)      # 0xc408
jmp 0x49a1
movb $0x1, 0x79f0(%rip)      # 0xc409
jmp 0x49a1
movb $0x1, 0x7a0e(%rip)      # 0xc430
jmp 0x49a1
movq 0x7572(%rip), %rax      # 0xbfa0
movq (%rax), %rdi
callq 0x45f0
cltq
movq %rax, 0x79b9(%rip)      # 0xc3f8
jmp 0x49a1
movb $0x0, 0x795d(%rip)      # 0xc3a8
jmp 0x49a1
movq 0x7549(%rip), %rax      # 0xbfa0
movq (%rax), %rdi
callq 0x71bc
movw %ax, 0x7944(%rip)       # 0xc3aa
jmp 0x49a1
movb $0x1, 0x7999(%rip)      # 0xc40b
jmp 0x49a1
movq 0x7522(%rip), %rax      # 0xbfa0
movq (%rax), %rdi
callq 0x71bc
movw %ax, 0x791f(%rip)       # 0xc3ac
jmp 0x49a1
movq 0x795f(%rip), %rax      # 0xc3f8
cmpb $0x0, 0x7990(%rip)      # 0xc430
je 0x4ac1
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movq %rax, 0x7946(%rip)      # 0xc3f8
imull $0xf4240, %edx, %ecx    # imm = 0xF4240
movq %rcx, 0x7941(%rip)      # 0xc400
jmp 0x4ac8
movq 0x7938(%rip), %rcx      # 0xc400
orq %rax, %rcx
jne 0x4ae0
movq $0x1, 0x7920(%rip) # 0xc3f8
andq $0x0, 0x7920(%rip)      # 0xc400
cmpq $0x0, 0x7930(%rip)      # 0xc418
jne 0x4b47
movq 0x74df(%rip), %rax      # 0xbfd0
movslq (%rax), %rax
movslq %ebx, %rsi
subq %rax, %rsi
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x28(%rsp), %r15
pushq $0x31
popq %rdx
movq %r15, %rdi
callq 0x4440
leaq 0x78f6(%rip), %rdi      # 0xc410
movq %r15, %rsi
callq 0x44b0
movq %r15, %rdi
callq 0x4738
cmpq $0x0, 0x78e6(%rip)      # 0xc418
jne 0x4b47
leaq 0x78d5(%rip), %rdi      # 0xc410
leaq 0x3530(%rip), %rsi      # 0x8072
callq 0x46f0
xorl %r13d, %r13d
leaq 0x788f(%rip), %r15      # 0xc3e0
leaq 0x28(%rsp), %r12
cmpq 0x78bb(%rip), %r13      # 0xc418
jae 0x4ba3
movq 0x78aa(%rip), %rax      # 0xc410
movsbl (%rax,%r13), %edi
callq 0x46e0
leal -0x31(%rax), %ecx
cmpl $0x8, %ecx
ja 0x4b7d
addl $-0x30, %eax
jmp 0x4b88
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x4b8e
addl $-0x37, %eax
movl %eax, 0x28(%rsp)
jmp 0x4b93
orl $-0x1, 0x28(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x5042
incq %r13
jmp 0x4b56
callq 0x7118
pushq $0x1
popq %rdi
callq 0x774c
movswl 0x77f3(%rip), %edi      # 0xc3aa
movswl 0x77ee(%rip), %esi      # 0xc3ac
callq 0x72b5
testl %eax, %eax
jne 0x4cfe
leaq 0x3ed(%rip), %rdi       # 0x4fbf
callq 0x7bc0
testl %eax, %eax
jne 0x4ca6
leaq 0x30(%rsp), %r15
movl $0x90, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4230
leaq 0x3f8(%rip), %rax       # 0x4ff2
movq %rax, -0x8(%r15)
movq %r15, %rdi
callq 0x44c0
cmpl $-0x1, %eax
je 0x4caf
pushq $0x2
popq %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x44d0
cmpl $-0x1, %eax
je 0x4cb8
movq 0x73a2(%rip), %rax      # 0xbfd0
movslq (%rax), %rax
subl %eax, %ebx
leaq (%r14,%rax,8), %rdx
leaq 0x8(%rsp), %rdi
movl %ebx, %esi
callq 0x51b8
leaq 0x8(%rsp), %rdi
callq 0x584e
testl %eax, %eax
jne 0x4cfe
leaq 0x8(%rsp), %rbx
cmpl $0x0, 0x777b(%rip)      # 0xc3dc
jne 0x4c74
callq 0x73e7
movq %rbx, %rdi
movl %eax, %esi
callq 0x5732
jmp 0x4c5a
leaq 0x8(%rsp), %rdi
callq 0x597a
leaq 0x8(%rsp), %rdi
callq 0x5308
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
callq 0x4d0b
jmp 0x4cfe
leaq 0x33c7(%rip), %rdi      # 0x8074
jmp 0x4cbf
leaq 0x33c5(%rip), %rdi      # 0x807b
jmp 0x4cbf
leaq 0x33c8(%rip), %rdi      # 0x8087
callq 0x4320
jmp 0x4cfe
movq %rdx, %r14
movq %rax, %rbx
jmp 0x4ce0
jmp 0x4cd0
movq %rdx, %r14
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5308
movq %rbx, %rdi
cmpl $0x1, %r14d
jne 0x4d06
callq 0x4160
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq %rax, 0x773a(%rip)      # 0xc438
pushq $0x1
popq %rdi
callq 0x4490
callq 0x46a0