// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/kvlds-dump/main.c
// Function: main
int
main(int argc, char * argv[])
{
	/* State variables. */
	void * K;
	struct wire_requestqueue * Q;
	struct dumpstate C;
	struct timeval st, en;

	/* Command-line parameters. */
	char * opt_fs = NULL;
	char * opt_t = NULL;
	int opt_v = 0;

	/* Working variables. */
	const char * ch;
	struct kvldskey * nullkey;

	WARNP_INIT;

	/* Parse the command line. */
	while ((ch = GETOPT(argc, argv)) != NULL) {
		GETOPT_SWITCH(ch) {
		GETOPT_OPTARG("--fs"):
			if (opt_fs != NULL)
				usage();
			if ((opt_fs = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-t"):
			if (opt_t != NULL)
				usage();
			if ((opt_t = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-v"):
			opt_v++;
			break;
		GETOPT_OPT("--version"):
			fprintf(stderr, "kivaloo-kvlds-dump @VERSION@\n");
			exit(0);
		GETOPT_MISSING_ARG:
			warn0("Missing argument to %s", ch);
			usage();
		GETOPT_DEFAULT:
			warn0("illegal option -- %s", ch);
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	/* We should have processed all the arguments. */
	if (argc != 0)
		usage();
	(void)argv; /* argv is not used beyond this point. */

	/* Sanity-check options. */
	if (opt_t == NULL)
		usage();

	/* Open a connection to KVLDS. */
	if ((K = kivaloo_open(opt_t, &Q)) == NULL) {
		warnp("Could not connect to KVLDS daemon");
		exit(1);
	}

	/* If we're writing to the filesystem, move to that directory. */
	if (opt_fs) {
		if (chdir(opt_fs)) {
			warnp("chdir(%s)", opt_fs);
			exit(1);
		}
	}

	/* Prepare for dumping key-value pairs. */
	if ((nullkey = kvldskey_create(NULL, 0)) == NULL) {
		warnp("kvldskey_create");
		exit(1);
	}
	C.tofs = opt_fs ? 1 : 0;
	C.N = 0;

	/* Get timestamp. */
	if (monoclock_get(&st)) {
		warnp("monoclock_get");
		exit(1);
	}

	/* Read the range. */
	if (kvlds_range(Q, nullkey, nullkey, callback_pair, &C)) {
		warnp("Error occurred while reading key-value pairs");
		exit(1);
	}

	/* Get timestamp. */
	if (monoclock_get(&en)) {
		warnp("monoclock_get");
		exit(1);
	}

	/* Print statistics if appropriate. */
	if (opt_v) {
		fprintf(stderr,
		    "Dumped %" PRIu64 " key-value pairs in %f seconds.",
		    C.N, timeval_diff(en, st));
	}

	/* Free memory allocated by kvldskey_create. */
	kvldskey_free(nullkey);

	/* Close the connection to KVLDS. */
	kivaloo_close(K);

	/* Free option strings. */
	free(opt_t);
	free(opt_fs);

	/* Success! */
	exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edi, %r15d
movq %rsi, 0x30(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x291f
callq 0x3b0c
movl %r15d, %edi
movq 0x30(%rsp), %rsi
callq 0x32dc
testq %rax, %rax
movl %r15d, 0x10(%rsp)
jne 0x295c
movb $0x1, %bpl
xorl %r12d, %r12d
xorl %r15d, %r15d
leaq 0xf89a(%rip), %rax      # 0x121e0
movl 0x10(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x2957
testq %r12, %r12
jne 0x2c06
callq 0x2e97
movq %rax, %r12
movq $0x0, 0x28(%rsp)
leaq 0xfcf1(%rip), %r13      # 0x12660
leaq 0x969a(%rip), %rbx      # 0xc010
leaq 0x970e(%rip), %r14      # 0xc08b
leaq 0x970a(%rip), %rbp      # 0xc08e
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x8e, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0x0, (%r13)
je 0x29ca
movq %r12, %rdi
callq 0x3607
addq 0x8(%rsp), %rax
jmp 0x29d8
movq 0x38(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x38(%rsp)
leaq -0x9b(%rax), %rcx
cmpq $0x9, %rcx
ja 0x2a0b
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
cmpl $0x0, (%r13)
jne 0x2aed
movl $0x9b, %esi
subq 0x8(%rsp), %rsi
movq %r14, %rdi
jmp 0x2ad1
cmpq $0x95, %rax
je 0x2ab5
cmpq $0x8f, %rax
jne 0x2a40
cmpl $0x0, (%r13)
jne 0x2b0c
movl $0x8f, %esi
subq 0x8(%rsp), %rsi
leaq 0x962a(%rip), %rdi      # 0xc065
jmp 0x2ad1
cmpl $0x0, (%r13)
jne 0x2bb5
cmpl $0x0, 0x14(%rsp)
jne 0x29b4
movl $0xa4, %edi
subq 0x8(%rsp), %rdi
callq 0x381b
movl $0x1, 0x14(%rsp)
jmp 0x29b4
cmpl $0x0, (%r13)
jne 0x2bbe
movl $0xa1, %edi
subq 0x8(%rsp), %rdi
callq 0x37db
jmp 0x29b4
cmpl $0x0, (%r13)
jne 0x2bdf
movl $0x9e, %esi
subq 0x8(%rsp), %rsi
movq %rbp, %rdi
xorl %edx, %edx
callq 0x36c4
jmp 0x29b4
cmpl $0x0, (%r13)
jne 0x2b42
movl $0x95, %esi
subq 0x8(%rsp), %rsi
leaq 0x95b7(%rip), %rdi      # 0xc088
movl $0x1, %edx
callq 0x36c4
jmp 0x29b4
movl $0x1, (%r13)
jmp 0x2b84
leaq 0xfb64(%rip), %rax      # 0x12658
cmpq $0x0, (%rax)
je 0x2e00
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
jmp 0x2b84
leaq 0xfb45(%rip), %rax      # 0x12658
cmpq $0x0, (%rax)
je 0x2e1f
cmpq $0x0, 0x20(%rsp)
jne 0x2957
leaq 0xfb28(%rip), %rax      # 0x12658
movq (%rax), %r15
movq %r15, %rdi
callq 0x2350
movq %rax, 0x20(%rsp)
jmp 0x2b76
leaq 0xfb0f(%rip), %rax      # 0x12658
cmpq $0x0, (%rax)
je 0x2e3e
cmpq $0x0, 0x18(%rsp)
jne 0x2957
leaq 0xfaf2(%rip), %rax      # 0x12658
movq (%rax), %r15
movq %r15, %rdi
callq 0x2350
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x2db8
movl 0x10(%rsp), %r15d
movl %r15d, %edi
movq 0x30(%rsp), %rsi
callq 0x32dc
movq %rax, %r12
testq %rax, %rax
jne 0x2996
cmpl $0x0, 0x28(%rsp)
sete %bpl
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %r12
jmp 0x293f
leaq 0x9511(%rip), %rdi      # 0xc0cd
jmp 0x2bc5
leaq 0x94f1(%rip), %rdi      # 0xc0b6
movq %r12, %rsi
xorl %eax, %eax
callq 0x3cab
callq 0x20a0
movl $0x0, (%rax)
callq 0x2e97
movq 0xf412(%rip), %rax      # 0x11ff8
movq (%rax), %rcx
leaq 0x94a8(%rip), %rdi      # 0xc098
movl $0x1d, %esi
movl $0x1, %edx
callq 0x2330
xorl %edi, %edi
callq 0x2310
leaq 0x50(%rsp), %rsi
movq %r12, %rdi
callq 0x3f10
testq %rax, %rax
jne 0x2c2e
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2c6e
leaq 0x94b9(%rip), %rdi      # 0xc0e2
jmp 0x2df4
movq %rax, %rbx
testq %r15, %r15
je 0x2c46
movq %r15, %rdi
callq 0x2140
testl %eax, %eax
jne 0x2d4e
xorl %edi, %edi
xorl %esi, %esi
callq 0x3dd0
testq %rax, %rax
jne 0x2c7d
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2d81
leaq 0x94a5(%rip), %rdi      # 0xc10e
jmp 0x2df4
movq %rax, %rbx
leaq 0x946a(%rip), %rdi      # 0xc0e2
jmp 0x2e80
movq %rax, %r14
xorl %eax, %eax
testq %r15, %r15
setne %al
movl %eax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x38d0
testl %eax, %eax
jne 0x2d6e
movq 0x50(%rsp), %rdi
leaq 0x228(%rip), %rcx       # 0x2edb
leaq 0x40(%rsp), %r8
movq %r14, %rsi
movq %r14, %rdx
callq 0x4245
testl %eax, %eax
jne 0x2ddf
leaq 0x58(%rsp), %rdi
callq 0x38d0
testl %eax, %eax
jne 0x2d6e
testb %bpl, %bpl
jne 0x2d29
movq 0xf30f(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq 0x68(%rsp), %rax
movq 0x70(%rsp), %rcx
subq 0x58(%rsp), %rax
cvtsi2sd %rax, %xmm1
subq 0x60(%rsp), %rcx
cvtsi2sd %rcx, %xmm0
movq 0x48(%rsp), %rdx
mulsd 0x92f1(%rip), %xmm0     # 0xc008
addsd %xmm1, %xmm0
leaq 0x9437(%rip), %rsi      # 0xc159
movb $0x1, %al
callq 0x2210
movq %r14, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x4059
movq %r12, %rdi
callq 0x2040
movq %r15, %rdi
callq 0x2040
jmp 0x2bff
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2d90
leaq 0x93a5(%rip), %rdi      # 0xc104
movq %r15, %rsi
xorl %eax, %eax
callq 0x3cab
jmp 0x2e8d
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2da9
leaq 0x939f(%rip), %rdi      # 0xc11e
jmp 0x2df4
movq %rax, %rbx
leaq 0x9383(%rip), %rdi      # 0xc10e
jmp 0x2e80
movq %rax, %rbx
leaq 0x936a(%rip), %rdi      # 0xc104
movq %r15, %rsi
xorl %eax, %eax
callq 0x3b8c
jmp 0x2e87
movq %rax, %rbx
leaq 0x936b(%rip), %rdi      # 0xc11e
jmp 0x2e80
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e5d
leaq 0x929d(%rip), %rdi      # 0xc06a
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3cab
jmp 0x2e8d
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e76
leaq 0x9338(%rip), %rdi      # 0xc12c
xorl %eax, %eax
callq 0x3cab
jmp 0x2e8d
leaq 0x9231(%rip), %rdi      # 0xc038
leaq 0x9239(%rip), %rsi      # 0xc047
leaq 0x9239(%rip), %rcx      # 0xc04e
movl $0x9b, %edx
callq 0x2190
leaq 0x9212(%rip), %rdi      # 0xc038
leaq 0x921a(%rip), %rsi      # 0xc047
leaq 0x921a(%rip), %rcx      # 0xc04e
movl $0x8f, %edx
callq 0x2190
leaq 0x91f3(%rip), %rdi      # 0xc038
leaq 0x91fb(%rip), %rsi      # 0xc047
leaq 0x91fb(%rip), %rcx      # 0xc04e
movl $0x95, %edx
callq 0x2190
movq %rax, %rbx
leaq 0x9203(%rip), %rdi      # 0xc06a
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3b8c
jmp 0x2e87
movq %rax, %rbx
leaq 0x92ac(%rip), %rdi      # 0xc12c
xorl %eax, %eax
callq 0x3b8c
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x2310