// File: /workspace/github_c_makefile_star2_O1/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 0x5250
cmpl $0x2, %ebx
jne 0x25d0
movq 0x8(%r14), %rdi
callq 0x4228
testq %rax, %rax
jne 0x25f4
callq 0x2090
cmpl $0x0, (%rax)
movq 0x8(%r14), %rsi
jne 0x261f
leaq 0x7a63(%rip), %rdi      # 0xa027
xorl %eax, %eax
callq 0x53ef
jmp 0x294e
movq 0xda21(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x7a23(%rip), %rsi      # 0xa004
leaq 0x7a32(%rip), %rdx      # 0xa01a
xorl %eax, %eax
callq 0x21b0
jmp 0x294e
movq %rax, %rbx
cmpq $0x0, (%rax)
jne 0x263b
movq 0x8(%r14), %rsi
leaq 0x7a42(%rip), %rdi      # 0xa04a
xorl %eax, %eax
callq 0x53ef
callq 0x2090
movl $0x0, (%rax)
jmp 0x294e
movq %rax, %rbx
leaq 0x79fe(%rip), %rdi      # 0xa027
xorl %eax, %eax
callq 0x52d0
movl $0x0, (%rbx)
jmp 0x294e
movq %rbx, %rdi
callq 0x4b45
cmpl $-0x1, %eax
je 0x294e
movl %eax, %edi
callq 0x6b20
testq %rax, %rax
jne 0x2672
callq 0x2090
cmpl $0x0, (%rax)
jne 0x28c5
leaq 0x79f7(%rip), %rdi      # 0xa064
jmp 0x2927
movq %rax, %r15
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x21e0
movq %r14, %rdi
callq 0x2290
leaq 0x79f4(%rip), %rdx      # 0xa085
leaq 0x10(%rsp), %r14
movl $0x14, %esi
movq %r14, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x79de(%rip), %rdi      # 0xa08b
xorl %r12d, %r12d
movq %r14, %rsi
xorl %eax, %eax
callq 0x53ef
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 0x795f(%rip), %rdx      # 0xa085
leaq 0x10(%rsp), %r12
movl $0x14, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x7998(%rip), %rdi      # 0xa0da
xorl %ebp, %ebp
movq %r12, %rsi
xorl %eax, %eax
callq 0x53ef
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 0x790b(%rip), %rdx      # 0xa085
movq %rax, %rcx
callq 0x2270
leaq 0x795e(%rip), %rdi      # 0xa0e7
movq %r12, %rsi
xorl %eax, %eax
callq 0x53ef
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 0x78b9(%rip), %rdx      # 0xa085
leaq 0x10(%rsp), %r12
movl $0x14, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x78f2(%rip), %rdi      # 0xa0da
movq %r12, %rsi
xorl %eax, %eax
callq 0x53ef
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 0x7865(%rip), %rdx      # 0xa085
movq %rax, %rcx
callq 0x2270
leaq 0x78fb(%rip), %rdi      # 0xa12a
movq %r12, %rsi
xorl %eax, %eax
callq 0x53ef
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 0x7816(%rip), %rdx      # 0xa085
leaq 0x10(%rsp), %r12
movl $0x14, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2270
leaq 0x784f(%rip), %rdi      # 0xa0da
movq %r12, %rsi
xorl %eax, %eax
callq 0x53ef
movl $0x0, (%r14)
movl $0xa, %edi
callq 0x2330
movq %r15, %rdi
callq 0x71e5
movq %r15, %rdi
callq 0x71f9
movq %rbx, %rdi
callq 0x493f
xorl %edi, %edi
callq 0x22d0
movq %rax, %rbx
leaq 0x7795(%rip), %rdi      # 0xa064
xorl %eax, %eax
callq 0x52d0
jmp 0x2630
cmpl $0x0, (%r14)
jne 0x28f9
leaq 0x77c0(%rip), %rdi      # 0xa0a8
jmp 0x2927
cmpl $0x0, (%r14)
jne 0x2902
leaq 0x77ca(%rip), %rdi      # 0xa0c1
jmp 0x2927
leaq 0x77a8(%rip), %rdi      # 0xa0a8
jmp 0x2940
leaq 0x77b8(%rip), %rdi      # 0xa0c1
jmp 0x2940
cmpl $0x0, (%r14)
jne 0x2930
leaq 0x77f8(%rip), %rdi      # 0xa110
jmp 0x2927
cmpl $0x0, (%r14)
jne 0x2939
leaq 0x7825(%rip), %rdi      # 0xa14c
xorl %eax, %eax
callq 0x53ef
jmp 0x294e
leaq 0x77d9(%rip), %rdi      # 0xa110
jmp 0x2940
leaq 0x780c(%rip), %rdi      # 0xa14c
xorl %eax, %eax
callq 0x52d0
movl $0x0, (%r14)
movl $0x1, %edi
callq 0x22d0