// File: /workspace/github_cpp_makefile_star2_O2/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb_stat.c
// Function: main
int main(int argc, char *argv[])
{
	int i, rc;
	MDB_env *env;
	MDB_txn *txn;
	MDB_dbi dbi;
	MDB_stat mst;
	MDB_envinfo mei;
	char *prog = argv[0];
	char *envname;
	char *subname = NULL;
	int alldbs = 0, envinfo = 0, envflags = 0, freinfo = 0, rdrinfo = 0;

	if (argc < 2) {
		usage(prog);
	}

	/* -a: print stat of main DB and all subDBs
	 * -s: print stat of only the named subDB
	 * -e: print env info
	 * -f: print freelist info
	 * -r: print reader info
	 * -n: use NOSUBDIR flag on env_open
	 * -V: print version and exit
	 * (default) print stat of only the main DB
	 */
	while ((i = getopt(argc, argv, "Vaefnrs:")) != EOF) {
		switch(i) {
		case 'V':
			printf("%s\n", MDB_VERSION_STRING);
			exit(0);
			break;
		case 'a':
			if (subname)
				usage(prog);
			alldbs++;
			break;
		case 'e':
			envinfo++;
			break;
		case 'f':
			freinfo++;
			break;
		case 'n':
			envflags |= MDB_NOSUBDIR;
			break;
		case 'r':
			rdrinfo++;
			break;
		case 's':
			if (alldbs)
				usage(prog);
			subname = optarg;
			break;
		default:
			usage(prog);
		}
	}

	if (optind != argc - 1)
		usage(prog);

	envname = argv[optind];
	rc = mdb_env_create(&env);
	if (rc) {
		fprintf(stderr, "mdb_env_create failed, error %d %s\n", rc, mdb_strerror(rc));
		return EXIT_FAILURE;
	}

	if (alldbs || subname) {
		mdb_env_set_maxdbs(env, 4);
	}

	rc = mdb_env_open(env, envname, envflags | MDB_RDONLY, 0664);
	if (rc) {
		fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
		goto env_close;
	}

	if (envinfo) {
		(void)mdb_env_stat(env, &mst);
		(void)mdb_env_info(env, &mei);
		printf("Environment Info\n");
		printf("  Map address: %p\n", mei.me_mapaddr);
		printf("  Map size: %"Z"u\n", mei.me_mapsize);
		printf("  Page size: %u\n", mst.ms_psize);
		printf("  Max pages: %"Z"u\n", mei.me_mapsize / mst.ms_psize);
		printf("  Number of pages used: %"Z"u\n", mei.me_last_pgno+1);
		printf("  Last transaction ID: %"Z"u\n", mei.me_last_txnid);
		printf("  Max readers: %u\n", mei.me_maxreaders);
		printf("  Number of readers used: %u\n", mei.me_numreaders);
	}

	if (rdrinfo) {
		printf("Reader Table Status\n");
		rc = mdb_reader_list(env, (MDB_msg_func *)fputs, stdout);
		if (rdrinfo > 1) {
			int dead;
			mdb_reader_check(env, &dead);
			printf("  %d stale readers cleared.\n", dead);
			rc = mdb_reader_list(env, (MDB_msg_func *)fputs, stdout);
		}
		if (!(subname || alldbs || freinfo))
			goto env_close;
	}

	rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
	if (rc) {
		fprintf(stderr, "mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc));
		goto env_close;
	}

	if (freinfo) {
		MDB_cursor *cursor;
		MDB_val key, data;
		size_t pages = 0, *iptr;

		printf("Freelist Status\n");
		dbi = 0;
		rc = mdb_cursor_open(txn, dbi, &cursor);
		if (rc) {
			fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc));
			goto txn_abort;
		}
		rc = mdb_stat(txn, dbi, &mst);
		if (rc) {
			fprintf(stderr, "mdb_stat failed, error %d %s\n", rc, mdb_strerror(rc));
			goto txn_abort;
		}
		prstat(&mst);
		while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
			iptr = data.mv_data;
			pages += *iptr;
			if (freinfo > 1) {
				char *bad = "";
				size_t pg, prev;
				ssize_t i, j, span = 0;
				j = *iptr++;
				for (i = j, prev = 1; --i >= 0; ) {
					pg = iptr[i];
					if (pg <= prev)
						bad = " [bad sequence]";
					prev = pg;
					pg += span;
					for (; i >= span && iptr[i-span] == pg; span++, pg++) ;
				}
				printf("    Transaction %"Z"u, %"Z"d pages, maxspan %"Z"d%s\n",
					*(size_t *)key.mv_data, j, span, bad);
				if (freinfo > 2) {
					for (--j; j >= 0; ) {
						pg = iptr[j];
						for (span=1; --j >= 0 && iptr[j] == pg+span; span++) ;
						printf(span>1 ? "     %9"Z"u[%"Z"d]\n" : "     %9"Z"u\n",
							pg, span);
					}
				}
			}
		}
		mdb_cursor_close(cursor);
		printf("  Free pages: %"Z"u\n", pages);
	}

	rc = mdb_open(txn, subname, 0, &dbi);
	if (rc) {
		fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
		goto txn_abort;
	}

	rc = mdb_stat(txn, dbi, &mst);
	if (rc) {
		fprintf(stderr, "mdb_stat failed, error %d %s\n", rc, mdb_strerror(rc));
		goto txn_abort;
	}
	printf("Status of %s\n", subname ? subname : "Main DB");
	prstat(&mst);

	if (alldbs) {
		MDB_cursor *cursor;
		MDB_val key;

		rc = mdb_cursor_open(txn, dbi, &cursor);
		if (rc) {
			fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc));
			goto txn_abort;
		}
		while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
			char *str;
			MDB_dbi db2;
			if (memchr(key.mv_data, '\0', key.mv_size))
				continue;
			str = malloc(key.mv_size+1);
			memcpy(str, key.mv_data, key.mv_size);
			str[key.mv_size] = '\0';
			rc = mdb_open(txn, str, 0, &db2);
			if (rc == MDB_SUCCESS)
				printf("Status of %s\n", str);
			free(str);
			if (rc) continue;
			rc = mdb_stat(txn, db2, &mst);
			if (rc) {
				fprintf(stderr, "mdb_stat failed, error %d %s\n", rc, mdb_strerror(rc));
				goto txn_abort;
			}
			prstat(&mst);
			mdb_close(env, db2);
		}
		mdb_cursor_close(cursor);
	}

	if (rc == MDB_NOTFOUND)
		rc = MDB_SUCCESS;

	mdb_close(env, dbi);
