// File: /workspace/github_cpp_makefile_star2_O3/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 0x2f26
movq %rsi, %r15
movq %rdi, 0x40(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0xc84f(%rip), %r13      # 0xf004
movq $0x0, 0x30(%rsp)
movl $0x0, 0x3c(%rsp)
xorl %r14d, %r14d
movl $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movl %r14d, %ebp
orl $0x4000, %ebp           # imm = 0x4000
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2330
cmpl $0x72, %eax
jne 0x27f3
incl %ebx
jmp 0x27dc
cmpl $0x65, %eax
jle 0x280d
cmpl $0x66, %eax
je 0x2807
cmpl $0x6e, %eax
jne 0x2826
movl %ebp, %r14d
jmp 0x27dc
incl 0x10(%rsp)
jmp 0x27dc
cmpl $0x60, %eax
jle 0x287d
cmpl $0x61, %eax
je 0x2857
cmpl $0x65, %eax
jne 0x2f1c
incl 0x3c(%rsp)
jmp 0x27d3
cmpl $0x73, %eax
jne 0x2f1c
cmpl $0x0, 0x20(%rsp)
jne 0x2f2b
movq 0x10797(%rip), %rax     # 0x12fd8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
jmp 0x27d3
cmpq $0x0, 0x30(%rsp)
jne 0x2f35
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
jmp 0x27d3
cmpl $-0x1, %eax
jne 0x2f04
movq 0x1073b(%rip), %rax     # 0x12fc8
movslq (%rax), %rax
decl %r12d
cmpl %r12d, %eax
movq 0x20(%rsp), %r12
movq 0x30(%rsp), %r13
jne 0x2f3f
movq (%r15,%rax,8), %r15
leaq 0x8(%rsp), %rdi
callq 0xc01a
testl %eax, %eax
jne 0x2e6b
testl %r12d, %r12d
setne %al
testq %r13, %r13
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x28de
movq 0x8(%rsp), %rdi
movl $0x4, %esi
callq 0xc1e3
movq 0x8(%rsp), %rdi
orl $0x20000, %r14d         # imm = 0x20000
movq %r15, %rsi
movl %r14d, %edx
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xc22c
testl %eax, %eax
jne 0x2e79
cmpl $0x0, 0x3c(%rsp)
je 0x29dc
movq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0xd468
movq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0xd4bc
leaq 0xc9af(%rip), %rdi      # 0xf2ea
callq 0x20a0
movq (%r14), %rsi
leaq 0xc728(%rip), %rdi      # 0xf072
xorl %eax, %eax
callq 0x2130
movq 0x8(%r14), %rsi
leaq 0xc729(%rip), %rdi      # 0xf085
xorl %eax, %eax
callq 0x2130
movl (%r15), %esi
leaq 0xc729(%rip), %rdi      # 0xf096
xorl %eax, %eax
callq 0x2130
movq 0x8(%r14), %rax
movl (%r15), %ecx
xorl %edx, %edx
divq %rcx
leaq 0xc720(%rip), %rdi      # 0xf0a7
movq %rax, %rsi
xorl %eax, %eax
callq 0x2130
movq 0x10(%r14), %rsi
incq %rsi
leaq 0xc71a(%rip), %rdi      # 0xf0b9
xorl %eax, %eax
callq 0x2130
movq 0x18(%r14), %rsi
leaq 0xc725(%rip), %rdi      # 0xf0d6
xorl %eax, %eax
callq 0x2130
movl 0x20(%r14), %esi
leaq 0xc72f(%rip), %rdi      # 0xf0f2
xorl %eax, %eax
callq 0x2130
movl 0x24(%r14), %esi
leaq 0xc730(%rip), %rdi      # 0xf105
xorl %eax, %eax
callq 0x2130
testl %ebx, %ebx
je 0x2a6a
leaq 0xc910(%rip), %rdi      # 0xf2fb
callq 0x20a0
movq 0x8(%rsp), %rdi
movq 0x105c4(%rip), %r15     # 0x12fc0
movq (%r15), %rdx
movq 0x105ca(%rip), %rsi     # 0x12fd0
callq 0xd5db
cmpl $0x2, %ebx
jl 0x2a47
movq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0xd718
movl (%r14), %esi
leaq 0xc6f7(%rip), %rdi      # 0xf123
xorl %eax, %eax
callq 0x2130
movq 0x8(%rsp), %rdi
movq (%r15), %rdx
movq 0x1058e(%rip), %rsi     # 0x12fd0
callq 0xd5db
movl %eax, %r14d
testq %r13, %r13
setne %al
testl %r12d, %r12d
setne %cl
orb %al, %cl
cmpl $0x0, 0x10(%rsp)
setne %al
orb %cl, %al
cmpb $0x1, %al
jne 0x2e47
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x345c
testl %eax, %eax
jne 0x2e82
cmpl $0x0, 0x10(%rsp)
je 0x2ca1
leaq 0xc875(%rip), %rdi      # 0xf30f
callq 0x20a0
movl $0x0, 0x14(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rdx
xorl %esi, %esi
callq 0x9263
testl %eax, %eax
jne 0x2ea9
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
xorl %esi, %esi
callq 0xd530
testl %eax, %eax
jne 0x2eb5
leaq 0x68(%rsp), %rdi
callq 0x2f49
movq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movl $0x8, %ecx
callq 0x5fd1
testl %eax, %eax
je 0x2b08
xorl %r14d, %r14d
jmp 0x2c7c
leaq 0xc697(%rip), %rbx      # 0xf1a6
xorl %r14d, %r14d
movl 0x10(%rsp), %r12d
movq 0x60(%rsp), %rbp
movq (%rbp), %r15
cmpl $0x2, %r12d
jl 0x2c58
testq %r15, %r15
jle 0x2b98
leaq (,%r15,8), %rax
addq %rbp, %rax
movl $0x1, %edx
xorl %ecx, %ecx
movq %r15, %rsi
leaq 0xc938(%rip), %r8       # 0xf483
movq %rdx, %rdi
movq (%rbp,%rsi,8), %rdx
cmpq %rdi, %rdx
cmovbeq %rbx, %r8
cmpq %rcx, %rsi
jle 0x2b85
leaq (,%rcx,8), %r9
movq %rax, %rdi
subq %r9, %rdi
leaq (%rdx,%rcx), %r9
cmpq (%rdi), %r9
jne 0x2b85
incq %rcx
addq $-0x8, %rdi
cmpq %rcx, %rsi
jg 0x2b6d
movq %rsi, %rcx
leaq -0x1(%rsi), %rdi
addq $-0x8, %rax
cmpq $0x1, %rsi
movq %rdi, %rsi
jg 0x2b4b
jmp 0x2ba1
leaq 0xc8e4(%rip), %r8       # 0xf483
xorl %ecx, %ecx
testq %r15, %r15
setle %r13b
cmpl $0x2, %r12d
sete %r12b
movq 0x50(%rsp), %rax
movq (%rax), %rsi
leaq 0xc5f7(%rip), %rdi      # 0xf1b6
movq %r15, %rdx
xorl %eax, %eax
callq 0x2130
orb %r13b, %r12b
movl 0x10(%rsp), %r12d
jne 0x2c58
leaq -0x1(%r15), %r13
movq 0x8(%rbp,%r13,8), %rsi
testq %r13, %r13
je 0x2c45
leaq 0x1(%r13), %rdx
movq %r13, %rax
negq %rax
decq %r13
movl $0x1, %ecx
leaq (%rsi,%rcx), %rdi
cmpq 0x8(%rbp,%r13,8), %rdi
jne 0x2c1e
leaq (%rax,%rcx), %rdi
incq %rdi
incq %rcx
decq %r13
cmpq $0x1, %rdi
jne 0x2bf7
movq $-0x1, %r13
jmp 0x2c21
movq %rcx, %rdx
cmpq $0x2, %rdx
leaq 0xc5c9(%rip), %rdi      # 0xf1f5
leaq 0xc5b2(%rip), %rax      # 0xf1e5
cmovaeq %rax, %rdi
xorl %eax, %eax
callq 0x2130
testq %r13, %r13
jns 0x2bdb
jmp 0x2c58
movl $0x1, %edx
leaq 0xc5a4(%rip), %rdi      # 0xf1f5
xorl %eax, %eax
callq 0x2130
addq %r15, %r14
movq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movl $0x8, %ecx
callq 0x5fd1
testl %eax, %eax
je 0x2b17
movq 0x28(%rsp), %rdi
callq 0x9412
leaq 0xc573(%rip), %rdi      # 0xf200
movq %r14, %rsi
xorl %eax, %eax
callq 0x2130
movq 0x20(%rsp), %r12
movq 0x30(%rsp), %r13
movq 0x18(%rsp), %rdi
leaq 0x14(%rsp), %rcx
movq %r13, %rsi
xorl %edx, %edx
callq 0x9647
testl %eax, %eax
jne 0x2e91
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x68(%rsp), %rdx
callq 0xd530
testl %eax, %eax
jne 0x2e9d
testq %r13, %r13
leaq 0xc55d(%rip), %rsi      # 0xf23f
cmovneq %r13, %rsi
leaq 0xc544(%rip), %rdi      # 0xf231
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x2130
leaq 0x68(%rsp), %rdi
callq 0x2f49
testl %r12d, %r12d
je 0x2e2f
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x58(%rsp), %rdx
callq 0x9263
testl %eax, %eax
jne 0x2ec4
movq 0x58(%rsp), %rdi
xorl %r14d, %r14d
leaq 0x48(%rsp), %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x5fd1
testl %eax, %eax
jne 0x2e19
leaq 0x28(%rsp), %rbx
leaq 0x48(%rsp), %r13
movq 0x48(%rsp), %r15
movq 0x50(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x21c0
testq %rax, %rax
jne 0x2dfd
leaq 0x1(%r15), %rdi
callq 0x2270
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2240
movb $0x0, (%rbp,%r15)
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x9647
testl %eax, %eax
je 0x2db0
movq %rbp, %rdi
callq 0x2030
jmp 0x2dfd
leaq 0xc47a(%rip), %rdi      # 0xf231
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2130
movq %rbp, %rdi
callq 0x2030
movq 0x18(%rsp), %rdi
movl 0x28(%rsp), %esi
leaq 0x68(%rsp), %r15
movq %r15, %rdx
callq 0xd530
testl %eax, %eax
jne 0x2ed3
movq %r15, %rdi
callq 0x2f49
movq 0x8(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x99d2
movq 0x58(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x5fd1
testl %eax, %eax
je 0x2d50
movl %eax, %ebp
movq 0x58(%rsp), %rdi
callq 0x9412
cmpl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
cmovnel %ebp, %r14d
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x99d2
movq 0x18(%rsp), %rdi
callq 0x3aa6
movq 0x8(%rsp), %rdi
callq 0xcd56
xorl %eax, %eax
testl %r14d, %r14d
setne %al
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x24ac
movl $0x1, %eax
jmp 0x2e59
movl %eax, %edi
callq 0x24df
jmp 0x2e89
movl %eax, %edi
callq 0x2512
movl $0x1, %r14d
jmp 0x2e47
movl %eax, %r14d
movl %eax, %edi
callq 0x25ab
jmp 0x2e3d
movl %eax, %r14d
movl %eax, %edi
callq 0x25de
jmp 0x2e3d
movl %eax, %r14d
movl %eax, %edi
callq 0x2545
jmp 0x2e3d
movl %eax, %r14d
movl %eax, %edi
callq 0x2578
jmp 0x2e3d
movl %eax, %r14d
movl %eax, %edi
callq 0x2611
jmp 0x2e3d
movl %eax, %ebp
movq 0x1011c(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2fa8
leaq 0xc29b(%rip), %rsi      # 0xf188
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2220
movl %ebp, %r14d
jmp 0x2e3d
cmpl $0x56, %eax
jne 0x2f1c
leaq 0xc0fd(%rip), %rdi      # 0xf00d
callq 0x20a0
xorl %edi, %edi
callq 0x2380
movq 0x40(%rsp), %rdi
callq 0x2644
callq 0x2668
movq 0x40(%rsp), %rdi
callq 0x2440
movq 0x40(%rsp), %rdi
callq 0x2464
movq 0x40(%rsp), %rdi
callq 0x2488