// File: /workspace/github_c_makefile_star2_O1/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 0x4338
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 0x582c
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 0x44d7
jmp 0x2570
xorl %eax, %eax
movl %eax, 0xcf94(%rip)      # 0xf548
movl %eax, 0xcf92(%rip)      # 0xf54c
movq 0x10(%rsp), %rdi
leaq 0x60b(%rip), %rsi       # 0x2bd1
xorl %edx, %edx
callq 0x45fc
testl %eax, %eax
jne 0x2618
leaq 0xcf74(%rip), %rdi      # 0xf54c
callq 0x2f8d
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 0x43b8
movl $0x0, (%rbx)
jmp 0x2570
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2666
leaq 0x7a1d(%rip), %rdi      # 0xa046
xorl %eax, %eax
callq 0x44d7
jmp 0x28a0
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 0x285a
leaq 0x7a16(%rip), %rdi      # 0xa07a
jmp 0x2629
movq %rax, %rbx
leaq 0x79d6(%rip), %rdi      # 0xa046
jmp 0x2864
movq %rax, %rbx
leaq 0x79e5(%rip), %rdi      # 0xa064
jmp 0x2864
leaq 0x7b35(%rip), %rax      # 0xa1c0
xorl %r12d, %r12d
xorl %r15d, %r15d
movq (%rax), %rax
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x26cc
movq 0xceab(%rip), %rbp      # 0xf550
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 0xce63(%rip), %rcx      # 0xf550
movq $0x0, (%rsp)
movq 0x20(%rsp), %rbx
movl %ebx, %esi
movq 0x8(%rsp), %r8
leaq 0x4ea(%rip), %r9        # 0x2bf2
callq 0x4ce9
testl %eax, %eax
jne 0x2840
leaq 0xce40(%rip), %rdi      # 0xf55c
callq 0x2f8d
orl 0xce31(%rip), %eax      # 0xf558
jne 0x282d
addq %rbx, %r12
leaq 0x7a89(%rip), %rax      # 0xa1c0
leaq (%rax,%r15,8), %rax
addq $0x8, %rax
incq %r15
cmpq $0x27, %r15
jne 0x2691
movq 0xcdfd(%rip), %rdx      # 0xf550
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x2160
movl $0x100, %r14d           # imm = 0x100
leaq 0x484(%rip), %r15       # 0x2bf2
leaq 0xcde7(%rip), %r12      # 0xf55c
movl %ebx, 0xcddd(%rip)      # 0xf558
movl %ebx, 0xcddb(%rip)      # 0xf55c
movq 0x10(%rsp), %rdi
movq 0xcdd3(%rip), %rdx      # 0xf560
movq 0xcdbc(%rip), %rcx      # 0xf550
movq $0x0, (%rsp)
movl $0x1, %esi
movq 0x8(%rsp), %r8
movq %r15, %r9
callq 0x4ce9
testl %eax, %eax
jne 0x2840
movq %r12, %rdi
callq 0x2f8d
orl 0xcd94(%rip), %eax      # 0xf558
jne 0x282d
decq %r14
jne 0x2775
movb $0x0, 0xcd96(%rip)      # 0xf568
xorl %eax, %eax
movl %eax, 0xcd7e(%rip)      # 0xf558
movl %eax, 0xcd7c(%rip)      # 0xf55c
movq 0x10(%rsp), %rdi
movq 0xcd64(%rip), %rcx      # 0xf550
movq $0x0, (%rsp)
leaq 0x417(%rip), %r9        # 0x2c12
movl $0x1, %esi
movq $-0x3, %rdx
movq 0x8(%rsp), %r8
callq 0x4ce9
testl %eax, %eax
jne 0x2840
leaq 0xcd40(%rip), %rdi      # 0xf55c
callq 0x2f8d
orl 0xcd31(%rip), %eax      # 0xf558
je 0x28af
callq 0x2090
cmpl $0x0, (%rax)
jne 0x287f
leaq 0x7861(%rip), %rdi      # 0xa09f
jmp 0x2851
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2873
leaq 0x7830(%rip), %rdi      # 0xa081
xorl %eax, %eax
callq 0x44d7
jmp 0x2896
movq %rax, %rbx
leaq 0x7816(%rip), %rdi      # 0xa07a
xorl %eax, %eax
callq 0x43b8
movl $0x0, (%rbx)
jmp 0x28a0
movq %rax, %rbx
leaq 0x7804(%rip), %rdi      # 0xa081
jmp 0x2889
movq %rax, %rbx
leaq 0x7816(%rip), %rdi      # 0xa09f
xorl %eax, %eax
callq 0x43b8
movl $0x0, (%rbx)
movq 0x8(%rsp), %rdi
callq 0x2040
movq 0x18(%rsp), %rdi
callq 0x5975
jmp 0x2570
cmpb $0x0, 0xccb2(%rip)      # 0xf568
je 0x28cf
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2a5c
leaq 0x77e8(%rip), %rdi      # 0xa0b5
jmp 0x2851
xorl %ebx, %ebx
leaq 0x359(%rip), %r12       # 0x2c31
leaq 0xcc91(%rip), %r13      # 0xf570
xorl %r15d, %r15d
movl %ebx, 0xcc84(%rip)      # 0xf56c
movl %ebx, 0xcc82(%rip)      # 0xf570
movq 0x10(%rsp), %rdi
movq 0xcc66(%rip), %rax      # 0xf560
leaq (%r15,%rax), %rsi
addq $-0x200, %rsi           # imm = 0xFE00
movq 0xcc44(%rip), %rdx      # 0xf550
movq %r12, %rcx
movq 0x8(%rsp), %r8
callq 0x4834
testl %eax, %eax
jne 0x2a6b
movq %r13, %rdi
callq 0x2f8d
orl 0xcc3d(%rip), %eax      # 0xf56c
jne 0x2a46
cmpq $0xff, %r15
ja 0x294f
movq 0x8(%rsp), %rax
movzbl (%rax), %eax
cmpq %rax, %r15
jne 0x2a81
cmpq $0x100, %r15            # imm = 0x100
jb 0x2966
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x2a81
incq %r15
cmpq $0x200, %r15            # imm = 0x200
jne 0x28e2
xorl %r15d, %r15d
movl %r15d, 0xcbf4(%rip)     # 0xf574
movb $0x0, 0xcbf1(%rip)      # 0xf578
movl %r15d, 0xcbee(%rip)     # 0xf57c
leaq 0x2d1(%rip), %r12       # 0x2c66
movq 0x10(%rsp), %rdi
movq 0xcbbf(%rip), %rax      # 0xf560
leaq (%r15,%rax), %rsi
addq $-0x200, %rsi           # imm = 0xFE00
movq 0xcb9d(%rip), %rdx      # 0xf550
movq %r12, %rcx
movq %r15, %r8
callq 0x4834
testl %eax, %eax
jne 0x2a6b
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0x2995
leaq 0xcba3(%rip), %rdi      # 0xf57c
callq 0x2f8d
testl %eax, %eax
jne 0x2ad9
testb $0x1, 0xcb8b(%rip)      # 0xf578
jne 0x2ad9
movb $0x0, 0xcb86(%rip)      # 0xf580
xorl %eax, %eax
movl %eax, 0xcb6a(%rip)      # 0xf56c
movl %eax, 0xcb68(%rip)      # 0xf570
movq 0x10(%rsp), %rdi
movq 0xcb3c(%rip), %rdx      # 0xf550
leaq 0x27f(%rip), %rcx       # 0x2c9a
movq $-0x3, %rsi
xorl %r8d, %r8d
callq 0x4834
testl %eax, %eax
jne 0x2a6b
leaq 0xcb3b(%rip), %rdi      # 0xf570
callq 0x2f8d
orl 0xcb2c(%rip), %eax      # 0xf56c
je 0x2afe
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2aca
leaq 0x76ac(%rip), %rdi      # 0xa103
jmp 0x2851
movq %rax, %rbx
leaq 0x764f(%rip), %rdi      # 0xa0b5
jmp 0x2889
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2abb
leaq 0x766c(%rip), %rdi      # 0xa0e8
jmp 0x2851
leaq 0x768e(%rip), %rdi      # 0xa116
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x44d7
callq 0x2090
movq %rax, %rbx
movl %ebp, (%rax)
movq 0x8(%rsp), %rax
movzbl (%rax), %edx
leaq 0x7682(%rip), %rdi      # 0xa12c
movl %r15d, %esi
xorl %eax, %eax
callq 0x44d7
movl %ebp, (%rbx)
jmp 0x2896
movq %rax, %rbx
leaq 0x7623(%rip), %rdi      # 0xa0e8
jmp 0x2889
movq %rax, %rbx
leaq 0x762f(%rip), %rdi      # 0xa103
jmp 0x2889
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2aef
leaq 0x7655(%rip), %rdi      # 0xa13f
jmp 0x2851
movq %rax, %rbx
leaq 0x7646(%rip), %rdi      # 0xa13f
jmp 0x2889
cmpb $0x1, 0xca7b(%rip)      # 0xf580
jne 0x2b1d
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2b73
leaq 0x763d(%rip), %rdi      # 0xa155
jmp 0x2851
xorl %eax, %eax
movl %eax, 0xca5f(%rip)      # 0xf584
movl %eax, 0xca5d(%rip)      # 0xf588
movq 0x10(%rsp), %rdi
movq 0xca29(%rip), %rsi      # 0xf560
leaq 0x17b(%rip), %rdx       # 0x2cb9
xorl %ecx, %ecx
callq 0x4d92
testl %eax, %eax
jne 0x2b82
leaq 0xca38(%rip), %rdi      # 0xf588
callq 0x2f8d
orl 0xca29(%rip), %eax      # 0xf584
je 0x2b98
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2bc2
leaq 0x762f(%rip), %rdi      # 0xa19d
jmp 0x2851
movq %rax, %rbx
leaq 0x75d8(%rip), %rdi      # 0xa155
jmp 0x2889
callq 0x2090
cmpl $0x0, (%rax)
jne 0x2bb3
leaq 0x75ee(%rip), %rdi      # 0xa181
jmp 0x2851
movq 0x18(%rsp), %rdi
callq 0x5975
movq 0x8(%rsp), %rdi
callq 0x2040
xorl %edi, %edi
callq 0x2290
movq %rax, %rbx
leaq 0x75c4(%rip), %rdi      # 0xa181
jmp 0x2889
movq %rax, %rbx
leaq 0x75d1(%rip), %rdi      # 0xa19d
jmp 0x2889