// File: /workspace/github_cpp_makefile_star2_O2/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mtest3.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];
	char kval[sizeof(int)];

	srand(time(NULL));

	memset(sval, 0, sizeof(sval));

	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_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, "id2", MDB_CREATE|MDB_DUPSORT, &dbi));

	key.mv_size = sizeof(int);
	key.mv_data = kval;
	data.mv_size = sizeof(sval);
	data.mv_data = sval;

	printf("Adding %d values\n", count);
	for (i=0;i<count;i++) {
		if (!(i & 0x0f))
			sprintf(kval, "%03x", values[i]);
		sprintf(sval, "%03x %d foo bar", values[i], values[i]);
		if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA)))
			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;

	for (i= count - 1; i > -1; i-= (rand()%5)) {
		j++;
		txn=NULL;
		E(mdb_txn_begin(env, NULL, 0, &txn));
		sprintf(kval, "%03x", values[i & ~0x0f]);
		sprintf(sval, "%03x %d foo bar", values[i], values[i]);
		key.mv_size = sizeof(int);
		key.mv_data = kval;
		data.mv_size = sizeof(sval);
		data.mv_data = sval;
		if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
			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
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x2250
movl %eax, %edi
callq 0x21d0
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
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, %r12d
cmovgl %ebp, %r12d
movl $0x400, %r13d           # imm = 0x400
cmpq %r15, %r12
je 0x25b9
callq 0x2420
cltd
idivl %r13d
movl %edx, (%r14,%r15,4)
incq %r15
jmp 0x25a2
leaq 0x10(%rsp), %rdi
callq 0xb77f
testl %eax, %eax
jne 0x2b7b
movq 0x10(%rsp), %rdi
movl $0xa00000, %esi         # imm = 0xA00000
callq 0xb7e0
testl %eax, %eax
jne 0x2ba5
movq 0x10(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0xb92f
testl %eax, %eax
jne 0x2bcf
movq 0x10(%rsp), %rdi
leaq 0xba6c(%rip), %rsi      # 0xe06f
movl $0x10001, %edx          # imm = 0x10001
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xb973
testl %eax, %eax
jne 0x2bfc
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x3257
testl %eax, %eax
jne 0x2c29
movq 0x8(%rsp), %rdi
leaq 0xba96(%rip), %rsi      # 0xe0d7
leaq 0x1c(%rsp), %rcx
movl $0x40004, %edx          # imm = 0x40004
callq 0x8fc7
testl %eax, %eax
jne 0x2c56
leaq 0x38(%rsp), %rcx
movq $0x4, (%rcx)
leaq 0x4c(%rsp), %rax
movq %rax, 0x8(%rcx)
leaq 0x28(%rsp), %rcx
movq $0x20, (%rcx)
leaq 0x50(%rsp), %rax
movq %rax, 0x8(%rcx)
leaq 0xba89(%rip), %rdi      # 0xe112
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %r15, %r12
je 0x2708
movl (%r14,%r15,4), %r13d
testb $0xf, %r15b
jne 0x26bc
leaq 0x4c(%rsp), %rdi
leaq 0xba72(%rip), %rsi      # 0xe124
movl %r13d, %edx
xorl %eax, %eax
callq 0x2380
leaq 0x50(%rsp), %rdi
leaq 0xba61(%rip), %rsi      # 0xe129
movl %r13d, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2380
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x38(%rsp), %rdx
leaq 0x28(%rsp), %rcx
pushq $0x20
popq %r8
callq 0x8f2c
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
je 0x2701
testl %eax, %eax
je 0x2703
jmp 0x2aec
incl %ebp
incq %r15
jmp 0x2697
testl %ebp, %ebp
je 0x271c
leaq 0xba54(%rip), %rdi      # 0xe167
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
movq 0x8(%rsp), %rdi
callq 0x3872
testl %eax, %eax
jne 0x2c83
movq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xcb08
testl %eax, %eax
jne 0x2cb0
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x3257
testl %eax, %eax
jne 0x2cdd
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x8c0c
testl %eax, %eax
jne 0x2d0a
leaq 0x38(%rsp), %r15
leaq 0x28(%rsp), %r12
pushq $0x8
popq %rbp
leaq 0xba66(%rip), %r13      # 0xe1f8
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x5bd7
testl %eax, %eax
jne 0x27ce
movq 0x40(%rsp), %rcx
movl 0x38(%rsp), %edx
movq 0x30(%rsp), %r8
movl 0x28(%rsp), %r9d
movq %r8, (%rsp)
movq %r13, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
jmp 0x2792
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2a3b
movq 0x20(%rsp), %rdi
callq 0x8db6
leaq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x384c
addl $0x3f, %ebx
leaq 0x28(%rsp), %r13
xorl %ebp, %ebp
testl %ebx, %ebx
js 0x28d5
andq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x3257
testl %eax, %eax
jne 0x2a68
movl %ebx, %eax
andl $0x7ffffff0, %eax       # imm = 0x7FFFFFF0
movl (%r14,%rax,4), %edx
leaq 0x4c(%rsp), %r15
movq %r15, %rdi
leaq 0xb8e7(%rip), %rsi      # 0xe124
xorl %eax, %eax
callq 0x2380
movl %ebx, %eax
movl (%r14,%rax,4), %ecx
leaq 0x50(%rsp), %r12
movq %r12, %rdi
leaq 0xb8d0(%rip), %rsi      # 0xe129
movl %ecx, %edx
xorl %eax, %eax
callq 0x2380
movq $0x4, 0x38(%rsp)
movq %r15, 0x40(%rsp)
movq $0x20, 0x28(%rsp)
movq %r12, 0x30(%rsp)
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x38(%rsp), %rdx
movq %r13, %rcx
callq 0x8e1a
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
je 0x28b9
testl %eax, %eax
jne 0x2b16
movq 0x8(%rsp), %rdi
callq 0x3872
testl %eax, %eax
jne 0x2b40
incl %ebp
jmp 0x28c3
movq 0x8(%rsp), %rdi
callq 0x384c
callq 0x2420
cltd
pushq $0x5
popq %rcx
idivl %ecx
subl %edx, %ebx
jmp 0x27fa
movq %r14, %rdi
callq 0x2030
leaq 0xb95f(%rip), %rdi      # 0xe243
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
movq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xcb08
testl %eax, %eax
jne 0x2d37
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x3257
testl %eax, %eax
jne 0x2d64
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x20(%rsp), %rdx
callq 0x8c0c
testl %eax, %eax
jne 0x2d91
leaq 0xb929(%rip), %rdi      # 0xe26d
callq 0x20a0
leaq 0x38(%rsp), %rbx
leaq 0x28(%rsp), %r14
pushq $0x8
popq %rbp
leaq 0xb8f9(%rip), %r15      # 0xe256
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x5bd7
testl %eax, %eax
jne 0x2991
movl 0x38(%rsp), %esi
movq 0x40(%rsp), %rdx
movl 0x28(%rsp), %ecx
movq 0x30(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x295d
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2a95
leaq 0xb8d6(%rip), %rdi      # 0xe279
callq 0x20a0
leaq 0x38(%rsp), %rbx
leaq 0x28(%rsp), %r14
pushq $0xc
popq %rbp
leaq 0xb89a(%rip), %r15      # 0xe256
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x5bd7
testl %eax, %eax
jne 0x29f0
movl 0x38(%rsp), %esi
movq 0x40(%rsp), %rdx
movl 0x28(%rsp), %ecx
movq 0x30(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x29bc
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2ac2
movq 0x20(%rsp), %rdi
callq 0x8db6
movq 0x8(%rsp), %rdi
callq 0x384c
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x931e
movq 0x10(%rsp), %rdi
callq 0xc455
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x105b6(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb5b1(%rip), %rsi      # 0xe004
leaq 0xb5b9(%rip), %rdx      # 0xe013
leaq 0xb7b4(%rip), %r8       # 0xe215
pushq $0x54
jmp 0x2b68
movq 0x10589(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb584(%rip), %rsi      # 0xe004
leaq 0xb58c(%rip), %rdx      # 0xe013
leaq 0xb627(%rip), %r8       # 0xe0b5
pushq $0x5d
jmp 0x2b68
movq 0x1055c(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb557(%rip), %rsi      # 0xe004
leaq 0xb55f(%rip), %rdx      # 0xe013
leaq 0xb75a(%rip), %r8       # 0xe215
pushq $0x77
jmp 0x2b68
movq 0x1052f(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb52a(%rip), %rsi      # 0xe004
leaq 0xb532(%rip), %rdx      # 0xe013
leaq 0xb72d(%rip), %r8       # 0xe215
pushq $0x7e
jmp 0x2b68
movq 0x10505(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb500(%rip), %rsi      # 0xe004
leaq 0xb508(%rip), %rdx      # 0xe013
leaq 0xb627(%rip), %r8       # 0xe139
pushq $0x46
jmp 0x2b68
movq 0x104db(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb4d6(%rip), %rsi      # 0xe004
leaq 0xb4de(%rip), %rdx      # 0xe013
leaq 0xb6e8(%rip), %r8       # 0xe224
pushq $0x64
jmp 0x2b68
movq 0x104b1(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb4ac(%rip), %rsi      # 0xe004
leaq 0xb4b4(%rip), %rdx      # 0xe013
leaq 0xb618(%rip), %r8       # 0xe17e
pushq $0x68
popq %rcx
movq %rbx, %rdi
movq %rax, %r9
xorl %eax, %eax
callq 0x2220
callq 0x2040
movq 0x10476(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb471(%rip), %rsi      # 0xe004
leaq 0xb479(%rip), %rdx      # 0xe013
leaq 0xb47b(%rip), %r8       # 0xe01c
pushq $0x34
jmp 0x2b68
movq 0x1044c(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb447(%rip), %rsi      # 0xe004
leaq 0xb44f(%rip), %rdx      # 0xe013
leaq 0xb466(%rip), %r8       # 0xe031
pushq $0x35
jmp 0x2b68
movq 0x10422(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb41d(%rip), %rsi      # 0xe004
leaq 0xb425(%rip), %rdx      # 0xe013
leaq 0xb45f(%rip), %r8       # 0xe054
pushq $0x36
jmp 0x2b68
movq 0x103f5(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb3f0(%rip), %rsi      # 0xe004
leaq 0xb3f8(%rip), %rdx      # 0xe013
leaq 0xb456(%rip), %r8       # 0xe078
pushq $0x37
jmp 0x2b68
movq 0x103c8(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb3c3(%rip), %rsi      # 0xe004
leaq 0xb3cb(%rip), %rdx      # 0xe013
leaq 0xb466(%rip), %r8       # 0xe0b5
pushq $0x39
jmp 0x2b68
movq 0x1039b(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb396(%rip), %rsi      # 0xe004
leaq 0xb39e(%rip), %rdx      # 0xe013
leaq 0xb45f(%rip), %r8       # 0xe0db
pushq $0x3a
jmp 0x2b68
movq 0x1036e(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb369(%rip), %rsi      # 0xe004
leaq 0xb371(%rip), %rdx      # 0xe013
leaq 0xb4d5(%rip), %r8       # 0xe17e
pushq $0x4a
jmp 0x2b68
movq 0x10341(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb33c(%rip), %rsi      # 0xe004
leaq 0xb344(%rip), %rdx      # 0xe013
leaq 0xb4bc(%rip), %r8       # 0xe192
pushq $0x4b
jmp 0x2b68
movq 0x10314(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb30f(%rip), %rsi      # 0xe004
leaq 0xb317(%rip), %rdx      # 0xe013
leaq 0xb4a7(%rip), %r8       # 0xe1aa
pushq $0x4d
jmp 0x2b68
movq 0x102e7(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb2e2(%rip), %rsi      # 0xe004
leaq 0xb2ea(%rip), %rdx      # 0xe013
leaq 0xb4a5(%rip), %r8       # 0xe1d5
pushq $0x4e
jmp 0x2b68
movq 0x102ba(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb2b5(%rip), %rsi      # 0xe004
leaq 0xb2bd(%rip), %rdx      # 0xe013
leaq 0xb435(%rip), %r8       # 0xe192
pushq $0x6e
jmp 0x2b68
movq 0x1028d(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb288(%rip), %rsi      # 0xe004
leaq 0xb290(%rip), %rdx      # 0xe013
leaq 0xb420(%rip), %r8       # 0xe1aa
pushq $0x6f
jmp 0x2b68
movq 0x10260(%rip), %rcx     # 0x12ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2dc0
leaq 0xb25b(%rip), %rsi      # 0xe004
leaq 0xb263(%rip), %rdx      # 0xe013
leaq 0xb41e(%rip), %r8       # 0xe1d5
pushq $0x70
jmp 0x2b68
nop