// File: /workspace/github_cpp_makefile_star2_O1/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 0x2f36
movq %rsi, %r15
movq %rdi, 0x40(%rsp)
movq $0x0, 0x28(%rsp)
leaq 0xc81f(%rip), %r13      # 0xf004
movl $0x0, 0x14(%rsp)
movl $0x0, 0x3c(%rsp)
xorl %r14d, %r14d
movl $0x0, 0x18(%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 0x2822
incl %ebx
jmp 0x280b
cmpl $0x65, %eax
jle 0x283c
cmpl $0x66, %eax
je 0x2836
cmpl $0x6e, %eax
jne 0x2855
movl %ebp, %r14d
jmp 0x280b
incl 0x18(%rsp)
jmp 0x280b
cmpl $0x60, %eax
jle 0x288f
cmpl $0x61, %eax
je 0x287a
cmpl $0x65, %eax
jne 0x2f2c
incl 0x3c(%rsp)
jmp 0x2802
cmpl $0x73, %eax
jne 0x2f2c
cmpl $0x0, 0x14(%rsp)
jne 0x2f3b
movq 0x10768(%rip), %rax     # 0x12fd8
movq (%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x2802
cmpq $0x0, 0x28(%rsp)
jne 0x2f45
incl 0x14(%rsp)
jmp 0x2802
cmpl $-0x1, %eax
jne 0x2f14
movq 0x10729(%rip), %rax     # 0x12fc8
movslq (%rax), %rax
decl %r12d
cmpl %r12d, %eax
jne 0x2f4f
movq (%r15,%rax,8), %r15
leaq 0x8(%rsp), %rdi
callq 0xc49b
testl %eax, %eax
jne 0x2e3f
cmpl $0x0, 0x14(%rsp)
setne %al
cmpq $0x0, 0x28(%rsp)
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x28eb
movq 0x8(%rsp), %rdi
movl $0x4, %esi
callq 0xc66c
movq 0x8(%rsp), %rdi
orl $0x20000, %r14d         # imm = 0x20000
movq %r15, %rsi
movl %r14d, %edx
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xc6b5
testl %eax, %eax
jne 0x2e4d
cmpl $0x0, 0x3c(%rsp)
je 0x29e9
movq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0xd8cd
movq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0xd931
leaq 0xc9a2(%rip), %rdi      # 0xf2ea
callq 0x20a0
movq (%r14), %rsi
leaq 0xc71b(%rip), %rdi      # 0xf072
xorl %eax, %eax
callq 0x2130
movq 0x8(%r14), %rsi
leaq 0xc71c(%rip), %rdi      # 0xf085
xorl %eax, %eax
callq 0x2130
movl (%r15), %esi
leaq 0xc71c(%rip), %rdi      # 0xf096
xorl %eax, %eax
callq 0x2130
movq 0x8(%r14), %rax
movl (%r15), %ecx
xorl %edx, %edx
divq %rcx
leaq 0xc713(%rip), %rdi      # 0xf0a7
movq %rax, %rsi
xorl %eax, %eax
callq 0x2130
movq 0x10(%r14), %rsi
incq %rsi
leaq 0xc70d(%rip), %rdi      # 0xf0b9
xorl %eax, %eax
callq 0x2130
movq 0x18(%r14), %rsi
leaq 0xc718(%rip), %rdi      # 0xf0d6
xorl %eax, %eax
callq 0x2130
movl 0x20(%r14), %esi
leaq 0xc722(%rip), %rdi      # 0xf0f2
xorl %eax, %eax
callq 0x2130
movl 0x24(%r14), %esi
leaq 0xc723(%rip), %rdi      # 0xf105
xorl %eax, %eax
callq 0x2130
testl %ebx, %ebx
je 0x2a6c
leaq 0xc907(%rip), %rdi      # 0xf2fb
callq 0x20a0
movq 0x8(%rsp), %rdi
movq 0x105bb(%rip), %r15     # 0x12fc0
movq (%r15), %rdx
movq 0x105c1(%rip), %rsi     # 0x12fd0
callq 0xda66
cmpl $0x2, %ebx
jl 0x2a50
movq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0xdb69
movl (%r14), %esi
leaq 0xc6ee(%rip), %rdi      # 0xf123
xorl %eax, %eax
callq 0x2130
movq 0x8(%rsp), %rdi
movq (%r15), %rdx
movq 0x10585(%rip), %rsi     # 0x12fd0
callq 0xda66
movl %eax, %ebp
cmpq $0x0, 0x28(%rsp)
jne 0x2a6c
cmpl $0x0, 0x14(%rsp)
jne 0x2a6c
cmpl $0x0, 0x18(%rsp)
je 0x2e90
movq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x34a6
testl %eax, %eax
jne 0x2eb7
cmpl $0x0, 0x18(%rsp)
je 0x2c91
leaq 0xc873(%rip), %rdi      # 0xf30f
callq 0x20a0
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rdx
xorl %esi, %esi
callq 0x962c
testl %eax, %eax
jne 0x2ecc
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x68(%rsp), %rdx
callq 0xd9a5
testl %eax, %eax
jne 0x2ed7
leaq 0x68(%rsp), %rdi
callq 0x2f59
movq 0x30(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movl $0x8, %ecx
callq 0x62d0
xorl %ebx, %ebx
testl %eax, %eax
je 0x2b10
movl %eax, %ebp
xorl %r14d, %r14d
jmp 0x2c65
leaq 0xc68f(%rip), %rbx      # 0xf1a6
leaq 0xc6d7(%rip), %r12      # 0xf1f5
xorl %r14d, %r14d
movq 0x60(%rsp), %r13
movq (%r13), %rbp
cmpl $0x2, 0x18(%rsp)
jl 0x2c3d
testq %rbp, %rbp
jle 0x2ba3
leaq (,%rbp,8), %rax
addq %r13, %rax
movl $0x1, %edx
xorl %ecx, %ecx
movq %rbp, %rsi
leaq 0xc8ed(%rip), %r8       # 0xf443
movq %rdx, %rdi
movq (%r13,%rsi,8), %rdx
cmpq %rdi, %rdx
cmovbeq %rbx, %r8
cmpq %rcx, %rsi
jle 0x2b90
leaq (,%rcx,8), %r9
movq %rax, %rdi
subq %r9, %rdi
leaq (%rdx,%rcx), %r9
cmpq (%rdi), %r9
jne 0x2b90
incq %rcx
addq $-0x8, %rdi
cmpq %rcx, %rsi
jg 0x2b78
movq %rsi, %rcx
leaq -0x1(%rsi), %rdi
addq $-0x8, %rax
cmpq $0x1, %rsi
movq %rdi, %rsi
jg 0x2b56
jmp 0x2bac
leaq 0xc899(%rip), %r8       # 0xf443
xorl %ecx, %ecx
cmpl $0x2, 0x18(%rsp)
setne %r15b
movq 0x50(%rsp), %rax
movq (%rax), %rsi
leaq 0xc5f2(%rip), %rdi      # 0xf1b6
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2130
testq %rbp, %rbp
setg %al
andb %r15b, %al
cmpb $0x1, %al
jne 0x2c3d
leaq -0x1(%rbp), %rdx
movq 0x8(%r13,%rdx,8), %rsi
leaq -0x1(%rdx), %r15
testq %rdx, %rdx
jle 0x2c12
incq %rdx
movl $0x1, %eax
leaq (%rsi,%rax), %rcx
cmpq 0x8(%r13,%r15,8), %rcx
jne 0x2c19
incq %rax
addq $-0x1, %r15
jb 0x2bf5
movq $-0x1, %r15
jmp 0x2c1c
movl $0x1, %edx
jmp 0x2c1c
movq %rax, %rdx
cmpq $0x2, %rdx
movq %r12, %rdi
leaq 0xc5bb(%rip), %rax      # 0xf1e5
cmovaeq %rax, %rdi
xorl %eax, %eax
callq 0x2130
movq %r15, %rdx
testq %r15, %r15
jns 0x2bdf
addq %rbp, %r14
movq 0x30(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movl $0x8, %ecx
callq 0x62d0
testl %eax, %eax
je 0x2b21
movl %eax, %ebp
xorl %ebx, %ebx
movq 0x30(%rsp), %rdi
callq 0x97db
leaq 0xc58a(%rip), %rdi      # 0xf200
movq %r14, %rsi
xorl %eax, %eax
callq 0x2130
cmpl $0x6, %ebx
je 0x2e86
testl %ebx, %ebx
jne 0x2eb3
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rcx
movq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x99ff
testl %eax, %eax
jne 0x2eea
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x68(%rsp), %rdx
callq 0xd9a5
testl %eax, %eax
jne 0x2ef5
movq 0x28(%rsp), %rax
testq %rax, %rax
leaq 0xc566(%rip), %rsi      # 0xf23f
cmovneq %rax, %rsi
leaq 0xc54d(%rip), %rdi      # 0xf231
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2130
leaq 0x68(%rsp), %rdi
callq 0x2f59
movl $0x0, %ebp
cmpl $0x0, 0x14(%rsp)
je 0x2e6f
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x58(%rsp), %rdx
callq 0x962c
testl %eax, %eax
jne 0x2f00
movq 0x58(%rsp), %rdi
xorl %r15d, %r15d
leaq 0x48(%rsp), %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x62d0
testl %eax, %eax
je 0x2d46
movl %eax, %ebp
jmp 0x2e5a
leaq 0x48(%rsp), %r12
movq 0x48(%rsp), %rbp
movq 0x50(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x21c0
movl $0x13, %ebx
testq %rax, %rax
je 0x2d73
xorl %ebp, %ebp
jmp 0x2e04
leaq 0x1(%rbp), %rdi
callq 0x2270
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2240
movb $0x0, (%r13,%rbp)
movq 0x20(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
leaq 0x30(%rsp), %rcx
callq 0x99ff
testl %eax, %eax
je 0x2db7
movl %eax, %ebp
movq %r13, %rdi
callq 0x2030
jmp 0x2e04
leaq 0xc473(%rip), %rdi      # 0xf231
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2030
movq 0x20(%rsp), %rdi
movl 0x30(%rsp), %esi
leaq 0x68(%rsp), %rbx
movq %rbx, %rdx
callq 0xd9a5
testl %eax, %eax
jne 0x2e2f
movq %rbx, %rdi
callq 0x2f59
movq 0x8(%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x9dad
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpl $0x13, %ebx
je 0x2e11
testl %ebx, %ebx
jne 0x2ec5
movq 0x58(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x62d0
testl %eax, %eax
je 0x2d4b
jmp 0x2e56
movl %eax, %ebp
movl %eax, %edi
callq 0x2644
movl $0x6, %ebx
jmp 0x2e04
movl %eax, %edi
callq 0x24ac
movl $0x1, %eax
jmp 0x2ea1
movl %eax, %edi
callq 0x24df
jmp 0x2ebe
movl %eax, %ebp
xorl %ebx, %ebx
movq 0x58(%rsp), %rdi
callq 0x97db
cmpl $0x6, %r15d
je 0x2e86
testl %r15d, %r15d
jne 0x2eb3
cmpl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
cmovel %ebx, %ebp
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x9dad
movq 0x20(%rsp), %rdi
callq 0x3b19
movq 0x8(%rsp), %rdi
callq 0xd1c4
xorl %eax, %eax
testl %ebp, %ebp
setne %al
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x2ea1
movl %eax, %edi
callq 0x2512
movl $0x1, %ebp
jmp 0x2e90
movl %ebx, %r15d
xorl %ebx, %ebx
jmp 0x2e64
movl %eax, %ebp
movl %eax, %edi
callq 0x2545
jmp 0x2ee0
movl %eax, %ebp
movl %eax, %edi
callq 0x2578
movl $0x6, %ebx
jmp 0x2c80
movl %eax, %ebp
movl %eax, %edi
callq 0x25ab
jmp 0x2e86
movl %eax, %ebp
movl %eax, %edi
callq 0x25de
jmp 0x2e86
movl %eax, %ebp
movl %eax, %edi
callq 0x2611
movl $0x6, %r15d
jmp 0x2e64
cmpl $0x56, %eax
jne 0x2f2c
leaq 0xc0ed(%rip), %rdi      # 0xf00d
callq 0x20a0
xorl %edi, %edi
callq 0x2380
movq 0x40(%rsp), %rdi
callq 0x2677
callq 0x269b
movq 0x40(%rsp), %rdi
callq 0x2440
movq 0x40(%rsp), %rdi
callq 0x2464
movq 0x40(%rsp), %rdi
callq 0x2488