// File: /workspace/github_cpp_makefile_star2_O2/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
movq (%rsi), %rax
movq %rax, 0x10d6c(%rip)     # 0x13300
cmpl $0x2, %edi
jl 0x29f9
movq %rsi, %r14
movl %edi, %r15d
movl $0x0, 0x1c(%rsp)
leaq 0xba8f(%rip), %r12      # 0xe041
movq 0x10a1f(%rip), %rbp     # 0x12fd8
movq 0x10a08(%rip), %rbx     # 0x12fc8
leaq 0xc5f2(%rip), %r13      # 0xebb9
movl $0x0, 0xc(%rsp)
movl %r15d, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2370
cmpl $0x54, %eax
je 0x2617
cmpl $0x66, %eax
je 0x25fe
cmpl $0x73, %eax
jne 0x2620
movq (%rbp), %rdi
callq 0x2400
movq %rax, 0x10d0c(%rip)     # 0x13308
jmp 0x25cf
movq (%rbp), %rdi
movq (%rbx), %rdx
movq %r13, %rsi
callq 0x2190
testq %rax, %rax
jne 0x25cf
jmp 0x29fe
orb $0x2, 0x10cf2(%rip)     # 0x13310
jmp 0x25cf
cmpl $-0x1, %eax
je 0x2646
cmpl $0x4e, %eax
je 0x263d
cmpl $0x6e, %eax
jne 0x29e1
movl $0x4000, 0xc(%rsp)      # imm = 0x4000
jmp 0x25cf
pushq $0x30
popq %rax
movl %eax, 0x1c(%rsp)
jmp 0x25cf
movq 0x10983(%rip), %rbx     # 0x12fd0
movl (%rbx), %ebp
decl %r15d
cmpl %r15d, %ebp
jne 0x29f9
movq $0x1000, 0x10cb2(%rip) # imm = 0x1000
movl $0x1000, %edi           # imm = 0x1000
callq 0x2290
movq %rax, 0x10ca9(%rip)     # 0x13320
testb $0x2, 0x10c92(%rip)     # 0x13310
jne 0x2687
callq 0x2a69
movl (%rbx), %ebp
movslq %ebp, %rax
movq (%r14,%rax,8), %r14
movq %rsp, %rdi
callq 0xbb77
testl %eax, %eax
jne 0x28a2
movq (%rsp), %rdi
pushq $0x2
popq %rsi
callq 0xbd27
movl 0x10c98(%rip), %esi     # 0x13348
testl %esi, %esi
je 0x26bd
movq (%rsp), %rdi
callq 0xbd3b
movq 0x10c6c(%rip), %rsi     # 0x13330
testq %rsi, %rsi
je 0x26d2
movq (%rsp), %rdi
callq 0xbbd8
xorl %eax, %eax
cmpq $0x0, 0x10c4c(%rip)     # 0x13328
setne %al
movl 0xc(%rsp), %edx
orl %eax, %edx
movq (%rsp), %rdi
movq %r14, %rsi
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xbd6b
testl %eax, %eax
jne 0x28d6
movq (%rsp), %rdi
callq 0xd061
leal 0x2(,%rax,2), %eax
movslq %eax, %rdi
movq %rdi, 0x10c38(%rip)     # 0x13350
callq 0x2290
movq %rax, 0x10c34(%rip)     # 0x13358
movb $0x1, %al
leaq 0x10c23(%rip), %r13     # 0x13350
leaq 0x38(%rsp), %rbp
leaq 0x10bdf(%rip), %r15     # 0x13318
leaq 0x28(%rsp), %r14
movb 0x10c1c(%rip), %bl      # 0x13360
testb %bl, %bl
jne 0x2979
andl $0x0, 0x10c11(%rip)     # 0x13364
testb $0x1, %al
jne 0x2765
testb $0x2, 0x10bb2(%rip)     # 0x13310
jne 0x2765
callq 0x2a69
movq (%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0x364f
testl %eax, %eax
jne 0x2907
movq 0x10(%rsp), %rdi
movq 0x10b7d(%rip), %rsi     # 0x13308
movl 0x10bd3(%rip), %edx     # 0x13364
movl $0x40000, %eax          # imm = 0x40000
orl %eax, %edx
leaq 0x18(%rsp), %rcx
callq 0x93bf
testl %eax, %eax
movb %bl, 0xc(%rsp)
jne 0x2949
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x9004
testl %eax, %eax
jne 0x292b
xorl %ebx, %ebx
movl 0x1c(%rsp), %r12d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2f10
cmpl $-0x1, %eax
je 0x2876
movq %r14, %rdi
movq %r15, %rsi
callq 0x2f10
testl %eax, %eax
jne 0x2975
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl %r12d, %ecx
callq 0x49e7
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
jne 0x2816
testl %r12d, %r12d
jne 0x27d0
testl %eax, %eax
jne 0x2975
incl %ebx
cmpl $0x64, %ebx
jne 0x27cb
movq 0x10(%rsp), %rdi
callq 0x3c6a
testl %eax, %eax
jne 0x29a3
movq (%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0x364f
testl %eax, %eax
jne 0x2907
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x9004
movl $0x0, %ebx
testl %eax, %eax
je 0x27cb
jmp 0x292b
movq 0x10(%rsp), %rdi
callq 0x3c6a
andq $0x0, 0x10(%rsp)
testl %eax, %eax
jne 0x29a3
movq (%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x9716
xorl %eax, %eax
jmp 0x273e
movl %eax, %r15d
movq 0x1074c(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %r15d, %edi
callq 0x31b8
leaq 0xb7bf(%rip), %rsi      # 0xe07d
movq %rbx, %rdi
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2240
pushq $0x1
popq %rbx
jmp 0x2992
movl %eax, %ebp
movq 0x10719(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %ebp, %edi
callq 0x31b8
leaq 0xb7b1(%rip), %rsi      # 0xe0a1
movq %rbx, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2240
pushq $0x1
popq %rbx
jmp 0x2989
movl %eax, %r12d
movq 0x106e7(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %r12d, %edi
callq 0x31b8
leaq 0xb7a0(%rip), %rsi      # 0xe0c3
movq %rbx, %rdi
movl %r12d, %edx
jmp 0x28f5
movl %eax, %r12d
movq 0x106c3(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %r12d, %edi
callq 0x31b8
leaq 0xb7bd(%rip), %rsi      # 0xe104
jmp 0x2965
movl %eax, %r12d
movq 0x106a5(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movl %r12d, %edi
callq 0x31b8
leaq 0xb781(%rip), %rsi      # 0xe0e6
movq %rbx, %rdi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2240
movb 0xc(%rsp), %bl
xorb $0x1, %bl
movq 0x10(%rsp), %rdi
callq 0x3c44
movzbl %bl, %ebx
movq (%rsp), %rdi
callq 0xc84d
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1064e(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movq 0x1094c(%rip), %r14     # 0x13300
movq 0x109ad(%rip), %r15     # 0x13368
movl %eax, %edi
callq 0x31b8
leaq 0xb760(%rip), %rsi      # 0xe129
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2240
jmp 0x28ff
cmpl $0x56, %eax
jne 0x29f9
leaq 0xb65d(%rip), %rdi      # 0xe04a
callq 0x20a0
xorl %edi, %edi
callq 0x23c0
callq 0x2a41
movq 0x105f3(%rip), %rax     # 0x12ff8
movq (%rax), %rbx
movq 0x108f1(%rip), %r14     # 0x13300
movq (%rbp), %r15
callq 0x2050
movl (%rax), %edi
callq 0x2410
leaq 0xb643(%rip), %rsi      # 0xe069
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2240
pushq $0x1
popq %rdi
callq 0x23c0