// File: /workspace/github_cpp_makefile_star2_O2/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mtest2.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;
	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_set_maxdbs(env, 4));
	E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));

	E(mdb_txn_begin(env, NULL, 0, &txn));
	E(mdb_dbi_open(txn, "id1", MDB_CREATE, &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]);
		data.mv_size = sizeof(sval);
		data.mv_data = sval;
		if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE)))
			j++;
	}
	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 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");
	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 %r15d, %r15d
xorl %edi, %edi
callq 0x2250
movl %eax, %edi
callq 0x21d0
callq 0x2420
movl $0x180, %ecx            # imm = 0x180
cltd
idivl %ecx
movl %edx, %ebx
leal 0x40(%rbx), %ebp
movslq %edx, %rax
leaq 0x100(,%rax,4), %rdi
callq 0x2280
movq %rax, %r14
testl %ebp, %ebp
movl $0x0, %r13d
cmovgl %ebp, %r13d
movl $0x400, %r12d           # imm = 0x400
cmpq %r15, %r13
je 0x25b9
callq 0x2420
cltd
idivl %r12d
movl %edx, (%r14,%r15,4)
incq %r15
jmp 0x25a2
leaq 0x18(%rsp), %rdi
callq 0xb767
testl %eax, %eax
jne 0x2b35
movq 0x18(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0xb92b
testl %eax, %eax
jne 0x2b5f
movq 0x18(%rsp), %rdi
movl $0xa00000, %esi         # imm = 0xA00000
callq 0xb7c8
testl %eax, %eax
jne 0x2b89
movq 0x18(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0xb917
testl %eax, %eax
jne 0x2bb6
movq 0x18(%rsp), %rdi
leaq 0xba76(%rip), %rsi      # 0xe08e
movl $0x10001, %edx          # imm = 0x10001
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xb95b
testl %eax, %eax
jne 0x2be3
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x323f
testl %eax, %eax
jne 0x2c10
movq 0x10(%rsp), %rdi
leaq 0xbaa0(%rip), %rsi      # 0xe0f6
leaq 0x24(%rsp), %rcx
movl $0x40000, %edx          # imm = 0x40000
callq 0x8faf
testl %eax, %eax
jne 0x2c3d
leaq 0x40(%rsp), %rcx
movq $0x4, (%rcx)
leaq 0x50(%rsp), %rax
movq %rax, 0x8(%rcx)
leaq 0xba9c(%rip), %rdi      # 0xe125
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %r15, %r13
je 0x26f9
movl (%r14,%r15,4), %ecx
leaq 0x50(%rsp), %r12
movq %r12, %rdi
leaq 0xba88(%rip), %rsi      # 0xe137
movl %ecx, %edx
xorl %eax, %eax
callq 0x2380
movq $0x20, 0x30(%rsp)
movq %r12, 0x38(%rsp)
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %esi
leaq 0x40(%rsp), %rdx
leaq 0x30(%rsp), %rcx
pushq $0x10
popq %r8
callq 0x8f14
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
je 0x26f2
testl %eax, %eax
je 0x26f4
jmp 0x2aa6
incl %ebp
incq %r15
jmp 0x2697
testl %ebp, %ebp
je 0x270d
leaq 0xba73(%rip), %rdi      # 0xe177
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
movq 0x10(%rsp), %rdi
callq 0x385a
testl %eax, %eax
jne 0x2c6a
movq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xcaf0
testl %eax, %eax
jne 0x2c97
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x323f
testl %eax, %eax
jne 0x2cc4
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %esi
leaq 0x28(%rsp), %rdx
callq 0x8bf4
testl %eax, %eax
jne 0x2cf1
leaq 0x40(%rsp), %r15
leaq 0x30(%rsp), %r12
pushq $0x8
popq %rbp
leaq 0xba85(%rip), %r13      # 0xe208
movq 0x28(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x5bbf
testl %eax, %eax
jne 0x27bf
movq 0x48(%rsp), %rcx
movl 0x40(%rsp), %edx
movq 0x38(%rsp), %r8
movl 0x30(%rsp), %r9d
movq %r8, (%rsp)
movq %r13, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
jmp 0x2783
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x29f5
movq 0x28(%rsp), %rdi
callq 0x8d9e
leaq 0x10(%rsp), %rax
movq (%rax), %rdi
callq 0x3834
leaq 0x40(%rsp), %r13
leaq 0x50(%rsp), %rax
movq %rax, 0x8(%r13)
addl $0x3f, %ebx
leaq 0xba3b(%rip), %r12      # 0xe234
pushq $0x5
popq %r15
xorl %ebp, %ebp
testl %ebx, %ebx
js 0x288f
andq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0x323f
testl %eax, %eax
jne 0x2a22
movl %ebx, %eax
movl (%r14,%rax,4), %edx
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x2380
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x8e02
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
je 0x2875
testl %eax, %eax
jne 0x2ad0
movq 0x10(%rsp), %rdi
callq 0x385a
testl %eax, %eax
jne 0x2afa
incl %ebp
jmp 0x287f
movq 0x10(%rsp), %rdi
callq 0x3834
callq 0x2420
cltd
idivl %r15d
subl %edx, %ebx
jmp 0x27ff
movq %r14, %rdi
callq 0x2030
leaq 0xb9ba(%rip), %rdi      # 0xe258
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
movq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xcaf0
testl %eax, %eax
jne 0x2d1e
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x323f
testl %eax, %eax
jne 0x2d4b
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %esi
leaq 0x28(%rsp), %rdx
callq 0x8bf4
testl %eax, %eax
jne 0x2d78
leaq 0xb984(%rip), %rdi      # 0xe282
callq 0x20a0
leaq 0x40(%rsp), %rbx
leaq 0x30(%rsp), %r14
pushq $0x8
popq %rbp
leaq 0xb954(%rip), %r15      # 0xe26b
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x5bbf
testl %eax, %eax
jne 0x294b
movl 0x40(%rsp), %esi
movq 0x48(%rsp), %rdx
movl 0x30(%rsp), %ecx
movq 0x38(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x2917
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2a4f
leaq 0xb931(%rip), %rdi      # 0xe28e
callq 0x20a0
leaq 0x40(%rsp), %rbx
leaq 0x30(%rsp), %r14
pushq $0xc
popq %rbp
leaq 0xb8f5(%rip), %r15      # 0xe26b
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x5bbf
testl %eax, %eax
jne 0x29aa
movl 0x40(%rsp), %esi
movq 0x48(%rsp), %rdx
movl 0x30(%rsp), %ecx
movq 0x38(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x2976
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2a7c
movq 0x28(%rsp), %rdi
callq 0x8d9e
movq 0x10(%rsp), %rdi
callq 0x3834
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x9306
movq 0x18(%rsp), %rdi
callq 0xc43d
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x105fc(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb5f7(%rip), %rsi      # 0xe004
leaq 0xb5ff(%rip), %rdx      # 0xe013
leaq 0xb80a(%rip), %r8       # 0xe225
pushq $0x50
jmp 0x2b22
movq 0x105cf(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb5ca(%rip), %rsi      # 0xe004
leaq 0xb5d2(%rip), %rdx      # 0xe013
leaq 0xb68c(%rip), %r8       # 0xe0d4
pushq $0x59
jmp 0x2b22
movq 0x105a2(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb59d(%rip), %rsi      # 0xe004
leaq 0xb5a5(%rip), %rdx      # 0xe013
leaq 0xb7b0(%rip), %r8       # 0xe225
pushq $0x6e
jmp 0x2b22
movq 0x10575(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb570(%rip), %rsi      # 0xe004
leaq 0xb578(%rip), %rdx      # 0xe013
leaq 0xb783(%rip), %r8       # 0xe225
pushq $0x75
jmp 0x2b22
movq 0x1054b(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb546(%rip), %rsi      # 0xe004
leaq 0xb54e(%rip), %rdx      # 0xe013
leaq 0xb67b(%rip), %r8       # 0xe147
pushq $0x42
jmp 0x2b22
movq 0x10521(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb51c(%rip), %rsi      # 0xe004
leaq 0xb524(%rip), %rdx      # 0xe013
leaq 0xb744(%rip), %r8       # 0xe23a
pushq $0x5b
jmp 0x2b22
movq 0x104f7(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb4f2(%rip), %rsi      # 0xe004
leaq 0xb4fa(%rip), %rdx      # 0xe013
leaq 0xb66e(%rip), %r8       # 0xe18e
pushq $0x5f
popq %rcx
movq %rbx, %rdi
movq %rax, %r9
xorl %eax, %eax
callq 0x2220
callq 0x2040
movq 0x104bc(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb4b7(%rip), %rsi      # 0xe004
leaq 0xb4bf(%rip), %rdx      # 0xe013
leaq 0xb4c1(%rip), %r8       # 0xe01c
pushq $0x31
jmp 0x2b22
movq 0x10492(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb48d(%rip), %rsi      # 0xe004
leaq 0xb495(%rip), %rdx      # 0xe013
leaq 0xb4ac(%rip), %r8       # 0xe031
pushq $0x32
jmp 0x2b22
movq 0x10468(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb463(%rip), %rsi      # 0xe004
leaq 0xb46b(%rip), %rdx      # 0xe013
leaq 0xb4a1(%rip), %r8       # 0xe050
pushq $0x33
jmp 0x2b22
movq 0x1043b(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb436(%rip), %rsi      # 0xe004
leaq 0xb43e(%rip), %rdx      # 0xe013
leaq 0xb497(%rip), %r8       # 0xe073
pushq $0x34
jmp 0x2b22
movq 0x1040e(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb409(%rip), %rsi      # 0xe004
leaq 0xb411(%rip), %rdx      # 0xe013
leaq 0xb48e(%rip), %r8       # 0xe097
pushq $0x35
jmp 0x2b22
movq 0x103e1(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb3dc(%rip), %rsi      # 0xe004
leaq 0xb3e4(%rip), %rdx      # 0xe013
leaq 0xb49e(%rip), %r8       # 0xe0d4
pushq $0x37
jmp 0x2b22
movq 0x103b4(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb3af(%rip), %rsi      # 0xe004
leaq 0xb3b7(%rip), %rdx      # 0xe013
leaq 0xb497(%rip), %r8       # 0xe0fa
pushq $0x38
jmp 0x2b22
movq 0x10387(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb382(%rip), %rsi      # 0xe004
leaq 0xb38a(%rip), %rdx      # 0xe013
leaq 0xb4fe(%rip), %r8       # 0xe18e
pushq $0x46
jmp 0x2b22
movq 0x1035a(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb355(%rip), %rsi      # 0xe004
leaq 0xb35d(%rip), %rdx      # 0xe013
leaq 0xb4e5(%rip), %r8       # 0xe1a2
pushq $0x47
jmp 0x2b22
movq 0x1032d(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb328(%rip), %rsi      # 0xe004
leaq 0xb330(%rip), %rdx      # 0xe013
leaq 0xb4d0(%rip), %r8       # 0xe1ba
pushq $0x49
jmp 0x2b22
movq 0x10300(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb2fb(%rip), %rsi      # 0xe004
leaq 0xb303(%rip), %rdx      # 0xe013
leaq 0xb4ce(%rip), %r8       # 0xe1e5
pushq $0x4a
jmp 0x2b22
movq 0x102d3(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb2ce(%rip), %rsi      # 0xe004
leaq 0xb2d6(%rip), %rdx      # 0xe013
leaq 0xb45e(%rip), %r8       # 0xe1a2
pushq $0x65
jmp 0x2b22
movq 0x102a6(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb2a1(%rip), %rsi      # 0xe004
leaq 0xb2a9(%rip), %rdx      # 0xe013
leaq 0xb449(%rip), %r8       # 0xe1ba
pushq $0x66
jmp 0x2b22
movq 0x10279(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2da8
leaq 0xb274(%rip), %rsi      # 0xe004
leaq 0xb27c(%rip), %rdx      # 0xe013
leaq 0xb447(%rip), %r8       # 0xe1e5
pushq $0x67
jmp 0x2b22
nopl (%rax)