// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/tests/lbs/main.c
// Function: main
int
main(int argc, char * argv[])
{
	struct wire_requestqueue * Q;
	struct kivaloo_cookie * K;
	uint8_t * buf;
	size_t i, j, k;

	WARNP_INIT;

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

	/* Open a connection to LBS. */
	if ((K = kivaloo_open(argv[1], &Q)) == NULL) {
		warnp("Could not connect to LBS daemon.");
		goto err0;
	}

	/* Send a PARAMS request and wait for it to complete. */
	params_done = params_failed = 0;
	if (proto_lbs_request_params(Q, callback_params, NULL)) {
		warnp("Failed to send PARAMS request");
		goto err1;
	}
	if (events_spin(&params_done) || params_failed) {
		warnp("PARAMS request failed");
		goto err1;
	}

	/* Allocate 16 blocks. */
	if ((buf = malloc(16 * params_blklen)) == NULL) {
		warnp("malloc");
		goto err1;
	}

	/* Write 256 pages in batches of various sizes. */
	for (i = k = 0; npages[i] != 0; i++) {
		for (j = 0; j < npages[i]; j++)
			memset(&buf[j * params_blklen],
			    (int)(k + j), params_blklen);
		k += npages[i];
		append_done = append_failed = 0;
		if (proto_lbs_request_append(Q, (uint32_t)npages[i],
		    params_nextblk, params_blklen, buf, callback_append,
		    NULL)) {
			warnp("Failed to send APPEND request");
			goto err2;
		}
		if (events_spin(&append_done) || append_failed) {
			warnp("APPEND request failed");
			goto err2;
		}
	}

	/* Write 256 pages individually. */
	memset(buf, 0, params_blklen);
	for (i = 0; i < 256; i++) {
		append_done = append_failed = 0;
		if (proto_lbs_request_append(Q, 1, params_nextblk,
		    params_blklen, buf, callback_append, NULL)) {
			warnp("Failed to send APPEND request");
			goto err2;
		}
		if (events_spin(&append_done) || append_failed) {
			warnp("APPEND request failed");
			goto err2;
		}
	}

	/* Attempt to write with a bad starting block #. */
	append_done = append_failed = append_bad_start_response = 0;
	if (proto_lbs_request_append(Q, 1, BAD_BLKNO, params_blklen,
	    buf, callback_append_should_bad_start, NULL)) {
		warnp("Failed to send APPEND request");
		goto err2;
	}
	if (events_spin(&append_done) || append_failed) {
		warnp("APPEND request failed");
		goto err2;
	}
	if (append_bad_start_response) {
		warnp("APPEND request failed to return bad-starting-blkno");
		goto err2;
	}

	/* Read pages sequentially. */
	for (i = 0; i < 512; i++) {
		get_done = get_failed = 0;
		if (proto_lbs_request_get(Q, params_nextblk - 512 + i,
		    params_blklen, callback_get, buf)) {
			warnp("Failed to send GET request");
			goto err2;
		}
		if (events_spin(&get_done) || get_failed) {
			warnp("GET request failed");
			goto err2;
		}
		if (((i < 256) && (buf[0] != i)) ||
		    ((i >= 256) && (buf[0] != 0))) {
			warn0("GET data is incorrect");
			warn0("i = %d buf[0] = %d", (int)(i), (int)(buf[0]));
			goto err2;
		}
	}

	/* Read 256 pages at once. */
	gets_done = gets_failed = gets_ndone = 0;
	for (i = 0; i < 256; i++) {
		if (proto_lbs_request_get(Q, params_nextblk - 512 + i,
		    params_blklen, callback_gets, (void *)(uintptr_t)(i))) {
			warnp("Failed to send GET request");
			goto err2;
		}
	}
	if (events_spin(&gets_done) || gets_failed) {
		warnp("GET request(s) failed");
		goto err2;
	}

	/* Attempt to read a non-existent block. */
	get_done = get_failed = get_not_exist_response = 0;
	if (proto_lbs_request_get(Q, BAD_BLKNO, params_blklen,
	    callback_get_should_not_exist, NULL)) {
		warnp("Failed to send GET request");
		goto err2;
	}
	if (events_spin(&get_done) || get_failed) {
		warnp("GET request failed");
		goto err2;
	}
	if (get_not_exist_response) {
		warnp("GET request failed to return does-not-exist");
		goto err2;
	}

	/* Free blocks. */
	free_done = free_failed = 0;
	if (proto_lbs_request_free(Q, params_nextblk, callback_free, NULL)) {
		warnp("Failed to send FREE request");
		goto err2;
	}
	if (events_spin(&free_done) || free_failed) {
		warnp("FREE request failed");
		goto err2;
	}

	/* Free the request queue and network connection. */
	kivaloo_close(K);

	/* Free buffer used for holding blocks. */
	free(buf);

	/* Success! */
	exit(0);

err2:
	free(buf);
err1:
	kivaloo_close(K);
err0:
	/* Failure! */
	exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x242c
callq 0x3ecc
cmpl $0x2, %ebp
je 0x2458
movq 0xcbc0(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x6bc2(%rip), %rsi      # 0x9004
leaq 0x6bcf(%rip), %rdx      # 0x9018
xorl %eax, %eax
callq 0x21b0
pushq $0x1
popq %rdi
callq 0x2290
movq 0x8(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x521c
movq %rax, 0x18(%rsp)
testq %rax, %rax
jne 0x248a
callq 0x2090
cmpl $0x0, (%rax)
jne 0x24d6
leaq 0x6ba4(%rip), %rdi      # 0x9025
xorl %eax, %eax
callq 0x40d8
jmp 0x2450
andl $0x0, 0xd0b7(%rip)      # 0xf548
andl $0x0, 0xd0b4(%rip)      # 0xf54c
movq 0x8(%rsp), %rdi
leaq 0x5b3(%rip), %rsi       # 0x2a57
xorl %edx, %edx
callq 0x425c
testl %eax, %eax
jne 0x24ef
leaq 0xd096(%rip), %rdi      # 0xf54c
callq 0x2df3
orl 0xd087(%rip), %eax      # 0xf548
je 0x250c
callq 0x2090
cmpl $0x0, (%rax)
jne 0x254c
leaq 0x6b90(%rip), %rdi      # 0x9064
jmp 0x2500
movq %rax, %rbx
leaq 0x6b45(%rip), %rdi      # 0x9025
xorl %eax, %eax
callq 0x3f49
andl $0x0, (%rbx)
jmp 0x2450
callq 0x2090
cmpl $0x0, (%rax)
jne 0x253d
leaq 0x6b46(%rip), %rdi      # 0x9046
xorl %eax, %eax
callq 0x40d8
jmp 0x2747
movq 0xd03d(%rip), %rdi      # 0xf550
shlq $0x4, %rdi
callq 0x21e0
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x255b
callq 0x2090
cmpl $0x0, (%rax)
jne 0x260f
leaq 0x6b3f(%rip), %rdi      # 0x907a
jmp 0x2500
movq %rax, %rbx
leaq 0x6aff(%rip), %rdi      # 0x9046
jmp 0x2619
movq %rax, %rbx
leaq 0x6b0e(%rip), %rdi      # 0x9064
jmp 0x2619
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x10(%rsp), %r14
cmpq $0x27, %r15
je 0x2628
leaq 0x6c49(%rip), %rax      # 0x91c0
movq (%rax,%r15,8), %r13
movq 0xcfce(%rip), %rbp      # 0xf550
movl %r12d, %ebx
movq %r13, 0x20(%rsp)
subq $0x1, %r13
jb 0x25a7
movzbl %bl, %ebx
movq %r14, %rdi
movl %ebx, %esi
movq %rbp, %rdx
callq 0x2160
addq %rbp, %r14
incb %bl
jmp 0x258a
andl $0x0, 0xcfaa(%rip)      # 0xf558
andl $0x0, 0xcfa7(%rip)      # 0xf55c
movq 0x8(%rsp), %rdi
movq 0xcf9f(%rip), %rdx      # 0xf560
andq $0x0, (%rsp)
movq 0x20(%rsp), %rbx
movl %ebx, %esi
movq %rbp, %rcx
movq 0x10(%rsp), %r14
movq %r14, %r8
leaq 0x499(%rip), %r9        # 0x2a78
callq 0x4908
testl %eax, %eax
jne 0x2703
addq %rbx, %r12
leaq 0xcf66(%rip), %rdi      # 0xf55c
callq 0x2df3
incq %r15
orl 0xcf54(%rip), %eax      # 0xf558
je 0x2566
jmp 0x26f0
movq %rax, %rbx
leaq 0x6a61(%rip), %rdi      # 0x907a
xorl %eax, %eax
callq 0x3f49
andl $0x0, (%rbx)
jmp 0x2747
movq 0xcf21(%rip), %rdx      # 0xf550
movq %r14, %rdi
xorl %esi, %esi
callq 0x2160
movl $0x101, %ebx            # imm = 0x101
leaq 0x433(%rip), %r15       # 0x2a78
pushq $0x1
popq %rbp
leaq 0xcf0d(%rip), %r12      # 0xf55c
decq %rbx
je 0x269d
andl $0x0, 0xcefd(%rip)      # 0xf558
andl $0x0, 0xcefa(%rip)      # 0xf55c
movq 0x8(%rsp), %rdi
movq 0xcef2(%rip), %rdx      # 0xf560
movq 0xcedb(%rip), %rcx      # 0xf550
andq $0x0, (%rsp)
movl %ebp, %esi
movq %r14, %r8
movq %r15, %r9
callq 0x4908
testl %eax, %eax
jne 0x2703
movq %r12, %rdi
callq 0x2df3
orl 0xcebf(%rip), %eax      # 0xf558
je 0x264f
jmp 0x26f0
andl $0x0, 0xceb4(%rip)      # 0xf558
andl $0x0, 0xceb1(%rip)      # 0xf55c
movb $0x0, 0xceb6(%rip)      # 0xf568
movq 0x8(%rsp), %rdi
movq 0xce92(%rip), %rcx      # 0xf550
andq $0x0, (%rsp)
leaq 0x3cc(%rip), %r9        # 0x2a96
pushq $0x1
popq %rsi
pushq $-0x3
popq %rdx
movq %r14, %r8
callq 0x4908
testl %eax, %eax
jne 0x2703
leaq 0xce79(%rip), %rdi      # 0xf55c
callq 0x2df3
orl 0xce6a(%rip), %eax      # 0xf558
je 0x2756
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2729
leaq 0x699e(%rip), %rdi      # 0x909f
jmp 0x2714
callq 0x2090
cmpl $0x0, (%rax)
jne 0x271d
leaq 0x696d(%rip), %rdi      # 0x9081
xorl %eax, %eax
callq 0x40d8
jmp 0x273d
movq %rax, %rbx
leaq 0x695a(%rip), %rdi      # 0x9081
jmp 0x2733
movq %rax, %rbx
leaq 0x696c(%rip), %rdi      # 0x909f
xorl %eax, %eax
callq 0x3f49
andl $0x0, (%rbx)
movq 0x10(%rsp), %rdi
callq 0x2040
movq 0x18(%rsp), %rdi
callq 0x5357
jmp 0x2450
cmpb $0x0, 0xce0b(%rip)      # 0xf568
je 0x2776
callq 0x2090
cmpl $0x0, (%rax)
jne 0x280a
leaq 0x6941(%rip), %rdi      # 0x90b5
jmp 0x2714
xorl %r15d, %r15d
leaq 0x335(%rip), %r12       # 0x2ab5
leaq 0xcde9(%rip), %r13      # 0xf570
movq 0x10(%rsp), %r14
cmpq $0x200, %r15            # imm = 0x200
je 0x2819
andl $0x0, 0xcdcc(%rip)      # 0xf56c
andl $0x0, 0xcdc9(%rip)      # 0xf570
movq 0x8(%rsp), %rdi
movq 0xcdad(%rip), %rax      # 0xf560
leaq (%r15,%rax), %rsi
addq $-0x200, %rsi           # imm = 0xFE00
movq 0xcd8b(%rip), %rdx      # 0xf550
movq %r12, %rcx
movq %r14, %r8
callq 0x44b0
testl %eax, %eax
jne 0x292b
movq %r13, %rdi
callq 0x2df3
orl 0xcd86(%rip), %eax      # 0xf56c
jne 0x2915
movzbl (%r14), %eax
cmpq $0xff, %r15
ja 0x2800
cmpq %rax, %r15
je 0x2805
jmp 0x2876
testq %rax, %rax
jne 0x2876
incq %r15
jmp 0x278c
movq %rax, %rbx
leaq 0x68a1(%rip), %rdi      # 0x90b5
jmp 0x2733
andl $0x0, 0xcd54(%rip)      # 0xf574
andl $0x0, 0xcd55(%rip)      # 0xf57c
movb $0x0, 0xcd4a(%rip)      # 0xf578
xorl %r15d, %r15d
leaq 0x2b0(%rip), %rbx       # 0x2ae8
cmpq $0x100, %r15            # imm = 0x100
je 0x28a9
movq 0x8(%rsp), %rdi
movq 0xcd13(%rip), %rax      # 0xf560
leaq (%r15,%rax), %rsi
addq $-0x200, %rsi           # imm = 0xFE00
movq 0xccf1(%rip), %rdx      # 0xf550
movq %rbx, %rcx
movq %r15, %r8
callq 0x44b0
incq %r15
testl %eax, %eax
je 0x2838
jmp 0x292b
leaq 0x6899(%rip), %rdi      # 0x9116
xorl %eax, %eax
callq 0x40d8
callq 0x2090
movq %rax, %rbx
andl $0x0, (%rax)
movzbl (%r14), %edx
leaq 0x6892(%rip), %rdi      # 0x912c
movl %r15d, %esi
xorl %eax, %eax
callq 0x40d8
jmp 0x273a
leaq 0xcccc(%rip), %rdi      # 0xf57c
callq 0x2df3
testl %eax, %eax
jne 0x295f
testb $0x1, 0xccb4(%rip)      # 0xf578
jne 0x295f
andl $0x0, 0xcc9b(%rip)      # 0xf56c
andl $0x0, 0xcc98(%rip)      # 0xf570
movb $0x0, 0xcca1(%rip)      # 0xf580
movq 0x8(%rsp), %rdi
movq 0xcc65(%rip), %rdx      # 0xf550
leaq 0x22a(%rip), %rcx       # 0x2b1c
pushq $-0x3
popq %rsi
xorl %r8d, %r8d
callq 0x44b0
testl %eax, %eax
jne 0x292b
leaq 0xcc68(%rip), %rdi      # 0xf570
callq 0x2df3
orl 0xcc59(%rip), %eax      # 0xf56c
je 0x2984
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2950
leaq 0x67dd(%rip), %rdi      # 0x9103
jmp 0x2714
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2941
leaq 0x67ac(%rip), %rdi      # 0x90e8
jmp 0x2714
movq %rax, %rbx
leaq 0x679d(%rip), %rdi      # 0x90e8
jmp 0x2733
movq %rax, %rbx
leaq 0x67a9(%rip), %rdi      # 0x9103
jmp 0x2733
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2975
leaq 0x67cf(%rip), %rdi      # 0x913f
jmp 0x2714
movq %rax, %rbx
leaq 0x67c0(%rip), %rdi      # 0x913f
jmp 0x2733
cmpb $0x1, 0xcbf5(%rip)      # 0xf580
jne 0x29a3
callq 0x2090
cmpl $0x0, (%rax)
jne 0x29f9
leaq 0x67b7(%rip), %rdi      # 0x9155
jmp 0x2714
andl $0x0, 0xcbda(%rip)      # 0xf584
andl $0x0, 0xcbd7(%rip)      # 0xf588
movq 0x8(%rsp), %rdi
movq 0xcba3(%rip), %rsi      # 0xf560
leaq 0x177(%rip), %rdx       # 0x2b3b
xorl %ecx, %ecx
callq 0x499f
testl %eax, %eax
jne 0x2a08
leaq 0xcbb2(%rip), %rdi      # 0xf588
callq 0x2df3
orl 0xcba3(%rip), %eax      # 0xf584
je 0x2a1e
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2a48
leaq 0x67a9(%rip), %rdi      # 0x919d
jmp 0x2714
movq %rax, %rbx
leaq 0x6752(%rip), %rdi      # 0x9155
jmp 0x2733
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2a39
leaq 0x6768(%rip), %rdi      # 0x9181
jmp 0x2714
movq 0x18(%rsp), %rdi
callq 0x5357
movq 0x10(%rsp), %rdi
callq 0x2040
xorl %edi, %edi
callq 0x2290
movq %rax, %rbx
leaq 0x673e(%rip), %rdi      # 0x9181
jmp 0x2733
movq %rax, %rbx
leaq 0x674b(%rip), %rdi      # 0x919d
jmp 0x2733