// File: /workspace/github_cpp_makefile_star2_O1/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 %edi, %edi
callq 0x2250
movl %eax, %edi
callq 0x21d0
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
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, %r13d
subl %ecx, %r13d
negl %ecx
leal (%rax,%rcx), %ebp
addl $0x40, %ebp
movslq %r13d, %r14
leaq 0x100(,%r14,4), %rdi
callq 0x2280
movq %rax, %rbx
cmpl $-0x3f, %r14d
jl 0x2a5a
movl %ebp, %r14d
xorl %r15d, %r15d
callq 0x2410
leal 0x3ff(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
subl %ecx, %eax
movl %eax, (%rbx,%r15,4)
incq %r15
cmpq %r15, %r14
jne 0x2a36
leaq 0x10(%rsp), %rdi
callq 0xc473
testl %eax, %eax
jne 0x2f32
movq 0x10(%rsp), %rdi
movl $0xa00000, %esi         # imm = 0xA00000
callq 0xc4e0
testl %eax, %eax
jne 0x2f39
movq 0x10(%rsp), %rdi
movl $0x4, %esi
callq 0xc644
testl %eax, %eax
jne 0x2f40
movq 0x10(%rsp), %rdi
leaq 0xc5c9(%rip), %rsi      # 0xf06f
movl $0x10001, %edx          # imm = 0x10001
movl $0x1b4, %ecx            # imm = 0x1B4
callq 0xc68d
testl %eax, %eax
jne 0x2f47
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
callq 0x347e
testl %eax, %eax
jne 0x2f4e
movq 0x8(%rsp), %rdi
leaq 0xc5f3(%rip), %rsi      # 0xf0d7
leaq 0x1c(%rsp), %rcx
movl $0x40004, %edx          # imm = 0x40004
callq 0x99d7
testl %eax, %eax
jne 0x2f55
movq $0x4, 0x30(%rsp)
leaq 0x4c(%rsp), %rax
movq %rax, 0x38(%rsp)
movq $0x20, 0x20(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0xc5ea(%rip), %rdi      # 0xf112
xorl %r14d, %r14d
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
cmpl $-0x3f, %r13d
jl 0x2bb4
movl %ebp, %ebp
leaq 0x20(%rsp), %r12
xorl %r15d, %r15d
xorl %r14d, %r14d
testb $0xf, %r15b
jne 0x2b64
movl (%rbx,%r15,4), %edx
leaq 0x4c(%rsp), %rdi
leaq 0xc5c7(%rip), %rsi      # 0xf124
xorl %eax, %eax
callq 0x2370
movl (%rbx,%r15,4), %ecx
leaq 0x50(%rsp), %rdi
leaq 0xc5b5(%rip), %rsi      # 0xf129
movl %ecx, %edx
xorl %eax, %eax
callq 0x2370
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x30(%rsp), %rdx
movq %r12, %rcx
movl $0x20, %r8d
callq 0x9938
cmpl $0xffff87b1, %eax       # imm = 0xFFFF87B1
je 0x2ba9
testl %eax, %eax
je 0x2bac
jmp 0x2f1d
incl %r14d
incq %r15
cmpq %r15, %rbp
jne 0x2b47
testl %r14d, %r14d
je 0x2bca
leaq 0xc5a7(%rip), %rdi      # 0xf167
movl %r14d, %esi
xorl %eax, %eax
callq 0x2130
movq 0x8(%rsp), %rdi
callq 0x3b17
testl %eax, %eax
jne 0x2f5c
movq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xd8a5
testl %eax, %eax
jne 0x2f63
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x347e
testl %eax, %eax
jne 0x2f6a
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0x9604
testl %eax, %eax
jne 0x2f71
leaq 0x30(%rsp), %r14
leaq 0x20(%rsp), %r15
leaq 0xc5bb(%rip), %r12      # 0xf1f8
movq 0x40(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movl $0x8, %ecx
callq 0x62a8
testl %eax, %eax
jne 0x2c7c
movq 0x38(%rsp), %rcx
movl 0x30(%rsp), %edx
movq 0x28(%rsp), %r8
movl 0x20(%rsp), %r9d
movq %r8, (%rsp)
movq %r12, %rdi
movq %rcx, %rsi
xorl %eax, %eax
callq 0x2130
jmp 0x2c3d
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2f01
movq 0x40(%rsp), %rdi
callq 0x97b3
movq 0x8(%rsp), %rdi
callq 0x3af1
xorl %ebp, %ebp
cmpl $-0x3f, %r13d
jl 0x2d9f
addl $0x3f, %r13d
leaq 0x20(%rsp), %r12
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x347e
testl %eax, %eax
jne 0x2f16
movl %r13d, %eax
andl $0x7ffffff0, %eax       # imm = 0x7FFFFFF0
movl (%rbx,%rax,4), %edx
leaq 0x4c(%rsp), %r14
movq %r14, %rdi
leaq 0xc434(%rip), %rsi      # 0xf124
xorl %eax, %eax
callq 0x2370
movl %r13d, %eax
movl (%rbx,%rax,4), %ecx
leaq 0x50(%rsp), %r15
movq %r15, %rdi
leaq 0xc41d(%rip), %rsi      # 0xf129
movl %ecx, %edx
xorl %eax, %eax
callq 0x2370
movq $0x4, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movq $0x20, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x30(%rsp), %rdx
movq %r12, %rcx
callq 0x9817
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
je 0x2d6c
testl %eax, %eax
jne 0x2f2b
movq 0x8(%rsp), %rdi
callq 0x3b17
testl %eax, %eax
jne 0x2f24
incl %ebp
jmp 0x2d76
movq 0x8(%rsp), %rdi
callq 0x3af1
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, %r13d
jns 0x2cb2
movq %rbx, %rdi
callq 0x2030
leaq 0xc495(%rip), %rdi      # 0xf243
movl %ebp, %esi
xorl %eax, %eax
callq 0x2130
movq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xd8a5
testl %eax, %eax
jne 0x2f78
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x347e
testl %eax, %eax
jne 0x2f7f
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0x9604
testl %eax, %eax
jne 0x2f86
leaq 0xc45f(%rip), %rdi      # 0xf26d
callq 0x20a0
leaq 0x30(%rsp), %rbx
leaq 0x20(%rsp), %r14
leaq 0xc432(%rip), %r15      # 0xf256
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x8, %ecx
callq 0x62a8
testl %eax, %eax
jne 0x2e5b
movl 0x30(%rsp), %esi
movq 0x38(%rsp), %rdx
movl 0x20(%rsp), %ecx
movq 0x28(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x2e24
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2f08
leaq 0xc40c(%rip), %rdi      # 0xf279
callq 0x20a0
leaq 0x30(%rsp), %rbx
leaq 0x20(%rsp), %r14
leaq 0xc3d3(%rip), %r15      # 0xf256
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0xc, %ecx
callq 0x62a8
testl %eax, %eax
jne 0x2eba
movl 0x30(%rsp), %esi
movq 0x38(%rsp), %rdx
movl 0x20(%rsp), %ecx
movq 0x28(%rsp), %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x2e83
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x2f0f
movq 0x40(%rsp), %rdi
callq 0x97b3
movq 0x8(%rsp), %rdi
callq 0x3af1
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x9d85
movq 0x10(%rsp), %rdi
callq 0xd19c
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x2854
movl %eax, %edi
callq 0x27e0
movl %eax, %edi
callq 0x27a6
movl %eax, %edi
callq 0x2684
movl %eax, %edi
callq 0x288e
movl %eax, %edi
callq 0x26be
movl %eax, %edi
callq 0x281a
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
nopl (%rax)