// File: /workspace/github_cpp_makefile_star2_O1/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mtest.c
// Function: main
int main(int argc,char * argv[])
{
	int i = 0, j = 0, rc;
	MDB_env *env;
	MDB_dbi dbi;
	MDB_val key, data;
	MDB_txn *txn;
	MDB_stat mst;
	MDB_cursor *cursor, *cur2;
	MDB_cursor_op op;
	int count;
	int *values;
	char sval[32] = "";

	srand(time(NULL));

	    count = (rand()%384) + 64;
	    values = (int *)malloc(count*sizeof(int));

	    for(i = 0;i<count;i++) {
			values[i] = rand()%1024;
	    }
    
		E(mdb_env_create(&env));
		E(mdb_env_set_maxreaders(env, 1));
		E(mdb_env_set_mapsize(env, 10485760));
		E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));

		E(mdb_txn_begin(env, NULL, 0, &txn));
		E(mdb_dbi_open(txn, NULL, 0, &dbi));
   
		key.mv_size = sizeof(int);
		key.mv_data = sval;

		printf("Adding %d values\n", count);
	    for (i=0;i<count;i++) {	
			sprintf(sval, "%03x %d foo bar", values[i], values[i]);
			/* Set <data> in each iteration, since MDB_NOOVERWRITE may modify it */
			data.mv_size = sizeof(sval);
			data.mv_data = sval;
			if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
				j++;
				data.mv_size = sizeof(sval);
				data.mv_data = sval;
			}
	    }
		if (j) printf("%d duplicates skipped\n", j);
		E(mdb_txn_commit(txn));
		E(mdb_env_stat(env, &mst));

		E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
		E(mdb_cursor_open(txn, dbi, &cursor));
		while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
			printf("key: %p %.*s, data: %p %.*s\n",
				key.mv_data,  (int) key.mv_size,  (char *) key.mv_data,
				data.mv_data, (int) data.mv_size, (char *) data.mv_data);
		}
		CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
		mdb_cursor_close(cursor);
		mdb_txn_abort(txn);

		j=0;
		key.mv_data = sval;
	    for (i= count - 1; i > -1; i-= (rand()%5)) {
			j++;
			txn=NULL;
			E(mdb_txn_begin(env, NULL, 0, &txn));
			sprintf(sval, "%03x ", values[i]);
			if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
				j--;
				mdb_txn_abort(txn);
			} else {
				E(mdb_txn_commit(txn));
			}
	    }
	    free(values);
		printf("Deleted %d values\n", j);

		E(mdb_env_stat(env, &mst));
		E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
		E(mdb_cursor_open(txn, dbi, &cursor));
		printf("Cursor next\n");
		while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
			printf("key: %.*s, data: %.*s\n",
				(int) key.mv_size,  (char *) key.mv_data,
				(int) data.mv_size, (char *) data.mv_data);
		}
		CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
		printf("Cursor last\n");
		E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
		printf("key: %.*s, data: %.*s\n",
			(int) key.mv_size,  (char *) key.mv_data,
			(int) data.mv_size, (char *) data.mv_data);
		printf("Cursor prev\n");
		while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
			printf("key: %.*s, data: %.*s\n",
				(int) key.mv_size,  (char *) key.mv_data,
				(int) data.mv_size, (char *) data.mv_data);
		}
		CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
		printf("Cursor last/prev\n");
		E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
			printf("key: %.*s, data: %.*s\n",
				(int) key.mv_size,  (char *) key.mv_data,
				(int) data.mv_size, (char *) data.mv_data);
		E(mdb_cursor_get(cursor, &key, &data, MDB_PREV));
			printf("key: %.*s, data: %.*s\n",
				(int) key.mv_size,  (char *) key.mv_data,
				(int) data.mv_size, (char *) data.mv_data);

		mdb_cursor_close(cursor);
		mdb_txn_abort(txn);

		printf("Deleting with cursor\n");
		E(mdb_txn_begin(env, NULL, 0, &txn));
		E(mdb_cursor_open(txn, dbi, &cur2));
		for (i=0; i<50; i++) {
			if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
				break;
			printf("key: %p %.*s, data: %p %.*s\n",
				key.mv_data,  (int) key.mv_size,  (char *) key.mv_data,
				data.mv_data, (int) data.mv_size, (char *) data.mv_data);
			E(mdb_del(txn, dbi, &key, NULL));
		}

		printf("Restarting cursor in txn\n");
		for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
			if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, op)))
				break;
			printf("key: %p %.*s, data: %p %.*s\n",
				key.mv_data,  (int) key.mv_size,  (char *) key.mv_data,
				data.mv_data, (int) data.mv_size, (char *) data.mv_data);
		}
		mdb_cursor_close(cur2);
		E(mdb_txn_commit(txn));

		printf("Restarting cursor outside txn\n");
		E(mdb_txn_begin(env, NULL, 0, &txn));
		E(mdb_cursor_open(txn, dbi, &cursor));
		for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
			if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, op)))
				break;
			printf("key: %p %.*s, data: %p %.*s\n",
				key.mv_data,  (int) key.mv_size,  (char *) key.mv_data,
				data.mv_data, (int) data.mv_size, (char *) data.mv_data);
		}
		mdb_cursor_close(cursor);
		mdb_txn_abort(txn);

		mdb_dbi_close(env, dbi);
		mdb_env_close(env);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
