// File: /workspace/github_cpp_makefile_star2_O3/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb_dump.c
// Function: main
int main(int argc, char *argv[])
{
	int i, rc;
	MDB_env *env;
	MDB_txn *txn;
	MDB_dbi dbi;
	char *prog = argv[0];
	char *envname;
	char *subname = NULL;
	int alldbs = 0, envflags = 0, list = 0;

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

	/* -a: dump main DB and all subDBs
	 * -s: dump only the named subDB
	 * -n: use NOSUBDIR flag on env_open
	 * -p: use printable characters
	 * -f: write to file instead of stdout
	 * -V: print version and exit
	 * (default) dump only the main DB
	 */
	while ((i = getopt(argc, argv, "af:lnps:V")) != EOF) {
		switch(i) {
		case 'V':
			printf("%s\n", MDB_VERSION_STRING);
			exit(0);
			break;
		case 'l':
			list = 1;
			/*FALLTHROUGH*/;
		case 'a':
			if (subname)
				usage(prog);
			alldbs++;
			break;
		case 'f':
			if (freopen(optarg, "w", stdout) == NULL) {
				fprintf(stderr, "%s: %s: reopen: %s\n",
					prog, optarg, strerror(errno));
				exit(EXIT_FAILURE);
			}
			break;
		case 'n':
			envflags |= MDB_NOSUBDIR;
			break;
		case 'p':
			mode |= PRINT;
			break;
		case 's':
			if (alldbs)
				usage(prog);
			subname = optarg;
			break;
		default:
			usage(prog);
		}
	}

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

#ifdef SIGPIPE
	signal(SIGPIPE, dumpsig);
#endif
#ifdef SIGHUP
	signal(SIGHUP, dumpsig);
#endif
	signal(SIGINT, dumpsig);
	signal(SIGTERM, dumpsig);

	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, 2);
	}

	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;
	}

	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;
	}

	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;
	}

	if (alldbs) {
		MDB_cursor *cursor;
		MDB_val key;
		int count = 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;
		}
		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;
			count++;
			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) {
				if (list) {
					printf("%s\n", str);
					list++;
				} else {
					rc = dumpit(txn, db2, str);
					if (rc)
						break;
				}
				mdb_close(env, db2);
			}
			free(str);
			if (rc) continue;
		}
		mdb_cursor_close(cursor);
		if (!count) {
			fprintf(stderr, "%s: %s does not contain multiple databases\n", prog, envname);
			rc = MDB_NOTFOUND;
		} else if (rc == MDB_NOTFOUND) {
			rc = MDB_SUCCESS;
		}
	} else {
		rc = dumpit(txn, dbi, subname);
	}
	if (rc && rc != MDB_NOTFOUND)
		fprintf(stderr, "%s: %s: %s\n", prog, envname, mdb_strerror(rc));

	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 $0x58, %rsp
