// File: /workspace/github_cpp_makefile_star2_O1/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb_load.c
// Function: main
int main(int argc, char *argv[])
{
	int i, rc;
	MDB_env *env;
	MDB_txn *txn;
	MDB_cursor *mc;
	MDB_dbi dbi;
	char *envname;
	int envflags = 0, putflags = 0;
	int dohdr = 0;

	prog = argv[0];

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

	/* -f: load file instead of stdin
	 * -n: use NOSUBDIR flag on env_open
	 * -s: load into named subDB
	 * -N: use NOOVERWRITE on puts
	 * -T: read plaintext
	 * -V: print version and exit
	 */
	while ((i = getopt(argc, argv, "f:ns:NTV")) != EOF) {
		switch(i) {
		case 'V':
			printf("%s\n", MDB_VERSION_STRING);
			exit(0);
			break;
		case 'f':
			if (freopen(optarg, "r", stdin) == NULL) {
				fprintf(stderr, "%s: %s: reopen: %s\n",
					prog, optarg, strerror(errno));
				exit(EXIT_FAILURE);
			}
			break;
		case 'n':
			envflags |= MDB_NOSUBDIR;
			break;
		case 's':
			subname = strdup(optarg);
			break;
		case 'N':
			putflags = MDB_NOOVERWRITE|MDB_NODUPDATA;
			break;
		case 'T':
			mode |= NOHDR;
			break;
		default:
			usage();
		}
	}

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

	dbuf.mv_size = 4096;
	dbuf.mv_data = malloc(dbuf.mv_size);

	if (!(mode & NOHDR))
		readhdr();

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

	mdb_env_set_maxdbs(env, 2);

	if (info.me_maxreaders)
		mdb_env_set_maxreaders(env, info.me_maxreaders);

	if (info.me_mapsize)
		mdb_env_set_mapsize(env, info.me_mapsize);

	if (info.me_mapaddr)
		envflags |= MDB_FIXEDMAP;

	rc = mdb_env_open(env, envname, envflags, 0664);
	if (rc) {
		fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
		goto env_close;
	}

	kbuf.mv_size = mdb_env_get_maxkeysize(env) * 2 + 2;
	kbuf.mv_data = malloc(kbuf.mv_size);

	while(!Eof) {
		MDB_val key, data;
		int batch = 0;
		flags = 0;

		if (!dohdr) {
			dohdr = 1;
		} else if (!(mode & NOHDR))
			readhdr();
		
		rc = mdb_txn_begin(env, NULL, 0, &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, flags|MDB_CREATE, &dbi);
		if (rc) {
			fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
			goto txn_abort;
		}

		rc = mdb_cursor_open(txn, dbi, &mc);
		if (rc) {
			fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc));
			goto txn_abort;
		}

		while(1) {
			rc = readline(&key, &kbuf);
			if (rc == EOF)
				break;
			if (rc)
				goto txn_abort;

			rc = readline(&data, &dbuf);
			if (rc)
				goto txn_abort;
			
			rc = mdb_cursor_put(mc, &key, &data, putflags);
			if (rc == MDB_KEYEXIST && putflags)
				continue;
			if (rc)
				goto txn_abort;
			batch++;
			if (batch == 100) {
				rc = mdb_txn_commit(txn);
				if (rc) {
					fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n",
						prog, lineno, mdb_strerror(rc));
					goto env_close;
				}
				rc = mdb_txn_begin(env, NULL, 0, &txn);
				if (rc) {
					fprintf(stderr, "mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc));
					goto env_close;
				}
				rc = mdb_cursor_open(txn, dbi, &mc);
				if (rc) {
					fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc));
					goto txn_abort;
				}
				batch = 0;
			}
		}
		rc = mdb_txn_commit(txn);
		txn = NULL;
		if (rc) {
			fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n",
				prog, lineno, mdb_strerror(rc));
			goto env_close;
		}
		mdb_dbi_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 $0x48, %rsp