xorl %edi, %edi
callq 0x2250
movl %eax, %edi
callq 0x21d0
callq 0x2410
cltq
imulq $0x2aaaaaab, %rax, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x26, %rcx
addl %edx, %ecx
shll $0x7, %ecx
leal (%rcx,%rcx,2), %ecx
movl %eax, %r14d
subl %ecx, %r14d
negl %ecx
leal (%rax,%rcx), %ebp
addl $0x40, %ebp
movslq %r14d, %r15
leaq 0x100(,%r15,4), %rdi
callq 0x2280
movq %rax, %rbx
cmpl $-0x3f, %r15d
jl 0x2d2a
movl %ebp, %r15d
xorl %r12d, %r12d
callq 0x2410
leal 0x3ff(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
subl %ecx, %eax
movl %eax, (%rbx,%r12,4)
incq %r12
cmpq %r12, %r15
jne 0x2d06
leaq 0x38(%rsp), %rdi
callq 0xca23
testl %eax, %eax
jne 0x34ad
movq 0x38(%rsp), %rdi
movl $0x1, %esi
callq 0xcc0a
testl %eax, %eax
jne 0x34b4
movq 0x38(%rsp), %rdi
movl $0xa00000, %esi         # imm = 0xA00000
callq 0xca90
testl %eax, %eax
jne 0x34bb
movq 0x38(%rsp), %rdi
leaq 0xc2fc(%rip), %rsi      # 0xf072
movl $0x1, %edx
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xcc3d
testl %eax, %eax
jne 0x34c2
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a2e
testl %eax, %eax
jne 0x34c9
movq 0x8(%rsp), %rdi
xorl %r15d, %r15d
leaq 0x14(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x9f87
testl %eax, %eax
jne 0x34d0
movq $0x4, 0x28(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0xc311(%rip), %rdi      # 0xf0f1
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
cmpl $-0x3f, %r14d
jl 0x2e69
movl %ebp, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
movl (%rbx,%r13,4), %ecx
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
leaq 0xc2f8(%rip), %rsi      # 0xf103
movl %ecx, %edx
xorl %eax, %eax
callq 0x2370
movq $0x20, 0x18(%rsp)
movq %rbp, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x28(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movl $0x10, %r8d
callq 0x9ee8
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
je 0x2e50
testl %eax, %eax
je 0x2e61
jmp 0x3498
incl %r15d
movq $0x20, 0x18(%rsp)
movq %rbp, 0x20(%rsp)
incq %r13
cmpq %r13, %r12
jne 0x2df8
testl %r15d, %r15d
je 0x2e7f
leaq 0xc2ce(%rip), %rdi      # 0xf143
movl %r15d, %esi
xorl %eax, %eax
callq 0x2130
movq 0x8(%rsp), %rdi
callq 0x40c7
testl %eax, %eax
leaq 0x50(%rsp), %rbp
jne 0x34d7
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xde55
testl %eax, %eax
jne 0x34de
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x3a2e
testl %eax, %eax
jne 0x34e5
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0x9bb4
testl %eax, %eax
jne 0x34ec
leaq 0x28(%rsp), %r15
leaq 0x18(%rsp), %r12
leaq 0xc2dd(%rip), %r13      # 0xf1d4
movq 0x40(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x8, %ecx
callq 0x6858
testl %eax, %eax
jne 0x2f36
movq 0x30(%rsp), %rcx
movl 0x28(%rsp), %edx
movq 0x20(%rsp), %r8
movl 0x18(%rsp), %r9d
movq %r8, (%rsp)
movq %r13, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
jmp 0x2ef7
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x3460
movq 0x40(%rsp), %rdi
callq 0x9d63
movq 0x8(%rsp), %rdi
callq 0x40a1
movq %rbp, 0x30(%rsp)
xorl %ebp, %ebp
cmpl $-0x3f, %r14d
jl 0x301f
addl $0x3f, %r14d
leaq 0xc28f(%rip), %r15      # 0xf200
leaq 0x50(%rsp), %r12
leaq 0x28(%rsp), %r13
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movq 0x38(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x3a2e
testl %eax, %eax
jne 0x3475
movl %r14d, %eax
movl (%rbx,%rax,4), %edx
movq %r12, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2370
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x9dc7
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
je 0x2fec
testl %eax, %eax
jne 0x34a6
movq 0x8(%rsp), %rdi
callq 0x40c7
testl %eax, %eax
jne 0x349f
incl %ebp
jmp 0x2ff6
movq 0x8(%rsp), %rdi
callq 0x40a1
callq 0x2410
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %eax, %ecx
addl %ecx, %r14d
jns 0x2f7d
movq %rbx, %rdi
callq 0x2030
leaq 0xc1f6(%rip), %rdi      # 0xf224
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xde55
testl %eax, %eax
jne 0x34f3
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x3a2e
testl %eax, %eax
jne 0x34fa
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0x9bb4
testl %eax, %eax
jne 0x3501
leaq 0xc2b7(%rip), %rdi      # 0xf345
callq 0x20a0
leaq 0x28(%rsp), %rbx
leaq 0x18(%rsp), %r14
leaq 0xc193(%rip), %r15      # 0xf237
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x8, %ecx
callq 0x6858
testl %eax, %eax
jne 0x30db
movl 0x28(%rsp), %esi
movq 0x30(%rsp), %rdx
movl 0x18(%rsp), %ecx
movq 0x20(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x30a4
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x3467
leaq 0xc264(%rip), %rdi      # 0xf351
callq 0x20a0
movq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movl $0x6, %ecx
callq 0x6858
testl %eax, %eax
jne 0x3508
leaq 0x28(%rsp), %rbx
movl (%rbx), %esi
movq 0x8(%rbx), %rdx
leaq 0x18(%rsp), %r14
movl (%r14), %ecx
movq 0x8(%r14), %r8
leaq 0xc106(%rip), %r15      # 0xf237
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
leaq 0xc21b(%rip), %rdi      # 0xf35d
callq 0x20a0
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0xc, %ecx
callq 0x6858
testl %eax, %eax
jne 0x317e
movl 0x28(%rsp), %esi
movq 0x30(%rsp), %rdx
movl 0x18(%rsp), %ecx
movq 0x20(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x3147
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x346e
leaq 0xc1d9(%rip), %rdi      # 0xf369
callq 0x20a0
movq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movl $0x6, %ecx
callq 0x6858
testl %eax, %eax
jne 0x350f
leaq 0x28(%rsp), %rbx
movl (%rbx), %esi
movq 0x8(%rbx), %rdx
leaq 0x18(%rsp), %r14
movl (%r14), %ecx
movq 0x8(%r14), %r8
leaq 0xc063(%rip), %rdi      # 0xf237
xorl %eax, %eax
callq 0x2130
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0xc, %ecx
callq 0x6858
testl %eax, %eax
jne 0x3516
movl 0x28(%rsp), %esi
movq 0x30(%rsp), %rdx
movl 0x18(%rsp), %ecx
movq 0x20(%rsp), %r8
leaq 0xc026(%rip), %rdi      # 0xf237
xorl %eax, %eax
callq 0x2130
movq 0x40(%rsp), %rdi
callq 0x9d63
leaq 0x8(%rsp), %rbx
movq (%rbx), %rdi
callq 0x40a1
leaq 0xc144(%rip), %rdi      # 0xf37a
callq 0x20a0
movq 0x38(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x3a2e
testl %eax, %eax
jne 0x351d
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x48(%rsp), %rdx
callq 0x9bb4
testl %eax, %eax
jne 0x3524
movl $0x32, %ebp
leaq 0x28(%rsp), %rbx
leaq 0x18(%rsp), %r14
leaq 0xbf4f(%rip), %r15      # 0xf1d4
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x8, %ecx
callq 0x6858
testl %eax, %eax
jne 0x32e3
movq 0x30(%rsp), %rcx
movl 0x28(%rsp), %edx
movq 0x20(%rsp), %r8
movl 0x18(%rsp), %r9d
movq %r8, (%rsp)
movq %r15, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x9dc7
testl %eax, %eax
jne 0x347c
decl %ebp
jne 0x3285
jmp 0x32ee
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x3483
leaq 0xc09a(%rip), %rdi      # 0xf38f
callq 0x20a0
movl $0x21, %ebp
leaq 0x28(%rsp), %rbx
leaq 0x18(%rsp), %r14
leaq 0xbec4(%rip), %r15      # 0xf1d4
xorl %ecx, %ecx
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x6858
testl %eax, %eax
jne 0x3355
movq 0x30(%rsp), %rcx
movl 0x28(%rsp), %edx
movq 0x20(%rsp), %r8
movl 0x18(%rsp), %r9d
movq %r8, (%rsp)
movq %r15, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
movl $0x8, %ecx
decl %ebp
jne 0x3312
jmp 0x3360
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x348a
movq 0x48(%rsp), %rdi
callq 0x9d63
movq 0x8(%rsp), %rdi
callq 0x40c7
testl %eax, %eax
jne 0x352b
leaq 0xc025(%rip), %rdi      # 0xf3a8
callq 0x20a0
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a2e
testl %eax, %eax
jne 0x3532
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0x9bb4
testl %eax, %eax
jne 0x3539
movl $0x21, %ebp
leaq 0x28(%rsp), %rbx
leaq 0x18(%rsp), %r14
leaq 0xbe00(%rip), %r15      # 0xf1d4
xorl %ecx, %ecx
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x6858
testl %eax, %eax
jne 0x3419
movq 0x30(%rsp), %rcx
movl 0x28(%rsp), %edx
movq 0x20(%rsp), %r8
movl 0x18(%rsp), %r9d
movq %r8, (%rsp)
movq %r15, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
movl $0x8, %ecx
decl %ebp
jne 0x33d6
jmp 0x3420
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x3491
movq 0x40(%rsp), %rdi
callq 0x9d63
movq 0x8(%rsp), %rdi
callq 0x40a1
movq 0x38(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0xa335
movq 0x38(%rsp), %rdi
callq 0xd74c
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x2b20
movl %eax, %edi
callq 0x2aac
movl %eax, %edi
callq 0x2a72
movl %eax, %edi
callq 0x2684
movl %eax, %edi
callq 0x28ce
movl %eax, %edi
callq 0x2a36
movl %eax, %edi
callq 0x29fa
movl %eax, %edi
callq 0x29be
movl %eax, %edi
callq 0x2b5a
movl %eax, %edi
callq 0x26be
movl %eax, %edi
callq 0x2ae6
movl %eax, %edi
callq 0x2440
movl %eax, %edi
callq 0x247a
movl %eax, %edi
callq 0x24b4
movl %eax, %edi
callq 0x24ee
movl %eax, %edi
callq 0x2528
movl %eax, %edi
callq 0x2562
movl %eax, %edi
callq 0x259c
movl %eax, %edi
callq 0x25d6
movl %eax, %edi
callq 0x2610
movl %eax, %edi
callq 0x264a
movl %eax, %edi
callq 0x26f8
movl %eax, %edi
callq 0x2732
movl %eax, %edi
callq 0x276c
movl %eax, %edi
callq 0x27a6
movl %eax, %edi
callq 0x27e0
movl %eax, %edi
callq 0x281a
movl %eax, %edi
callq 0x2856
movl %eax, %edi
callq 0x2892
movl %eax, %edi
callq 0x290a
movl %eax, %edi
callq 0x2946
movl %eax, %edi
callq 0x2982