// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq (%rsi), %rax
movq %rax, 0x10(%rsp)
cmpl $0x2, %edi
jl 0x2a38
movq %rsi, %r14
movl %edi, %r12d
movq $0x0, 0x30(%rsp)
leaq 0xbab0(%rip), %r13      # 0xe061
leaq 0xbad2(%rip), %rbx      # 0xe08a
leaq 0xba45(%rip), %r15      # 0xe004
movl $0x0, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x40(%rsp)
movl 0x18(%rsp), %ebp
orl $0x4000, %ebp           # imm = 0x4000
movl %r12d, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2370
leal -0x6c(%rax), %ecx
cmpl $0x7, %ecx
ja 0x260a
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movb $0x1, 0x10cbc(%rip)     # 0x132c4
jmp 0x25e2
cmpl $0x66, %eax
jne 0x2663
movq 0x109c2(%rip), %rax     # 0x12fd8
movq (%rax), %rdi
movq 0x109a8(%rip), %rax     # 0x12fc8
movq (%rax), %rdx
movq %rbx, %rsi
callq 0x21b0
testq %rax, %rax
jne 0x25e2
jmp 0x2a42
movl %ebp, 0x18(%rsp)
jmp 0x25e2
cmpl $0x0, 0x30(%rsp)
jne 0x2a38
movq 0x1098b(%rip), %rax     # 0x12fd8
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
jmp 0x25d8
cmpl $-0x1, %eax
je 0x2696
cmpl $0x61, %eax
je 0x2679
jmp 0x2a20
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x2a38
movq 0x30(%rsp), %rax
incl %eax
movq %rax, 0x30(%rsp)
jmp 0x25cf
movq 0x10933(%rip), %r15     # 0x12fd0
decl %r12d
cmpl %r12d, (%r15)
jne 0x2a38
leaq 0x3fa(%rip), %r12       # 0x2aaa
pushq $0xd
popq %rdi
movq %r12, %rsi
callq 0x2230
pushq $0x1
popq %rbx
movl %ebx, %edi
movq %r12, %rsi
callq 0x2230
pushq $0x2
popq %rdi
movq %r12, %rsi
callq 0x2230
pushq $0xf
popq %rdi
movq %r12, %rsi
callq 0x2230
movslq (%r15), %rax
movq (%r14,%rax,8), %r15
leaq 0x28(%rsp), %rdi
callq 0xb723
testl %eax, %eax
jne 0x28f8
movq 0x30(%rsp), %r14
testl %r14d, %r14d
setne %al
movq 0x40(%rsp), %r12
testq %r12, %r12
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x2721
movq 0x28(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0xb8d3
movq 0x28(%rsp), %rdi
movl 0x18(%rsp), %edx
orl $0x20000, %edx          # imm = 0x20000
movq %r15, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xb917
testl %eax, %eax
jne 0x2926
movq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x31fb
testl %eax, %eax
jne 0x2942
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rcx
movq %r12, %rsi
xorl %edx, %edx
callq 0x8f6b
testl %eax, %eax
jne 0x2973
testl %r14d, %r14d
movq %r15, 0x48(%rsp)
je 0x289b
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x50(%rsp), %rdx
callq 0x8bb0
testl %eax, %eax
jne 0x298f
xorl %r12d, %r12d
leaq 0x58(%rsp), %r15
pushq $0xb
popq %rbp
movq 0x50(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %ebp, %ecx
callq 0x5b7b
testl %eax, %eax
jne 0x2876
movq 0x58(%rsp), %r13
movq 0x60(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x21e0
testq %rax, %rax
jne 0x27b3
incl %r12d
leaq 0x1(%r13), %rdi
callq 0x22a0
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2270
movb $0x0, (%rbx,%r13)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
leaq 0x3c(%rsp), %rcx
callq 0x8f6b
testl %eax, %eax
jne 0x2869
movl 0xc(%rsp), %r14d
testl %r14d, %r14d
je 0x283e
movq %rbx, %rdi
callq 0x20b0
incl %r14d
movl %r14d, 0xc(%rsp)
jmp 0x285b
movq 0x20(%rsp), %rdi
movl 0x3c(%rsp), %esi
movq %rbx, %rdx
callq 0x2ab5
movl $0x0, 0xc(%rsp)
testl %eax, %eax
jne 0x2876
movq 0x28(%rsp), %rdi
movl 0x3c(%rsp), %esi
callq 0x92c2
movq %rbx, %rdi
callq 0x2030
jmp 0x27b3
movl %eax, %r13d
movq 0x50(%rsp), %rdi
callq 0x8d5a
testl %r12d, %r12d
je 0x29c0
xorl %ebp, %ebp
cmpl $0xffff87b2, %r13d      # imm = 0xFFFF87B2
cmovnel %r13d, %ebp
jmp 0x28ae
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq %r12, %rdx
callq 0x2ab5
movl %eax, %ebp
cmpl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
je 0x28be
testl %ebp, %ebp
jne 0x29ec
movq 0x28(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x92c2
xorl %ebx, %ebx
testl %ebp, %ebp
setne %bl
movq 0x20(%rsp), %rdi
callq 0x37f0
movq 0x28(%rsp), %rdi
callq 0xc3f9
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r14d
movq 0x106f6(%rip), %rax     # 0x12ff8
movq (%rax), %r15
movl %r14d, %edi
callq 0x2d64
leaq 0xb78c(%rip), %rsi      # 0xe0a0
movq %r15, %rdi
movl %r14d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2250
jmp 0x28e7
movl %eax, %ebx
movq 0x106c9(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2d64
leaq 0xb784(%rip), %rsi      # 0xe0c4
jmp 0x295c
movl %eax, %ebx
movq 0x106ad(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2d64
leaq 0xb78a(%rip), %rsi      # 0xe0e6
movq %r14, %rdi
movl %ebx, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2250
pushq $0x1
popq %rbx
jmp 0x28dd
movl %eax, %ebx
movq 0x1067c(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2d64
leaq 0xb77c(%rip), %rsi      # 0xe109
jmp 0x29a9
movl %eax, %ebx
movq 0x10660(%rip), %rax     # 0x12ff8
movq (%rax), %r14
movl %ebx, %edi
callq 0x2d64
leaq 0xb77e(%rip), %rsi      # 0xe127
movq %r14, %rdi
movl %ebx, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2250
pushq $0x1
popq %rbx
jmp 0x28d3
movq 0x10631(%rip), %rax     # 0x12ff8
movq (%rax), %rdi
leaq 0xb77b(%rip), %rsi      # 0xe14c
movq 0x10(%rsp), %rdx
movq 0x48(%rsp), %rcx
xorl %eax, %eax
callq 0x2250
movl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
jmp 0x28ae
movq 0x10605(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2d64
leaq 0xb774(%rip), %rsi      # 0xe178
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2250
jmp 0x28be
cmpl $0x56, %eax
jne 0x2a38
leaq 0xb63f(%rip), %rdi      # 0xe06b
callq 0x20b0
xorl %edi, %edi
callq 0x23c0
movq 0x10(%rsp), %rdi
callq 0x2a86
movq 0x105af(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movq 0x10585(%rip), %rax     # 0x12fd8
movq (%rax), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2410
leaq 0xb623(%rip), %rsi      # 0xe08c
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2250
pushq $0x1
popq %rdi
callq 0x23c0