// File: /workspace/github_c_makefile_star2_O3/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 0x254c
callq 0x4354
cmpl $0x2, %ebp
je 0x257a
movq 0xcaa0(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x7aa2(%rip), %rsi      # 0xa004
leaq 0x7aaf(%rip), %rdx      # 0xa018
xorl %eax, %eax
callq 0x21b0
movl $0x1, %edi
callq 0x2290
movq 0x8(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x586c
movq %rax, 0x18(%rsp)
testq %rax, %rax
jne 0x25ac
callq 0x2090
cmpl $0x0, (%rax)
jne 0x25fc
leaq 0x7a82(%rip), %rdi      # 0xa025
xorl %eax, %eax
callq 0x44f3
jmp 0x2570
xorl %eax, %eax
movl %eax, 0xcf94(%rip)      # 0xf548
movl %eax, 0xcf92(%rip)      # 0xf54c
movq 0x10(%rsp), %rdi
leaq 0x5fa(%rip), %rsi       # 0x2bc0
xorl %edx, %edx
callq 0x4618
testl %eax, %eax
jne 0x2618
leaq 0xcf74(%rip), %rdi      # 0xf54c
callq 0x2f6d
orl 0xcf65(%rip), %eax      # 0xf548
je 0x2635
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2675
leaq 0x7a6a(%rip), %rdi      # 0xa064
jmp 0x2629
movq %rax, %rbx
leaq 0x7a1f(%rip), %rdi      # 0xa025
xorl %eax, %eax
callq 0x43d4
movl $0x0, (%rbx)
jmp 0x2570
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2666
leaq 0x7a1d(%rip), %rdi      # 0xa046
xorl %eax, %eax
callq 0x44f3
jmp 0x289c
movq 0xcf14(%rip), %rdi      # 0xf550
shlq $0x4, %rdi
callq 0x21e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x2684
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2856
leaq 0x7a16(%rip), %rdi      # 0xa07a
jmp 0x2629
movq %rax, %rbx
leaq 0x79d6(%rip), %rdi      # 0xa046
jmp 0x2860
movq %rax, %rbx
leaq 0x79e5(%rip), %rdi      # 0xa064
jmp 0x2860
leaq 0x7b35(%rip), %rax      # 0xa1c0
xorl %r12d, %r12d
xorl %r15d, %r15d
movq (%rax), %rax
movq 0xceb5(%rip), %rbp      # 0xf550
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x26cc
movq 0x8(%rsp), %r14
movl %r12d, %ebx
movq 0x20(%rsp), %r13
movzbl %bl, %ebx
movq %r14, %rdi
movl %ebx, %esi
movq %rbp, %rdx
callq 0x2160
incb %bl
addq %rbp, %r14
decq %r13
jne 0x26b2
xorl %eax, %eax
movl %eax, 0xce84(%rip)      # 0xf558
movl %eax, 0xce82(%rip)      # 0xf55c
movq 0x10(%rsp), %rdi
movq 0xce7a(%rip), %rdx      # 0xf560
movq $0x0, (%rsp)
movq 0x20(%rsp), %rbx
movl %ebx, %esi
movq %rbp, %rcx
movq 0x8(%rsp), %r8
leaq 0x4dd(%rip), %r9        # 0x2be1
callq 0x4d04
testl %eax, %eax
jne 0x283c
leaq 0xce44(%rip), %rdi      # 0xf55c
callq 0x2f6d
orl 0xce35(%rip), %eax      # 0xf558
jne 0x2829
addq %rbx, %r12
leaq 0x7a8d(%rip), %rax      # 0xa1c0
leaq (%rax,%r15,8), %rax
addq $0x8, %rax
incq %r15
cmpq $0x27, %r15
jne 0x2691
movq 0xce01(%rip), %rdx      # 0xf550
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x2160
movl $0x100, %r14d           # imm = 0x100
leaq 0x477(%rip), %r15       # 0x2be1
leaq 0xcdeb(%rip), %r12      # 0xf55c
movl %ebx, 0xcde1(%rip)      # 0xf558
movl %ebx, 0xcddf(%rip)      # 0xf55c
movq 0x10(%rsp), %rdi
movq 0xcdd7(%rip), %rdx      # 0xf560
movq 0xcdc0(%rip), %rcx      # 0xf550
movq $0x0, (%rsp)
movl $0x1, %esi
movq 0x8(%rsp), %r8
movq %r15, %r9
callq 0x4d04
testl %eax, %eax
jne 0x283c
movq %r12, %rdi
callq 0x2f6d
orl 0xcd98(%rip), %eax      # 0xf558
jne 0x2829
decq %r14
jne 0x2771
movb $0x0, 0xcd9a(%rip)      # 0xf568
xorl %eax, %eax
movl %eax, 0xcd82(%rip)      # 0xf558
movl %eax, 0xcd80(%rip)      # 0xf55c
movq 0x10(%rsp), %rdi
movq 0xcd68(%rip), %rcx      # 0xf550
movq $0x0, (%rsp)
leaq 0x40a(%rip), %r9        # 0x2c01
movl $0x1, %esi
movq $-0x3, %rdx
movq 0x8(%rsp), %r8
callq 0x4d04
testl %eax, %eax
jne 0x283c
leaq 0xcd44(%rip), %rdi      # 0xf55c
callq 0x2f6d
orl 0xcd35(%rip), %eax      # 0xf558
je 0x28ab
callq 0x2090
cmpl $0x0, (%rax)
jne 0x287b
leaq 0x7865(%rip), %rdi      # 0xa09f
jmp 0x284d
callq 0x2090
cmpl $0x0, (%rax)
jne 0x286f
leaq 0x7834(%rip), %rdi      # 0xa081
xorl %eax, %eax
callq 0x44f3
jmp 0x2892
movq %rax, %rbx
leaq 0x781a(%rip), %rdi      # 0xa07a
xorl %eax, %eax
callq 0x43d4
movl $0x0, (%rbx)
jmp 0x289c
movq %rax, %rbx
leaq 0x7808(%rip), %rdi      # 0xa081
jmp 0x2885
movq %rax, %rbx
leaq 0x781a(%rip), %rdi      # 0xa09f
xorl %eax, %eax
callq 0x43d4
movl $0x0, (%rbx)
movq 0x8(%rsp), %rdi
callq 0x2040
movq 0x18(%rsp), %rdi
callq 0x59b5
jmp 0x2570
cmpb $0x0, 0xccb6(%rip)      # 0xf568
je 0x28cb
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2a4b
leaq 0x77ec(%rip), %rdi      # 0xa0b5
jmp 0x284d
xorl %ebx, %ebx
leaq 0x34c(%rip), %r12       # 0x2c20
leaq 0xcc95(%rip), %r13      # 0xf570
xorl %r15d, %r15d
movl %ebx, 0xcc88(%rip)      # 0xf56c
movl %ebx, 0xcc86(%rip)      # 0xf570
movq 0x10(%rsp), %rdi
movq 0xcc6a(%rip), %rax      # 0xf560
leaq (%r15,%rax), %rsi
addq $-0x200, %rsi           # imm = 0xFE00
movq 0xcc48(%rip), %rdx      # 0xf550
movq %r12, %rcx
movq 0x8(%rsp), %r8
callq 0x4850
testl %eax, %eax
jne 0x2a5a
movq %r13, %rdi
callq 0x2f6d
orl 0xcc41(%rip), %eax      # 0xf56c
jne 0x2a35
movq 0x8(%rsp), %rax
movzbl (%rax), %eax
cmpq $0xff, %r15
ja 0x294c
cmpq %rax, %r15
je 0x2955
jmp 0x2a70
testq %rax, %rax
jne 0x2a70
incq %r15
cmpq $0x200, %r15            # imm = 0x200
jne 0x28de
xorl %r15d, %r15d
movl %r15d, 0xcc05(%rip)     # 0xf574
movb $0x0, 0xcc02(%rip)      # 0xf578
movl %r15d, 0xcbff(%rip)     # 0xf57c
leaq 0x2d1(%rip), %r12       # 0x2c55
movq 0x10(%rsp), %rdi
movq 0xcbd0(%rip), %rax      # 0xf560
leaq (%r15,%rax), %rsi
addq $-0x200, %rsi           # imm = 0xFE00
movq 0xcbae(%rip), %rdx      # 0xf550
movq %r12, %rcx
movq %r15, %r8
callq 0x4850
testl %eax, %eax
jne 0x2a5a
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0x2984
leaq 0xcbb4(%rip), %rdi      # 0xf57c
callq 0x2f6d
testl %eax, %eax
jne 0x2ac8
testb $0x1, 0xcb9c(%rip)      # 0xf578
jne 0x2ac8
movb $0x0, 0xcb97(%rip)      # 0xf580
xorl %eax, %eax
movl %eax, 0xcb7b(%rip)      # 0xf56c
movl %eax, 0xcb79(%rip)      # 0xf570
movq 0x10(%rsp), %rdi
movq 0xcb4d(%rip), %rdx      # 0xf550
leaq 0x27f(%rip), %rcx       # 0x2c89
movq $-0x3, %rsi
xorl %r8d, %r8d
callq 0x4850
testl %eax, %eax
jne 0x2a5a
leaq 0xcb4c(%rip), %rdi      # 0xf570
callq 0x2f6d
orl 0xcb3d(%rip), %eax      # 0xf56c
je 0x2aed
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2ab9
leaq 0x76bd(%rip), %rdi      # 0xa103
jmp 0x284d
movq %rax, %rbx
leaq 0x7660(%rip), %rdi      # 0xa0b5
jmp 0x2885
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2aaa
leaq 0x767d(%rip), %rdi      # 0xa0e8
jmp 0x284d
leaq 0x769f(%rip), %rdi      # 0xa116
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x44f3
callq 0x2090
movq %rax, %rbx
movl %ebp, (%rax)
movq 0x8(%rsp), %rax
movzbl (%rax), %edx
leaq 0x7693(%rip), %rdi      # 0xa12c
movl %r15d, %esi
xorl %eax, %eax
callq 0x44f3
movl %ebp, (%rbx)
jmp 0x2892
movq %rax, %rbx
leaq 0x7634(%rip), %rdi      # 0xa0e8
jmp 0x2885
movq %rax, %rbx
leaq 0x7640(%rip), %rdi      # 0xa103
jmp 0x2885
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2ade
leaq 0x7666(%rip), %rdi      # 0xa13f
jmp 0x284d
movq %rax, %rbx
leaq 0x7657(%rip), %rdi      # 0xa13f
jmp 0x2885
cmpb $0x1, 0xca8c(%rip)      # 0xf580
jne 0x2b0c
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2b62
leaq 0x764e(%rip), %rdi      # 0xa155
jmp 0x284d
xorl %eax, %eax
movl %eax, 0xca70(%rip)      # 0xf584
movl %eax, 0xca6e(%rip)      # 0xf588
movq 0x10(%rsp), %rdi
movq 0xca3a(%rip), %rsi      # 0xf560
leaq 0x17b(%rip), %rdx       # 0x2ca8
xorl %ecx, %ecx
callq 0x4da8
testl %eax, %eax
jne 0x2b71
leaq 0xca49(%rip), %rdi      # 0xf588
callq 0x2f6d
orl 0xca3a(%rip), %eax      # 0xf584
je 0x2b87
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2bb1
leaq 0x7640(%rip), %rdi      # 0xa19d
jmp 0x284d
movq %rax, %rbx
leaq 0x75e9(%rip), %rdi      # 0xa155
jmp 0x2885
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2ba2
leaq 0x75ff(%rip), %rdi      # 0xa181
jmp 0x284d
movq 0x18(%rsp), %rdi
callq 0x59b5
movq 0x8(%rsp), %rdi
callq 0x2040
xorl %edi, %edi
callq 0x2290
movq %rax, %rbx
leaq 0x75d5(%rip), %rdi      # 0xa181
jmp 0x2885
movq %rax, %rbx
leaq 0x75e2(%rip), %rdi      # 0xa19d
jmp 0x2885