movl %edi, %r15d
movq (%rsi), %rdi
movq %rdi, 0x11829(%rip)     # 0x14300
cmpl $0x2, %r15d
jl 0x2ef2
movq %rsi, %r14
xorl %ebx, %ebx
leaq 0xc554(%rip), %r12      # 0xf041
movq 0x114e4(%rip), %rbp     # 0x13fd8
leaq 0xd09e(%rip), %r13      # 0xfb99
movl $0x0, 0x1c(%rsp)
movl %r15d, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2360
cmpl $0x65, %eax
jle 0x2b32
cmpl $0x66, %eax
je 0x2b49
cmpl $0x73, %eax
jne 0x2b7e
movq (%rbp), %rdi
callq 0x23f0
movq %rax, 0x117d8(%rip)     # 0x14308
jmp 0x2b03
cmpl $0x53, %eax
jle 0x2b69
cmpl $0x54, %eax
jne 0x2ed0
orb $0x2, 0x117c9(%rip)     # 0x14310
jmp 0x2b03
movq (%rbp), %rdi
movq 0x11474(%rip), %rax     # 0x13fc8
movq (%rax), %rdx
movq %r13, %rsi
callq 0x2190
testq %rax, %rax
jne 0x2b03
jmp 0x2ee8
cmpl $-0x1, %eax
je 0x2b94
cmpl $0x4e, %eax
jne 0x2eed
movl $0x30, %ebx
jmp 0x2b03
cmpl $0x6e, %eax
jne 0x2eed
movl $0x4000, 0x1c(%rsp)     # imm = 0x4000
jmp 0x2b03
movq 0x11435(%rip), %r12     # 0x13fd0
decl %r15d
cmpl %r15d, (%r12)
jne 0x2ef7
movq $0x1000, 0x11765(%rip) # imm = 0x1000
movl $0x1000, %edi           # imm = 0x1000
callq 0x2290
movq %rax, 0x1175c(%rip)     # 0x14320
testb $0x2, 0x11745(%rip)     # 0x14310
jne 0x2bd2
callq 0x2efc
movslq (%r12), %rax
movq (%r14,%rax,8), %r14
leaq 0x8(%rsp), %rdi
callq 0xca37
testl %eax, %eax
jne 0x2eb3
movq 0x8(%rsp), %rdi
movl $0x2, %esi
callq 0xcc08
movl 0x11747(%rip), %esi     # 0x14348
testl %esi, %esi
je 0x2c0f
movq 0x8(%rsp), %rdi
callq 0xcc1e
movq 0x1171a(%rip), %rsi     # 0x14330
testq %rsi, %rsi
je 0x2c25
movq 0x8(%rsp), %rdi
callq 0xcaa4
xorl %eax, %eax
cmpq $0x0, 0x116f9(%rip)     # 0x14328
setne %al
movl 0x1c(%rsp), %edx
orl %eax, %edx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xcc51
testl %eax, %eax
jne 0x2ec1
movq 0x8(%rsp), %rdi
callq 0xdffc
leal 0x2(,%rax,2), %eax
movslq %eax, %rdi
movq %rdi, 0x116e3(%rip)     # 0x14350
callq 0x2290
movq %rax, 0x116df(%rip)     # 0x14358
xorl %r14d, %r14d
cmpb $0x0, 0x116dd(%rip)     # 0x14360
jne 0x2e84
movl $0x0, 0x116d1(%rip)     # 0x14364
leaq 0x38(%rsp), %rbp
leaq 0x28(%rsp), %r12
movq 0x8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0x3a42
testl %eax, %eax
jne 0x2df7
movq 0x10(%rsp), %rdi
movq 0x11644(%rip), %rsi     # 0x14308
movl 0x1169a(%rip), %edx     # 0x14364
movl $0x40000, %eax          # imm = 0x40000
orl %eax, %edx
leaq 0x18(%rsp), %rcx
callq 0x9f9b
testl %eax, %eax
jne 0x2e03
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x9bc8
testl %eax, %eax
jne 0x2e0f
xorl %r13d, %r13d
movq %rbp, %rdi
leaq 0x11645(%rip), %rsi     # 0x14350
callq 0x32a2
cmpl $-0x1, %eax
je 0x2dc2
movq %r12, %rdi
leaq 0x115f5(%rip), %rsi     # 0x14318
callq 0x32a2
movl $0x8, %r15d
testl %eax, %eax
jne 0x2def
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl %ebx, %ecx
callq 0x4818
movl %eax, %r14d
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
jne 0x2d56
testl %ebx, %ebx
jne 0x2d01
testl %r14d, %r14d
jne 0x2e31
incl %r13d
cmpl $0x64, %r13d
jne 0x2d01
movq 0x10(%rsp), %rdi
callq 0x40db
testl %eax, %eax
jne 0x2e60
movq 0x8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0x3a42
testl %eax, %eax
jne 0x2e6c
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x9bc8
movl $0x0, %r13d
testl %eax, %eax
je 0x2d01
movl %eax, %r14d
movl %eax, %edi
callq 0x266a
jmp 0x2e31
movq 0x10(%rsp), %rdi
callq 0x40db
movq $0x0, 0x10(%rsp)
testl %eax, %eax
jne 0x2e21
movq 0x8(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0xa349
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x2e31
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x2e31
movl %eax, %r14d
movl %eax, %edi
callq 0x255c
jmp 0x2e2b
movl %eax, %r14d
movl %eax, %edi
callq 0x258f
jmp 0x2e19
movl %eax, %r14d
movl %eax, %edi
callq 0x25c2
movl $0x8, %r15d
jmp 0x2e31
movl %eax, %r14d
movl %eax, %edi
callq 0x269d
movl $0x5, %r15d
testl %r15d, %r15d
jne 0x2e78
cmpb $0x0, 0x11523(%rip)     # 0x14360
jne 0x2e84
movl $0x0, 0x1151b(%rip)     # 0x14364
testb $0x2, 0x114c0(%rip)     # 0x14310
jne 0x2c9d
callq 0x2efc
jmp 0x2c9d
movl %eax, %r14d
movl %eax, %edi
callq 0x25f5
jmp 0x2e2b
movl %eax, %r14d
movl %eax, %edi
callq 0x2637
jmp 0x2e2b
cmpl $0x5, %r15d
je 0x2e8e
cmpl $0x8, %r15d
jne 0x2eaf
movq 0x10(%rsp), %rdi
callq 0x40b5
movq 0x8(%rsp), %rdi
callq 0xd760
xorl %eax, %eax
testl %r14d, %r14d
setne %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x2ea0
movl %eax, %edi
callq 0x24f6
movl $0x1, %eax
jmp 0x2ea0
movl %eax, %edi
callq 0x2529
movl $0x1, %r14d
jmp 0x2e8e
cmpl $0x56, %eax
jne 0x2eed
leaq 0xc16e(%rip), %rdi      # 0xf04a
callq 0x20a0
xorl %edi, %edi
callq 0x23b0
callq 0x2480
callq 0x26df
callq 0x2707
callq 0x24ce