// File: /workspace/github_cpp_makefile_star2_O3/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, 0x11899(%rip)     # 0x14300
cmpl $0x2, %r15d
jl 0x2e8b
movq %rsi, %r14
movl $0x0, 0x18(%rsp)
leaq 0xc5be(%rip), %r12      # 0xf041
movq 0x1154e(%rip), %rbp     # 0x13fd8
movq 0x11537(%rip), %rbx     # 0x13fc8
leaq 0xd141(%rip), %r13      # 0xfbd9
movl $0x0, 0x1c(%rsp)
movl %r15d, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2360
cmpl $0x65, %eax
jle 0x2acf
cmpl $0x66, %eax
je 0x2ae6
cmpl $0x73, %eax
jne 0x2b17
movq (%rbp), %rdi
callq 0x23f0
movq %rax, 0x1183b(%rip)     # 0x14308
jmp 0x2aa0
cmpl $0x53, %eax
jle 0x2aff
cmpl $0x54, %eax
jne 0x2e69
orb $0x2, 0x1182c(%rip)     # 0x14310
jmp 0x2aa0
movq (%rbp), %rdi
movq (%rbx), %rdx
movq %r13, %rsi
callq 0x2190
testq %rax, %rax
jne 0x2aa0
jmp 0x2e81
cmpl $-0x1, %eax
je 0x2b2d
cmpl $0x4e, %eax
jne 0x2e86
movl $0x30, 0x18(%rsp)
jmp 0x2aa0
cmpl $0x6e, %eax
jne 0x2e86
movl $0x4000, 0x1c(%rsp)     # imm = 0x4000
jmp 0x2aa0
movq 0x1149c(%rip), %rbx     # 0x13fd0
movl (%rbx), %ebp
decl %r15d
cmpl %r15d, %ebp
jne 0x2e90
movq $0x1000, 0x117cb(%rip) # imm = 0x1000
movl $0x1000, %edi           # imm = 0x1000
callq 0x2290
movq %rax, 0x117c2(%rip)     # 0x14320
testb $0x2, 0x117ab(%rip)     # 0x14310
jne 0x2b6e
callq 0x2e95
movl (%rbx), %ebp
movslq %ebp, %rax
movq (%r14,%rax,8), %r14
movq %rsp, %rdi
callq 0xc5d6
testl %eax, %eax
jne 0x2dc2
movq (%rsp), %rdi
movl $0x2, %esi
callq 0xc79f
movl 0x117af(%rip), %esi     # 0x14348
testl %esi, %esi
je 0x2ba6
movq (%rsp), %rdi
callq 0xc7b5
movq 0x11783(%rip), %rsi     # 0x14330
testq %rsi, %rsi
je 0x2bbb
movq (%rsp), %rdi
callq 0xc643
xorl %eax, %eax
cmpq $0x0, 0x11763(%rip)     # 0x14328
setne %al
movl 0x1c(%rsp), %edx
orl %eax, %edx
movq (%rsp), %rdi
movq %r14, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xc7e8
testl %eax, %eax
jne 0x2dd0
movq (%rsp), %rdi
callq 0xdb91
leal 0x2(,%rax,2), %eax
movslq %eax, %rdi
movq %rdi, 0x1174f(%rip)     # 0x14350
callq 0x2290
movq %rax, 0x1174b(%rip)     # 0x14358
cmpb $0x0, 0x1174c(%rip)     # 0x14360
je 0x2c1d
xorl %ebx, %ebx
jmp 0x2e21
movl $0x0, 0x1173d(%rip)     # 0x14364
movq (%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a18
testl %eax, %eax
jne 0x2dd9
movl $0x40000, %eax          # imm = 0x40000
leaq 0x14(%rsp), %rcx
leaq 0x116fe(%rip), %r12     # 0x14350
leaq 0x38(%rsp), %r13
leaq 0x116ba(%rip), %rbp     # 0x14318
leaq 0x28(%rsp), %r14
movq 0x8(%rsp), %rdi
movq 0x11699(%rip), %rsi     # 0x14308
movl 0x116ef(%rip), %edx     # 0x14364
orl %eax, %edx
callq 0x9c03
testl %eax, %eax
jne 0x2e0c
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x981f
testl %eax, %eax
jne 0x2e15
xorl %ebx, %ebx
movl 0x18(%rsp), %r15d
movq %r13, %rdi
movq %r12, %rsi
callq 0x329e
cmpl $-0x1, %eax
je 0x2d4c
movq %r14, %rdi
movq %rbp, %rsi
callq 0x329e
testl %eax, %eax
jne 0x2e1c
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x4775
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
jne 0x2cec
testl %r15d, %r15d
jne 0x2ca6
testl %eax, %eax
jne 0x2e1c
incl %ebx
cmpl $0x64, %ebx
jne 0x2ca6
movq 0x8(%rsp), %rdi
callq 0x4088
testl %eax, %eax
jne 0x2e4e
movq (%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x3a18
testl %eax, %eax
jne 0x2e57
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x981f
movl $0x0, %ebx
testl %eax, %eax
je 0x2ca6
jmp 0x2e60
movq 0x8(%rsp), %rdi
callq 0x4088
movq $0x0, 0x8(%rsp)
testl %eax, %eax
jne 0x2e45
movq (%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x9f8e
cmpb $0x1, 0x115e5(%rip)     # 0x14360
je 0x2c16
movl $0x0, 0x115d9(%rip)     # 0x14364
testb $0x2, 0x1157e(%rip)     # 0x14310
jne 0x2d99
callq 0x2e95
movq (%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x3a18
movl %eax, %r15d
testl %eax, %eax
movl $0x40000, %eax          # imm = 0x40000
leaq 0x14(%rsp), %rcx
je 0x2c63
jmp 0x2ddc
movl %eax, %edi
callq 0x24f6
movl $0x1, %ebx
jmp 0x2e34
movl %eax, %edi
callq 0x2529
jmp 0x2e05
movl %eax, %r15d
movq 0x11215(%rip), %rax     # 0x13ff8
movq (%rax), %rbx
movl %r15d, %edi
callq 0x3564
leaq 0xc2ce(%rip), %rsi      # 0xf0c3
movq %rbx, %rdi
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2240
movl $0x1, %ebx
jmp 0x2e2b
movl %eax, %edi
callq 0x255c
jmp 0x2e1c
movl %eax, %edi
callq 0x258f
movl $0x1, %ebx
movq 0x8(%rsp), %rdi
callq 0x4062
movq (%rsp), %rdi
callq 0xd312
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x266a
jmp 0x2e05
movl %eax, %edi
callq 0x25c2
jmp 0x2e05
movl %eax, %edi
callq 0x2604
jmp 0x2e05
movl %eax, %edi
callq 0x2637
jmp 0x2e1c
cmpl $0x56, %eax
jne 0x2e86
leaq 0xc1d5(%rip), %rdi      # 0xf04a
callq 0x20a0
xorl %edi, %edi
callq 0x23b0
callq 0x2480
callq 0x26ac
callq 0x26d4
callq 0x24ce