// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/perftests/kvldsclean/main.c
// Function: main
int
main(int argc, char * argv[])
{
	struct sock_addr ** sas;
	int s;
	struct wire_requestqueue * Q;
	size_t i;
	time_t t_now;
	char datetime[20];

	WARNP_INIT;

	/* Check number of arguments. */
	if (argc != 2) {
		fprintf(stderr, "usage: test_kvlds %s\n", "<socketname>");
		exit(1);
	}

	/* Resolve the socket address and connect. */
	if ((sas = sock_resolve(argv[1])) == NULL) {
		warnp("Error resolving socket address: %s", argv[1]);
		exit(1);
	}
	if (sas[0] == NULL) {
		warn0("No addresses found for %s", argv[1]);
		exit(1);
	}
	if ((s = sock_connect(sas)) == -1)
		exit(1);

	/* Create a request queue. */
	if ((Q = wire_requestqueue_init(s)) == NULL) {
		warnp("Cannot create packet write queue");
		exit(1);
	}

	/* 10 stages of writing new keys followed by existing keys. */
	time(&t_now);
	strftime(datetime, 20, "%F %T", gmtime(&t_now));
	warn0("%s: Writing and modifying...", datetime);
	for (i = 0; i < 10; i++) {
		/* Write 1k new keys. */
		if (batch_set(Q, i * 1000, 1000)) {
			warnp("Failure writing new keys");
			exit(1);
		}

		/* Write the same 100k keys each iteration. */
		if (batch_set(Q, 1000000, 100000)) {
			warnp("Failure writing old keys");
			exit(1);
		}
	}

	/* Sleep 1800 seconds so that we can watch the cleaner kick in. */
	time(&t_now);
	strftime(datetime, 20, "%F %T", gmtime(&t_now));
	warn0("%s: ... done", datetime);
	sleep(1800);

	/* Delete the 100k repeatedly modified keys. */
	time(&t_now);
	strftime(datetime, 20, "%F %T", gmtime(&t_now));
	warn0("%s: Deleting repeatedly modified keys...", datetime);
	if (batch_delete(Q, 1000000, 100000)) {
		warnp("Failure deleting old keys");
		exit(1);
	}

	/* Sleep 1200 seconds so that we can watch the cleaner do more work. */
	time(&t_now);
	strftime(datetime, 20, "%F %T", gmtime(&t_now));
	warn0("%s: ... done", datetime);
	sleep(1200);

	/* Delete the 10 x 1k once-written keys. */
	time(&t_now);
	strftime(datetime, 20, "%F %T", gmtime(&t_now));
	warn0("%s: Deleting once-written keys...", datetime);
	if (batch_delete(Q, 0, 10000)) {
		warnp("Failure deleting new keys");
		exit(1);
	}

	/* Sleep 10 seconds so that we can see an empty tree. */
	time(&t_now);
	strftime(datetime, 20, "%F %T", gmtime(&t_now));
	warn0("%s: ... done", datetime);
	sleep(10);

	/* Free the request queue. */
	wire_requestqueue_destroy(Q);
	wire_requestqueue_free(Q);

	/* Free socket addresses. */
	sock_addr_freelist(sas);

	/* Success! */
	exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebx
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x246c
callq 0x4c50
cmpl $0x2, %ebx
jne 0x24a0
movq 0x8(%r14), %rdi
callq 0x3dd8
testq %rax, %rax
jne 0x24c4
callq 0x2090
cmpl $0x0, (%rax)
movq 0x8(%r14), %rsi
jne 0x24ec
leaq 0x6b93(%rip), %rdi      # 0x9027
xorl %eax, %eax
callq 0x4e5c
jmp 0x280e
movq 0xcb51(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x6b53(%rip), %rsi      # 0x9004
leaq 0x6b62(%rip), %rdx      # 0x901a
xorl %eax, %eax
callq 0x21a0
jmp 0x280e
movq %rax, %rbx
cmpq $0x0, (%rax)
jne 0x2505
movq 0x8(%r14), %rsi
leaq 0x6b72(%rip), %rdi      # 0x904a
xorl %eax, %eax
callq 0x4e5c
callq 0x2090
andl $0x0, (%rax)
jmp 0x280e
movq %rax, %rbx
leaq 0x6b31(%rip), %rdi      # 0x9027
xorl %eax, %eax
callq 0x4ccd
andl $0x0, (%rbx)
jmp 0x280e
movq %rbx, %rdi
callq 0x45b1
cmpl $-0x1, %eax
je 0x280e
movl %eax, %edi
callq 0x62bc
testq %rax, %rax
jne 0x253c
callq 0x2090
cmpl $0x0, (%rax)
jne 0x25e5
leaq 0x6b2d(%rip), %rdi      # 0x9064
jmp 0x27ea
movq %rax, %r15
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x21d0
movq %r14, %rdi
callq 0x2280
leaq 0x6b2a(%rip), %rdx      # 0x9085
leaq 0x10(%rsp), %r14
pushq $0x14
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
callq 0x2260
leaq 0x6b16(%rip), %rdi      # 0x908b
xorl %r12d, %r12d
movq %r14, %rsi
xorl %eax, %eax
callq 0x4e5c
callq 0x2090
movq %rax, %r14
andl $0x0, (%rax)
leaq 0x3e8(%r12), %r13
cmpq $0x2af8, %r13           # imm = 0x2AF8
je 0x25fb
movl $0x3e8, %edx            # imm = 0x3E8
movq %r15, %rdi
movq %r12, %rsi
callq 0x2816
testl %eax, %eax
jne 0x27ad
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x186a0, %edx          # imm = 0x186A0
movq %r15, %rdi
callq 0x2816
movq %r13, %r12
testl %eax, %eax
je 0x258d
cmpl $0x0, (%r14)
jne 0x27d4
leaq 0x6ae1(%rip), %rdi      # 0x90c1
jmp 0x27ea
movq %rax, %rbx
leaq 0x6a75(%rip), %rdi      # 0x9064
xorl %eax, %eax
callq 0x4ccd
jmp 0x24fd
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
callq 0x2280
leaq 0x6a6e(%rip), %rdx      # 0x9085
leaq 0x10(%rsp), %r12
pushq $0x14
popq %rbp
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rcx
callq 0x2260
leaq 0x6aa6(%rip), %rdi      # 0x90da
movq %r12, %rsi
xorl %eax, %eax
callq 0x4e5c
andl $0x0, (%r14)
movl $0x708, %edi            # imm = 0x708
callq 0x2320
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
callq 0x2280
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x6a1c(%rip), %rdx      # 0x9085
movq %rax, %rcx
callq 0x2260
leaq 0x6a6f(%rip), %rdi      # 0x90e7
movq %r12, %rsi
xorl %eax, %eax
callq 0x4e5c
andl $0x0, (%r14)
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x186a0, %edx          # imm = 0x186A0
movq %r15, %rdi
callq 0x292d
testl %eax, %eax
jne 0x27bc
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
callq 0x2280
leaq 0x69c9(%rip), %rdx      # 0x9085
leaq 0x10(%rsp), %r12
pushq $0x14
popq %rbp
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rcx
callq 0x2260
leaq 0x6a01(%rip), %rdi      # 0x90da
movq %r12, %rsi
xorl %eax, %eax
callq 0x4e5c
andl $0x0, (%r14)
movl $0x4b0, %edi            # imm = 0x4B0
callq 0x2320
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
callq 0x2280
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x6977(%rip), %rdx      # 0x9085
movq %rax, %rcx
callq 0x2260
leaq 0x6a0d(%rip), %rdi      # 0x912a
movq %r12, %rsi
xorl %eax, %eax
callq 0x4e5c
andl $0x0, (%r14)
movl $0x2710, %edx           # imm = 0x2710
movq %r15, %rdi
xorl %esi, %esi
callq 0x292d
testl %eax, %eax
jne 0x27dd
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x21d0
movq %r12, %rdi
callq 0x2280
leaq 0x6927(%rip), %rdx      # 0x9085
leaq 0x10(%rsp), %r12
pushq $0x14
popq %rsi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2260
leaq 0x6962(%rip), %rdi      # 0x90da
movq %r12, %rsi
xorl %eax, %eax
callq 0x4e5c
andl $0x0, (%r14)
pushq $0xa
popq %rdi
callq 0x2320
movq %r15, %rdi
callq 0x679f
movq %r15, %rdi
callq 0x67b3
movq %rbx, %rdi
callq 0x43d7
xorl %edi, %edi
callq 0x22c0
cmpl $0x0, (%r14)
jne 0x27cb
leaq 0x68ee(%rip), %rdi      # 0x90a8
jmp 0x27ea
cmpl $0x0, (%r14)
jne 0x27f3
leaq 0x6947(%rip), %rdi      # 0x9110
jmp 0x27ea
leaq 0x68d6(%rip), %rdi      # 0x90a8
jmp 0x2803
leaq 0x68e6(%rip), %rdi      # 0x90c1
jmp 0x2803
cmpl $0x0, (%r14)
jne 0x27fc
leaq 0x6962(%rip), %rdi      # 0x914c
xorl %eax, %eax
callq 0x4e5c
jmp 0x280e
leaq 0x6916(%rip), %rdi      # 0x9110
jmp 0x2803
leaq 0x6949(%rip), %rdi      # 0x914c
xorl %eax, %eax
callq 0x4ccd
andl $0x0, (%r14)
pushq $0x1
popq %rdi
callq 0x22c0