// File: /workspace/github_c_makefile_star2_O3/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 0x259c
callq 0x5258
cmpl $0x2, %ebx
jne 0x25d0
movq 0x8(%r14), %rdi
callq 0x4254
testq %rax, %rax
jne 0x25f4
callq 0x2090
cmpl $0x0, (%rax)
movq 0x8(%r14), %rsi
jne 0x261f
leaq 0x8a63(%rip), %rdi      # 0xb027
xorl %eax, %eax
callq 0x53f7
jmp 0x294e
movq 0xea21(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8a23(%rip), %rsi      # 0xb004
leaq 0x8a32(%rip), %rdx      # 0xb01a
xorl %eax, %eax
callq 0x21b0
jmp 0x294e
movq %rax, %rbx
cmpq $0x0, (%rax)
jne 0x263b
movq 0x8(%r14), %rsi
leaq 0x8a42(%rip), %rdi      # 0xb04a
xorl %eax, %eax
callq 0x53f7
callq 0x2090
movl $0x0, (%rax)
jmp 0x294e
movq %rax, %rbx
leaq 0x89fe(%rip), %rdi      # 0xb027
xorl %eax, %eax
callq 0x52d8
movl $0x0, (%rbx)
jmp 0x294e
movq %rbx, %rdi
callq 0x4b6c
cmpl $-0x1, %eax
je 0x294e
movl %eax, %edi
callq 0x6b18
testq %rax, %rax
jne 0x2672
callq 0x2090
cmpl $0x0, (%rax)
jne 0x28c5
leaq 0x89f7(%rip), %rdi      # 0xb064
jmp 0x2927
movq %rax, %r15
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x21e0
movq %r14, %rdi
callq 0x2290
leaq 0x89f4(%rip), %rdx      # 0xb085
leaq 0x10(%rsp), %r14
movl $0x14, %esi
movq %r14, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x89de(%rip), %rdi      # 0xb08b
xorl %r12d, %r12d
movq %r14, %rsi
xorl %eax, %eax
callq 0x53f7
callq 0x2090
movq %rax, %r14
movl $0x0, (%rax)
movl $0x3e8, %edx            # imm = 0x3E8
movq %r15, %rdi
movq %r12, %rsi
callq 0x2958
testl %eax, %eax
jne 0x28db
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x186a0, %edx          # imm = 0x186A0
movq %r15, %rdi
callq 0x2958
testl %eax, %eax
jne 0x28ea
addq $0x3e8, %r12            # imm = 0x3E8
cmpq $0x2710, %r12           # imm = 0x2710
jne 0x26c8
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21e0
movq %r13, %rdi
callq 0x2290
leaq 0x895f(%rip), %rdx      # 0xb085
leaq 0x10(%rsp), %r12
movl $0x14, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x8998(%rip), %rdi      # 0xb0da
xorl %ebp, %ebp
movq %r12, %rsi
xorl %eax, %eax
callq 0x53f7
movl %ebp, (%r14)
movl $0x708, %edi            # imm = 0x708
callq 0x2330
movq %r13, %rdi
callq 0x21e0
movq %r13, %rdi
callq 0x2290
movl $0x14, %esi
movq %r12, %rdi
leaq 0x890b(%rip), %rdx      # 0xb085
movq %rax, %rcx
callq 0x2270
leaq 0x895e(%rip), %rdi      # 0xb0e7
movq %r12, %rsi
xorl %eax, %eax
callq 0x53f7
movl %ebp, (%r14)
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x186a0, %edx          # imm = 0x186A0
movq %r15, %rdi
callq 0x2a7d
testl %eax, %eax
jne 0x290b
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21e0
movq %r13, %rdi
callq 0x2290
leaq 0x88b9(%rip), %rdx      # 0xb085
leaq 0x10(%rsp), %r12
movl $0x14, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x88f2(%rip), %rdi      # 0xb0da
movq %r12, %rsi
xorl %eax, %eax
callq 0x53f7
xorl %ebp, %ebp
movl %ebp, (%r14)
movl $0x4b0, %edi            # imm = 0x4B0
callq 0x2330
movq %r13, %rdi
callq 0x21e0
movq %r13, %rdi
callq 0x2290
movl $0x14, %esi
movq %r12, %rdi
leaq 0x8865(%rip), %rdx      # 0xb085
movq %rax, %rcx
callq 0x2270
leaq 0x88fb(%rip), %rdi      # 0xb12a
movq %r12, %rsi
xorl %eax, %eax
callq 0x53f7
movl %ebp, (%r14)
movl $0x2710, %edx           # imm = 0x2710
movq %r15, %rdi
xorl %esi, %esi
callq 0x2a7d
testl %eax, %eax
jne 0x291a
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x21e0
movq %r12, %rdi
callq 0x2290
leaq 0x8816(%rip), %rdx      # 0xb085
leaq 0x10(%rsp), %r12
movl $0x14, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x884f(%rip), %rdi      # 0xb0da
movq %r12, %rsi
xorl %eax, %eax
callq 0x53f7
movl $0x0, (%r14)
movl $0xa, %edi
callq 0x2330
movq %r15, %rdi
callq 0x7209
movq %r15, %rdi
callq 0x721d
movq %rbx, %rdi
callq 0x4966
xorl %edi, %edi
callq 0x22d0
movq %rax, %rbx
leaq 0x8795(%rip), %rdi      # 0xb064
xorl %eax, %eax
callq 0x52d8
jmp 0x2630
cmpl $0x0, (%r14)
jne 0x28f9
leaq 0x87c0(%rip), %rdi      # 0xb0a8
jmp 0x2927
cmpl $0x0, (%r14)
jne 0x2902
leaq 0x87ca(%rip), %rdi      # 0xb0c1
jmp 0x2927
leaq 0x87a8(%rip), %rdi      # 0xb0a8
jmp 0x2940
leaq 0x87b8(%rip), %rdi      # 0xb0c1
jmp 0x2940
cmpl $0x0, (%r14)
jne 0x2930
leaq 0x87f8(%rip), %rdi      # 0xb110
jmp 0x2927
cmpl $0x0, (%r14)
jne 0x2939
leaq 0x8825(%rip), %rdi      # 0xb14c
xorl %eax, %eax
callq 0x53f7
jmp 0x294e
leaq 0x87d9(%rip), %rdi      # 0xb110
jmp 0x2940
leaq 0x880c(%rip), %rdi      # 0xb14c
xorl %eax, %eax
callq 0x52d8
movl $0x0, (%r14)
movl $0x1, %edi
callq 0x22d0