// File: 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
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0xc0(%rbp), %rdi
leaq 0x12109(%rip), %rsi     # 0x16c00
movl $0xa0, %edx
callq 0x4370
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0xc0(%rbp), %rcx
leaq 0xa5d5(%rip), %rdx      # 0xf0eb
leaq -0x14(%rbp), %r8
callq 0x4740
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
je 0x4c10
movl -0x18(%rbp), %eax
addl $-0x42, %eax
movl %eax, %ecx
movq %rcx, -0x1e8(%rbp)
subl $0x33, %eax
ja 0x4c0b
movq -0x1e8(%rbp), %rax
leaq 0xa4b3(%rip), %rcx      # 0xf004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x1242f(%rip), %rax     # 0x16f90
movq (%rax), %rsi
leaq 0x12945(%rip), %rdi     # 0x174b0
callq 0x45f0
jmp 0x4c0b
movq 0x12414(%rip), %rax     # 0x16f90
movq (%rax), %rdi
callq 0x46e0
cltq
movq %rax, 0x1290b(%rip)     # 0x17498
jmp 0x4c0b
movq 0x123fa(%rip), %rax     # 0x16f90
movq (%rax), %rdi
callq 0xca30
movw %ax, 0x128a5(%rip)      # 0x1744a
jmp 0x4c0b
movq 0x123e2(%rip), %rax     # 0x16f90
movq (%rax), %rdi
callq 0xca30
movw %ax, 0x1288f(%rip)      # 0x1744c
jmp 0x4c0b
movb $0x1, 0x1290a(%rip)     # 0x174d0
jmp 0x4c0b
movb $0x1, 0x128d9(%rip)     # 0x174a8
jmp 0x4c0b
movb $0x1, 0x128d1(%rip)     # 0x174a9
jmp 0x4c0b
movb $0x0, 0x12867(%rip)     # 0x17448
jmp 0x4c0b
movb $0x1, 0x128c0(%rip)     # 0x174aa
jmp 0x4c0b
movb $0x1, 0x128b8(%rip)     # 0x174ab
jmp 0x4c0b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5080
movl $0x1, %edi
callq 0x4560
jmp 0x4b01
testb $0x1, 0x128b9(%rip)     # 0x174d0
je 0x4c62
movq 0x12878(%rip), %rax     # 0x17498
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, %eax
movq %rax, 0x1285a(%rip)     # 0x17498
movl -0xc4(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movl %eax, %eax
movq %rax, 0x1283e(%rip)     # 0x174a0
cmpq $0x0, 0x1282e(%rip)     # 0x17498
jne 0x4c8c
cmpq $0x0, 0x1282c(%rip)     # 0x174a0
jne 0x4c8c
movq $0x1, 0x12817(%rip) # 0x17498
movq $0x0, 0x12814(%rip) # 0x174a0
leaq 0x1281d(%rip), %rdi     # 0x174b0
callq 0x4750
testb $0x1, %al
jne 0x4ca1
jmp 0x4d63
movl -0x8(%rbp), %eax
movq 0x12325(%rip), %rcx     # 0x16fd0
movl (%rcx), %ecx
subl %ecx, %eax
cltq
movq %rax, -0x1f8(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x47c0
movq -0x1f8(%rbp), %rsi
movq -0x1f0(%rbp), %rcx
leaq -0xe8(%rbp), %rdi
movl $0x31, %edx
callq 0x54f0
jmp 0x4cec
leaq 0x127bd(%rip), %rdi     # 0x174b0
leaq -0xe8(%rbp), %rsi
callq 0x4580
leaq -0xe8(%rbp), %rdi
callq 0x4878
leaq -0xe9(%rbp), %rdi
callq 0x4490
leaq 0x12792(%rip), %rdi     # 0x174b0
callq 0x4750
testb $0x1, %al
jne 0x4d29
jmp 0x4d61
leaq 0x12780(%rip), %rdi     # 0x174b0
leaq 0xa3bf(%rip), %rsi      # 0xf0f6
callq 0x45f0
jmp 0x4d61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0xe9(%rbp), %rdi
callq 0x4490
jmp 0x506c
jmp 0x4d63
movq $0x0, -0x108(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq 0x1272d(%rip), %rdi     # 0x174b0
callq 0x42e0
movq %rax, %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
jae 0x4e63
movq -0x108(%rbp), %rsi
leaq 0x12707(%rip), %rdi     # 0x174b0
callq 0x4860
movsbl (%rax), %edi
callq 0x4810
movl %eax, -0x10c(%rbp)
cmpl $0x31, -0x10c(%rbp)
jl 0x4df2
cmpl $0x39, -0x10c(%rbp)
jg 0x4df2
movl -0x10c(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x110(%rbp)
leaq 0x1269c(%rip), %rdi     # 0x17480
leaq -0x110(%rbp), %rsi
callq 0x5560
jmp 0x4e4a
cmpl $0x41, -0x10c(%rbp)
jl 0x4e2b
cmpl $0x46, -0x10c(%rbp)
jg 0x4e2b
movl -0x10c(%rbp), %eax
subl $0x41, %eax
addl $0xa, %eax
movl %eax, -0x114(%rbp)
leaq 0x12663(%rip), %rdi     # 0x17480
leaq -0x114(%rbp), %rsi
callq 0x5560
jmp 0x4e48
movl $0xffffffff, -0x118(%rbp) # imm = 0xFFFFFFFF
leaq 0x12644(%rip), %rdi     # 0x17480
leaq -0x118(%rbp), %rsi
callq 0x5560
jmp 0x4e4a
jmp 0x4e4c
movq -0x108(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x108(%rbp)
jmp 0x4d6e
callq 0xc930
movl $0x1, %edi
callq 0xd2d0
movw 0x125d1(%rip), %ax      # 0x1744a
movswl %ax, %edi
movswl 0x125c9(%rip), %esi     # 0x1744c
callq 0xcc50
movl %eax, -0x11c(%rbp)
cmpl $0x0, -0x11c(%rbp)
je 0x4ea1
movl $0x1, %edi
callq 0x4560
leaq 0x558(%rip), %rdi       # 0x5400
callq 0xe8c0
cmpl $0x0, %eax
je 0x4ec8
leaq 0xa23f(%rip), %rdi      # 0xf0f8
callq 0x4380
movl $0x1, %edi
callq 0x4560
leaq -0x1b8(%rbp), %rdi
xorl %esi, %esi
movl $0x98, %edx
callq 0x4250
leaq 0x56e(%rip), %rax       # 0x5450
movq %rax, -0x1b8(%rbp)
leaq -0x1b8(%rbp), %rdi
addq $0x8, %rdi
callq 0x45a0
cmpl $-0x1, %eax
jne 0x4f14
leaq 0xa1fa(%rip), %rdi      # 0xf0ff
callq 0x4380
movl $0x1, %edi
callq 0x4560
movl $0x2, %edi
leaq -0x1b8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x45b0
cmpl $-0x1, %eax
jne 0x4f44
leaq 0xa1d6(%rip), %rdi      # 0xf10b
callq 0x4380
movl $0x1, %edi
callq 0x4560
movl -0x8(%rbp), %esi
movq 0x12082(%rip), %rax     # 0x16fd0
movslq (%rax), %rcx
movl %ecx, %eax
subl %eax, %esi
movq -0x10(%rbp), %rax
leaq (%rax,%rcx,8), %rdx
leaq -0x1d8(%rbp), %rdi
callq 0x6080
jmp 0x4f6b
leaq -0x1d8(%rbp), %rdi
callq 0x6bd0
movl %eax, -0x204(%rbp)
jmp 0x4f7f
movl -0x204(%rbp), %eax
cmpl $0x0, %eax
je 0x500e
movl $0x1, %edi
callq 0x4560
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x4fca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x6350
movl -0xfc(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x506c
movq -0xf8(%rbp), %rdi
callq 0x4170
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, 0x124d4(%rip)     # 0x174d8
movl $0x1, %edi
callq 0x4560
jmp 0x5010
movl 0x12466(%rip), %eax     # 0x1747c
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x5024
jmp 0x5047
callq 0xce10
movl %eax, -0x208(%rbp)
jmp 0x5031
movl -0x208(%rbp), %esi
leaq -0x1d8(%rbp), %rdi
callq 0x69b0
jmp 0x5045
jmp 0x5010
leaq -0x1d8(%rbp), %rdi
callq 0x6dc0
jmp 0x5055
leaq -0x1d8(%rbp), %rdi
callq 0x6350
xorl %eax, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0xf8(%rbp), %rdi
callq 0x47b0
nopl (%rax,%rax)