txn_abort:
	mdb_txn_abort(txn);
env_close:
	mdb_env_close(env);

	return rc ? EXIT_FAILURE : EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %edi, %r12d
movq (%rsi), %rdi
cmpl $0x2, %r12d
jl 0x2c89
movq %rsi, %r15
movq %rdi, 0x40(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0xba8f(%rip), %rbx      # 0xe004
movq 0x10a5c(%rip), %r14     # 0x12fd8
movq $0x0, 0x28(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x8(%rsp)
xorl %r13d, %r13d
movl 0x20(%rsp), %ebp
orl $0x4000, %ebp           # imm = 0x4000
movl %r12d, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2340
cmpl $0x72, %eax
jne 0x25c2
incl %r13d
jmp 0x25aa
cmpl $-0x1, %eax
je 0x263a
cmpl $0x61, %eax
je 0x2614
cmpl $0x65, %eax
je 0x260e
cmpl $0x66, %eax
je 0x25e1
cmpl $0x6e, %eax
jne 0x25e7
movl %ebp, 0x20(%rsp)
jmp 0x25aa
incl 0x8(%rsp)
jmp 0x25aa
cmpl $0x73, %eax
jne 0x2c6c
cmpl $0x0, 0x18(%rsp)
jne 0x2c84
movq (%r14), %rax
movq %rax, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x25a0
incl 0x3c(%rsp)
jmp 0x25a0
cmpq $0x0, 0x28(%rsp)
jne 0x2c84
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
jmp 0x25a0
movq 0x10987(%rip), %rax     # 0x12fc8
movslq (%rax), %rax
decl %r12d
cmpl %r12d, %eax
jne 0x2c84
movq (%r15,%rax,8), %rbx
movq %rsp, %rdi
callq 0xb6cf
testl %eax, %eax
movq 0x28(%rsp), %r12
jne 0x2b61
movq 0x18(%rsp), %r15
testl %r15d, %r15d
setne %al
testq %r12, %r12
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x268d
movq (%rsp), %rdi
pushq $0x4
popq %rsi
callq 0xb87f
movq (%rsp), %rdi
movl 0x20(%rsp), %edx
orl $0x20000, %edx          # imm = 0x20000
movq %rbx, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xb8c3
testl %eax, %eax
jne 0x2b95
cmpl $0x0, 0x3c(%rsp)
je 0x2786
movq (%rsp), %rdi
leaq 0x68(%rsp), %r14
movq %r14, %rsi
callq 0xca58
movq (%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0xcabe
leaq 0xbc03(%rip), %rdi      # 0xe2ea
callq 0x20a0
movq (%rbx), %rsi
leaq 0xb97c(%rip), %rdi      # 0xe072
xorl %eax, %eax
callq 0x2130
movq 0x8(%rbx), %rsi
leaq 0xb97d(%rip), %rdi      # 0xe085
xorl %eax, %eax
callq 0x2130
movl (%r14), %esi
leaq 0xb97d(%rip), %rdi      # 0xe096
xorl %eax, %eax
callq 0x2130
movq 0x8(%rbx), %rax
movl (%r14), %ecx
xorl %edx, %edx
divq %rcx
leaq 0xb974(%rip), %rdi      # 0xe0a7
movq %rax, %rsi
xorl %eax, %eax
callq 0x2130
movq 0x10(%rbx), %rsi
incq %rsi
leaq 0xb96e(%rip), %rdi      # 0xe0b9
xorl %eax, %eax
callq 0x2130
movq 0x18(%rbx), %rsi
leaq 0xb979(%rip), %rdi      # 0xe0d6
xorl %eax, %eax
callq 0x2130
movl 0x20(%rbx), %esi
leaq 0xb984(%rip), %rdi      # 0xe0f2
xorl %eax, %eax
callq 0x2130
movl 0x24(%rbx), %esi
leaq 0xb986(%rip), %rdi      # 0xe105
xorl %eax, %eax
callq 0x2130
testl %r13d, %r13d
je 0x2811
leaq 0xbb65(%rip), %rdi      # 0xe2fb
callq 0x20a0
movq (%rsp), %rdi
movq 0x1081a(%rip), %r14     # 0x12fc0
movq (%r14), %rdx
movq 0x10820(%rip), %rsi     # 0x12fd0
callq 0xcbbf
cmpl $0x2, %r13d
jl 0x27ef
movq (%rsp), %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0xccc2
movl (%rbx), %esi
leaq 0xb94e(%rip), %rdi      # 0xe123
xorl %eax, %eax
callq 0x2130
movq (%rsp), %rdi
movq (%r14), %rdx
movq 0x107e6(%rip), %rsi     # 0x12fd0
callq 0xcbbf
movl %eax, %ebp
testq %r12, %r12
setne %al
testl %r15d, %r15d
setne %cl
orb %al, %cl
cmpl $0x0, 0x8(%rsp)
setne %al
orb %cl, %al
cmpb $0x1, %al
jne 0x2c4a
movq (%rsp), %rdi
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x31a7
testl %eax, %eax
jne 0x2be9
cmpl $0x0, 0x8(%rsp)
je 0x29dc
leaq 0xbacf(%rip), %rdi      # 0xe30f
callq 0x20a0
andl $0x0, 0xc(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
xorl %esi, %esi
callq 0x8b5c
testl %eax, %eax
jne 0x2bcd
movq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rdx
xorl %esi, %esi
callq 0xcb31
testl %eax, %eax
jne 0x2bb1
leaq 0x68(%rsp), %rdi
callq 0x2cb2
pushq $0x1
popq %r13
leaq 0xb915(%rip), %r15      # 0xe1a6
leaq 0xb94d(%rip), %rbp      # 0xe1e5
leaq 0xb956(%rip), %r14      # 0xe1f5
movq $0x0, 0x20(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x58(%rsp), %rdx
pushq $0x8
popq %rcx
callq 0x5b27
testl %eax, %eax
jne 0x29b5
movq 0x60(%rsp), %r12
movq (%r12), %rbx
addq %rbx, 0x20(%rsp)
cmpl $0x2, 0x8(%rsp)
jl 0x28a8
leaq (%r12,%rbx,8), %rax
leaq 0xbb7c(%rip), %r8       # 0xe463
movq %r13, %r9
movq %rbx, %rdx
xorl %ecx, %ecx
testq %rdx, %rdx
jle 0x2941
movq (%r12,%rdx,8), %rsi
cmpq %r9, %rsi
cmovbeq %r15, %r8
cmpq %rdx, %rcx
movq %rdx, %r9
cmovgq %rcx, %r9
leaq -0x1(%rdx), %rdi
leaq (,%rcx,8), %r11
movq %rax, %r10
subq %r11, %r10
cmpq %rcx, %rdx
jle 0x2932
leaq (%rsi,%rcx), %r11
cmpq (%r10), %r11
jne 0x2935
incq %rcx
addq $-0x8, %r10
jmp 0x291b
movq %r9, %rcx
addq $-0x8, %rax
movq %rsi, %r9
movq %rdi, %rdx
jmp 0x28ef
movq 0x50(%rsp), %rax
movq (%rax), %rsi
leaq 0xb866(%rip), %rdi      # 0xe1b6
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2130
cmpl $0x2, 0x8(%rsp)
je 0x28a8
decq %rbx
testq %rbx, %rbx
js 0x28a8
movq 0x8(%r12,%rbx,8), %rsi
leaq 0x1(%rbx), %rdx
decq %rbx
movq %r13, %rax
cmpq $-0x1, %rbx
je 0x2999
leaq (%rsi,%rax), %rcx
cmpq 0x8(%r12,%rbx,8), %rcx
jne 0x299e
incq %rax
decq %rbx
jmp 0x2980
pushq $-0x1
popq %rbx
jmp 0x29a1
movq %rax, %rdx
cmpq $0x2, %rdx
movq %r14, %rdi
cmovaeq %rbp, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x2968
movq 0x30(%rsp), %rdi
callq 0x8d06
leaq 0xb83a(%rip), %rdi      # 0xe200
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x2130
movq 0x18(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rcx
movq %r12, %rsi
xorl %edx, %edx
callq 0x8f17
testl %eax, %eax
jne 0x2c17
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
leaq 0x68(%rsp), %rdx
callq 0xcb31
testl %eax, %eax
jne 0x2bb1
testq %r12, %r12
leaq 0xb822(%rip), %rsi      # 0xe23f
cmovneq %r12, %rsi
leaq 0xb809(%rip), %rdi      # 0xe231
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2130
leaq 0x68(%rsp), %rdi
callq 0x2cb2
testl %r15d, %r15d
je 0x2b4f
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
leaq 0x58(%rsp), %rdx
callq 0x8b5c
testl %eax, %eax
jne 0x2bcd
leaq 0x48(%rsp), %rbx
pushq $0xb
popq %r14
leaq 0x30(%rsp), %r15
movq 0x58(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl %r14d, %ecx
callq 0x5b27
testl %eax, %eax
jne 0x2b35
movq 0x48(%rsp), %r12
movq 0x50(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x21c0
testq %rax, %rax
jne 0x2a6d
leaq 0x1(%r12), %rdi
callq 0x2270
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2240
movb $0x0, (%rbp,%r12)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x8f17
testl %eax, %eax
je 0x2ae4
movq %rbp, %rdi
callq 0x2030
jmp 0x2a6d
leaq 0xb746(%rip), %rdi      # 0xe231
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2130
movq %rbp, %rdi
callq 0x2030
movq 0x10(%rsp), %rdi
movl 0x30(%rsp), %esi
leaq 0x68(%rsp), %r12
movq %r12, %rdx
callq 0xcb31
testl %eax, %eax
jne 0x2bb1
movq %r12, %rdi
callq 0x2cb2
movq (%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x926e
jmp 0x2a6d
movl %eax, %r12d
movq 0x58(%rsp), %rdi
callq 0x8d06
xorl %ebp, %ebp
cmpl $0xffff87b2, %r12d      # imm = 0xFFFF87B2
cmovnel %r12d, %ebp
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x926e
jmp 0x2c40
movl %eax, %r14d
movq 0x1048d(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %r14d, %edi
callq 0x2d10
leaq 0xb4af(%rip), %rsi      # 0xe02c
movq %rbx, %rdi
movl %r14d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2220
pushq $0x1
popq %rax
jmp 0x2c5a
movl %eax, %ebx
movq 0x1045a(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2d10
leaq 0xb4a1(%rip), %rsi      # 0xe050
jmp 0x2c03
movl %eax, %ebp
movq 0x1043e(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2d10
leaq 0xb5bd(%rip), %rsi      # 0xe188
jmp 0x2c31
movl %eax, %ebp
movq 0x10422(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2d10
leaq 0xb57c(%rip), %rsi      # 0xe163
jmp 0x2c31
movl %eax, %ebx
movq 0x10406(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2d10
leaq 0xb53d(%rip), %rsi      # 0xe140
movq %r14, %rdi
movl %ebx, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2220
pushq $0x1
popq %rbp
jmp 0x2c4a
movl %eax, %ebp
movq 0x103d8(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2d10
leaq 0xb5e2(%rip), %rsi      # 0xe213
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2220
movq 0x10(%rsp), %rdi
callq 0x379c
movq (%rsp), %rdi
callq 0xc3a5
xorl %eax, %eax
testl %ebp, %ebp
setne %al
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x56, %eax
jne 0x2c84
leaq 0xb395(%rip), %rdi      # 0xe00d
callq 0x20a0
xorl %edi, %edi
callq 0x2390
movq 0x40(%rsp), %rdi
callq 0x2c8e