movq (%rsi), %rax
movq %rax, 0x8(%rsp)
cmpl $0x2, %edi
jl 0x2bed
movq %rsi, %r14
movl %edi, %r12d
movq $0x0, 0x10(%rsp)
leaq 0xc8f0(%rip), %r13      # 0xf061
movq 0x10860(%rip), %r15     # 0x12fd8
leaq 0xc885(%rip), %rbp      # 0xf004
movl $0x0, 0x18(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x40(%rsp)
movl 0x18(%rsp), %ebx
orl $0x4000, %ebx           # imm = 0x4000
movl %r12d, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2360
cmpl $0x6b, %eax
jle 0x27d4
addl $-0x6c, %eax
cmpl $0x7, %eax
ja 0x2bcf
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movb $0x1, 0x10af2(%rip)     # 0x132c4
jmp 0x27a2
cmpl $0x65, %eax
jle 0x282c
cmpl $0x66, %eax
jne 0x2bcf
movq (%r15), %rdi
movq 0x107dc(%rip), %rax     # 0x12fc8
movq (%rax), %rdx
leaq 0xc894(%rip), %rsi      # 0xf08a
callq 0x21b0
testq %rax, %rax
jne 0x27a2
jmp 0x2bc5
movl %ebx, 0x18(%rsp)
jmp 0x27a2
cmpl $0x0, 0x10(%rsp)
jne 0x2be3
movq (%r15), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x2798
cmpl $-0x1, %eax
je 0x2860
cmpl $0x61, %eax
je 0x2843
jmp 0x2bad
movl $0x1, 0x4(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x2bd9
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
jmp 0x278f
movq 0x10769(%rip), %r15     # 0x12fd0
decl %r12d
cmpl %r12d, (%r15)
jne 0x2bf7
leaq 0x387(%rip), %r12       # 0x2c01
movl $0xd, %edi
movq %r12, %rsi
callq 0x2230
movl $0x1, %ebx
movl $0x1, %edi
movq %r12, %rsi
callq 0x2230
movl $0x2, %edi
movq %r12, %rsi
callq 0x2230
movl $0xf, %edi
movq %r12, %rsi
callq 0x2230
movslq (%r15), %rax
movq (%r14,%rax,8), %r15
leaq 0x28(%rsp), %rdi
callq 0xbf82
testl %eax, %eax
jne 0x2aee
movq 0x10(%rsp), %rbx
testl %ebx, %ebx
setne %al
movq 0x40(%rsp), %r14
testq %r14, %r14
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x28f7
movq 0x28(%rsp), %rdi
movl $0x2, %esi
callq 0xc14b
movq 0x28(%rsp), %rdi
movl 0x18(%rsp), %edx
orl $0x20000, %edx          # imm = 0x20000
movq %r15, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xc194
testl %eax, %eax
jne 0x2af7
movq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x33c4
testl %eax, %eax
jne 0x2b00
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rcx
movq %r14, %rsi
xorl %edx, %edx
callq 0x95af
testl %eax, %eax
jne 0x2b0e
testl %ebx, %ebx
je 0x2a91
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x38(%rsp), %rdx
callq 0x91cb
testl %eax, %eax
jne 0x2b17
movq 0x38(%rsp), %rdi
xorl %r14d, %r14d
leaq 0x48(%rsp), %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x5f39
testl %eax, %eax
jne 0x2b47
movq %r15, 0x10(%rsp)
leaq 0x34(%rsp), %r15
leaq 0x48(%rsp), %r12
movq 0x48(%rsp), %r13
movq 0x50(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x21e0
testq %rax, %rax
jne 0x2a4b
incl %r14d
leaq 0x1(%r13), %rdi
callq 0x22a0
movq %rax, %rbx
movq %rax, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2270
movb $0x0, (%rbx,%r13)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x95af
testl %eax, %eax
jne 0x2a43
movl 0x4(%rsp), %ebp
testl %ebp, %ebp
je 0x2a18
movq %rbx, %rdi
callq 0x20b0
incl %ebp
movl %ebp, 0x4(%rsp)
jmp 0x2a35
movq 0x20(%rsp), %rdi
movl 0x34(%rsp), %esi
movq %rbx, %rdx
callq 0x2c0c
movl $0x0, 0x4(%rsp)
testl %eax, %eax
jne 0x2a67
movq 0x28(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x993a
movq %rbx, %rdi
callq 0x2030
movq 0x38(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x5f39
testl %eax, %eax
je 0x29a8
movl %eax, %r13d
movq 0x38(%rsp), %rdi
callq 0x937a
testl %r14d, %r14d
movq 0x10(%rsp), %r15
je 0x2b51
xorl %ebp, %ebp
cmpl $0xffff87b2, %r13d      # imm = 0xFFFF87B2
cmovnel %r13d, %ebp
jmp 0x2aa4
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq %r14, %rdx
callq 0x2c0c
movl %eax, %ebp
cmpl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
je 0x2ab4
testl %ebp, %ebp
jne 0x2b7b
movq 0x28(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x993a
xorl %ebx, %ebx
testl %ebp, %ebp
setne %bl
movq 0x20(%rsp), %rdi
callq 0x3a0e
movq 0x28(%rsp), %rdi
callq 0xccbe
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x2536
jmp 0x2add
movl %eax, %edi
callq 0x2569
jmp 0x2b07
movl %eax, %edi
callq 0x259c
movl $0x1, %ebx
jmp 0x2ad3
movl %eax, %edi
callq 0x25cf
jmp 0x2b40
movl %eax, %ebx
movq 0x104d8(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2f10
leaq 0xc5f6(%rip), %rsi      # 0xf127
movq %r14, %rdi
movl %ebx, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2250
movl $0x1, %ebx
jmp 0x2ac9
movq 0x38(%rsp), %rdi
callq 0x937a
movq 0x104a0(%rip), %rax     # 0x12ff8
movq (%rax), %rdi
leaq 0xc5ea(%rip), %rsi      # 0xf14c
movq 0x8(%rsp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2250
movl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
jmp 0x2aa4
movq 0x10476(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2f10
leaq 0xc5e5(%rip), %rsi      # 0xf178
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2250
jmp 0x2ab4
cmpl $0x56, %eax
jne 0x2bcf
leaq 0xc4b2(%rip), %rdi      # 0xf06b
callq 0x20b0
xorl %edi, %edi
callq 0x23b0
movq 0x8(%rsp), %rdi
callq 0x24a4
movq 0x8(%rsp), %rdi
callq 0x2602
movq 0x8(%rsp), %rdi
callq 0x24ee
movq 0x8(%rsp), %rdi
callq 0x2480
movq 0x8(%rsp), %rdi
callq 0x2626
movq 0x8(%rsp), %rdi
callq 0x2512