// File: /workspace/github_cpp_makefile_star2_O1/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 0x2be1
movq %rsi, %r14
movl %edi, %r12d
movq $0x0, 0x30(%rsp)
leaq 0xc8c0(%rip), %r13      # 0xf061
movq 0x10830(%rip), %r15     # 0x12fd8
leaq 0xc855(%rip), %rbp      # 0xf004
movl $0x0, 0x4(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, (%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 0x2802
addl $-0x6c, %eax
cmpl $0x7, %eax
ja 0x2bcd
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movb $0x1, 0x10ac4(%rip)     # 0x132c4
jmp 0x27d0
cmpl $0x65, %eax
jle 0x2839
cmpl $0x66, %eax
jne 0x2bcd
movq (%r15), %rdi
movq 0x107ae(%rip), %rax     # 0x12fc8
movq (%rax), %rdx
leaq 0xc866(%rip), %rsi      # 0xf08a
callq 0x21b0
testq %rax, %rax
jne 0x27d0
jmp 0x2bc3
movl %ebx, 0x18(%rsp)
jmp 0x27d0
cmpl $-0x1, %eax
je 0x287c
cmpl $0x61, %eax
je 0x284f
jmp 0x2bab
movl $0x1, (%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x2bd7
incl 0x4(%rsp)
jmp 0x27c6
cmpl $0x0, 0x4(%rsp)
jne 0x2beb
movq (%r15), %rax
movq %rax, 0x30(%rsp)
jmp 0x27c6
movq 0x1074d(%rip), %r15     # 0x12fd0
decl %r12d
cmpl %r12d, (%r15)
jne 0x2bf5
leaq 0x369(%rip), %r12       # 0x2bff
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), %r14
leaq 0x28(%rsp), %rdi
callq 0xc3f7
testl %eax, %eax
jne 0x2b06
cmpl $0x0, 0x4(%rsp)
setne %al
cmpq $0x0, 0x30(%rsp)
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x290f
movq 0x28(%rsp), %rdi
movl $0x2, %esi
callq 0xc5c8
movq 0x28(%rsp), %rdi
movl 0x18(%rsp), %edx
orl $0x20000, %edx          # imm = 0x20000
movq %r14, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xc611
testl %eax, %eax
jne 0x2b0f
movq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x3402
testl %eax, %eax
jne 0x2b18
movq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rcx
movq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x995b
testl %eax, %eax
jne 0x2b26
movq %r14, 0x18(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0x2a74
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0x9588
testl %eax, %eax
jne 0x2b34
xorl %r12d, %r12d
leaq 0x48(%rsp), %r15
movq 0x40(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0xb, %ecx
callq 0x622c
testl %eax, %eax
jne 0x2a8b
movq 0x48(%rsp), %r13
movq 0x50(%rsp), %r14
xorl %ebp, %ebp
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x21e0
testq %rax, %rax
jne 0x2a46
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 0x995b
testl %eax, %eax
je 0x2a1a
movl %eax, %ebp
jmp 0x2a3e
movl (%rsp), %ebp
testl %ebp, %ebp
je 0x2a52
movq %rbx, %rdi
callq 0x20b0
incl %ebp
movl %ebp, (%rsp)
movq 0x28(%rsp), %rdi
movl 0x3c(%rsp), %esi
callq 0x9d09
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x2030
xorl %eax, %eax
testb %al, %al
je 0x29a2
jmp 0x2a8d
movq 0x20(%rsp), %rdi
movl 0x3c(%rsp), %esi
movq %rbx, %rdx
callq 0x2c0a
movl $0x0, (%rsp)
testl %eax, %eax
je 0x2a2e
movl %eax, %ebp
movb $0x1, %al
jmp 0x2a48
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
movq 0x30(%rsp), %rdx
callq 0x2c0a
movl %eax, %ebp
jmp 0x2abc
movl %eax, %ebp
movq 0x40(%rsp), %rdi
callq 0x9737
testl %r12d, %r12d
je 0x2b48
xorl %r14d, %r14d
cmpl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
cmovel %r14d, %ebp
testl %r14d, %r14d
je 0x2abc
xorl %ebx, %ebx
cmpl $0x6, %r14d
je 0x2ada
jmp 0x2af5
cmpl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
je 0x2acc
testl %ebp, %ebp
jne 0x2b77
movq 0x28(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x9d09
movq 0x20(%rsp), %rdi
callq 0x3a75
xorl %ebx, %ebx
testl %ebp, %ebp
setne %bl
movq 0x28(%rsp), %rdi
callq 0xd120
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 0x2af5
movl %eax, %edi
callq 0x2569
jmp 0x2b1f
movl %eax, %edi
callq 0x259c
movl $0x1, %ebx
jmp 0x2aeb
movl %eax, %edi
callq 0x25cf
movl $0x1, %ebp
jmp 0x2ada
movl %eax, %ebp
movl %eax, %edi
callq 0x2602
movl $0x6, %r14d
jmp 0x2aad
movq 0x104a9(%rip), %rax     # 0x12ff8
movq (%rax), %rdi
leaq 0xc5f3(%rip), %rsi      # 0xf14c
xorl %r14d, %r14d
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x2250
movl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
jmp 0x2aad
movq 0x1047a(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x2f14
leaq 0xc5e9(%rip), %rsi      # 0xf178
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2250
jmp 0x2acc
cmpl $0x56, %eax
jne 0x2bcd
leaq 0xc4b4(%rip), %rdi      # 0xf06b
callq 0x20b0
xorl %edi, %edi
callq 0x23b0
movq 0x8(%rsp), %rdi
callq 0x24a4
movq 0x8(%rsp), %rdi
callq 0x2635
movq 0x8(%rsp), %rdi
callq 0x24ee
movq 0x8(%rsp), %rdi
callq 0x2659
movq 0x8(%rsp), %rdi
callq 0x2480
movq 0x8(%rsp), %rdi
callq 0x2512