// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rsi, 0x38(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x24a0
callq 0x3890
movq $0x0, 0x28(%rsp)
leaq 0xf1a0(%rip), %r14      # 0x11650
pushq $0x1
popq %rbx
leaq 0x8b56(%rip), %r13      # 0xb010
movl $0x0, 0x14(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x8bb9(%rip), %rbp      # 0xb08b
leaq 0x8bb5(%rip), %r15      # 0xb08e
movl 0x18(%rsp), %edi
movq 0x38(%rsp), %rsi
callq 0x2de8
testq %rax, %rax
je 0x272f
movq %rax, %r12
movq $0x8e, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x1c(%rsp)
cmpl $0x0, (%r14)
je 0x2526
movq %r12, %rdi
callq 0x31fd
addq 0x8(%rsp), %rax
jmp 0x2534
movq 0x30(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%rsp)
leaq -0x9b(%rax), %rcx
cmpq $0x9, %rcx
ja 0x2567
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
cmpl $0x0, (%r14)
jne 0x263c
movl $0x9b, %esi
subq 0x8(%rsp), %rsi
movq %rbp, %rdi
jmp 0x2624
cmpq $0x95, %rax
je 0x260d
cmpq $0x8f, %rax
jne 0x259b
cmpl $0x0, (%r14)
jne 0x2656
movl $0x8f, %esi
subq 0x8(%rsp), %rsi
leaq 0x8acf(%rip), %rdi      # 0xb065
jmp 0x2624
cmpl $0x0, (%r14)
jne 0x26e5
cmpl $0x0, 0x1c(%rsp)
jne 0x2511
movl $0xa4, %edi
subq 0x8(%rsp), %rdi
callq 0x356a
movl $0x1, 0x1c(%rsp)
jmp 0x2511
cmpl $0x0, (%r14)
jne 0x26ee
movl $0xa1, %edi
subq 0x8(%rsp), %rdi
callq 0x34df
jmp 0x2511
cmpl $0x0, (%r14)
jne 0x270c
movl $0x9e, %esi
subq 0x8(%rsp), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x3315
jmp 0x2511
cmpl $0x0, (%r14)
jne 0x2690
movl $0x95, %esi
subq 0x8(%rsp), %rsi
leaq 0x8a64(%rip), %rdi      # 0xb088
movl %ebx, %edx
callq 0x3315
jmp 0x2511
movl $0x1, (%r14)
jmp 0x24d9
leaq 0xf005(%rip), %rax      # 0x11648
cmpq $0x0, (%rax)
je 0x274d
incl 0x14(%rsp)
jmp 0x24d2
leaq 0xefeb(%rip), %rax      # 0x11648
movq (%rax), %r15
testq %r15, %r15
je 0x27bf
cmpq $0x0, 0x20(%rsp)
jne 0x2748
movq %r15, %rdi
callq 0x2340
movq %rax, 0x20(%rsp)
testq %rax, %rax
jne 0x24d2
jmp 0x2798
leaq 0xefb1(%rip), %rax      # 0x11648
movq (%rax), %rbp
testq %rbp, %rbp
je 0x27de
cmpq $0x0, 0x28(%rsp)
jne 0x2748
movq %rbp, %rdi
callq 0x2340
movq %rax, 0x28(%rsp)
testq %rax, %rax
jne 0x24cb
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2854
leaq 0x8990(%rip), %rdi      # 0xb06a
movq %r12, %rsi
movq %rbp, %rdx
jmp 0x27b3
leaq 0x89e1(%rip), %rdi      # 0xb0cd
jmp 0x26f5
leaq 0x89c1(%rip), %rdi      # 0xb0b6
movq %r12, %rsi
xorl %eax, %eax
callq 0x3a9c
callq 0x20a0
andl $0x0, (%rax)
callq 0x29e3
movq 0xe8e5(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x897b(%rip), %rdi      # 0xb098
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2320
xorl %edi, %edi
callq 0x2300
leaq 0xea9a(%rip), %rax      # 0x111d0
movl 0x18(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x2748
movq 0x28(%rsp), %r12
testq %r12, %r12
jne 0x276c
callq 0x29e3
leaq 0x88e4(%rip), %rdi      # 0xb038
leaq 0x88ec(%rip), %rsi      # 0xb047
leaq 0x88ec(%rip), %rcx      # 0xb04e
movl $0x9b, %edx
callq 0x2190
leaq 0x50(%rsp), %rsi
movq %r12, %rdi
callq 0x3d24
testq %rax, %rax
jne 0x27fd
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2870
leaq 0x894f(%rip), %rdi      # 0xb0e2
jmp 0x29be
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2842
leaq 0x88bd(%rip), %rdi      # 0xb06a
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3a9c
jmp 0x29db
leaq 0x8872(%rip), %rdi      # 0xb038
leaq 0x887a(%rip), %rsi      # 0xb047
leaq 0x887a(%rip), %rcx      # 0xb04e
movl $0x8f, %edx
callq 0x2190
leaq 0x8853(%rip), %rdi      # 0xb038
leaq 0x885b(%rip), %rsi      # 0xb047
leaq 0x885b(%rip), %rcx      # 0xb04e
movl $0x95, %edx
callq 0x2190
movq %rax, %rbx
movq 0x20(%rsp), %r15
testq %r15, %r15
je 0x281a
movq %r15, %rdi
callq 0x2140
testl %eax, %eax
jne 0x294f
xorl %edi, %edi
xorl %esi, %esi
callq 0x3c20
testq %rax, %rax
jne 0x287f
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x297f
leaq 0x88d1(%rip), %rdi      # 0xb10e
jmp 0x29be
movq %rax, %rbx
leaq 0x881e(%rip), %rdi      # 0xb06a
movq %r12, %rsi
movq %r15, %rdx
jmp 0x2864
movq %rax, %rbx
leaq 0x880c(%rip), %rdi      # 0xb06a
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x390d
jmp 0x29d8
movq %rax, %rbx
leaq 0x8868(%rip), %rdi      # 0xb0e2
jmp 0x29d1
movq %rax, %r14
xorl %eax, %eax
testq %r15, %r15
setne %al
movl %eax, 0x40(%rsp)
andq $0x0, 0x48(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x3694
testl %eax, %eax
jne 0x296c
movq 0x50(%rsp), %rdi
leaq 0x171(%rip), %rcx       # 0x2a23
leaq 0x40(%rsp), %r8
movq %r14, %rsi
movq %r14, %rdx
callq 0x402e
testl %eax, %eax
jne 0x29ad
leaq 0x58(%rsp), %rdi
callq 0x3694
testl %eax, %eax
jne 0x296c
cmpl $0x0, 0x14(%rsp)
je 0x292a
movq 0xe70e(%rip), %rax      # 0x10ff8
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 0x86f0(%rip), %xmm0     # 0xb008
addsd %xmm1, %xmm0
leaq 0x8836(%rip), %rsi      # 0xb159
movb $0x1, %al
callq 0x2200
movq %r14, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x3e5f
movq %r12, %rdi
callq 0x2040
movq %r15, %rdi
callq 0x2040
jmp 0x2728
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x298b
leaq 0x87a4(%rip), %rdi      # 0xb104
movq %r15, %rsi
xorl %eax, %eax
callq 0x3a9c
jmp 0x29db
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x29a1
leaq 0x87a1(%rip), %rdi      # 0xb11e
jmp 0x29be
movq %rax, %rbx
leaq 0x8785(%rip), %rdi      # 0xb10e
jmp 0x29d1
movq %rax, %rbx
leaq 0x876f(%rip), %rdi      # 0xb104
movq %r15, %rsi
xorl %eax, %eax
callq 0x390d
jmp 0x29d8
movq %rax, %rbx
leaq 0x8773(%rip), %rdi      # 0xb11e
jmp 0x29d1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x29c7
leaq 0x876e(%rip), %rdi      # 0xb12c
xorl %eax, %eax
callq 0x3a9c
jmp 0x29db
movq %rax, %rbx
leaq 0x875b(%rip), %rdi      # 0xb12c
xorl %eax, %eax
callq 0x390d
andl $0x0, (%rbx)
pushq $0x1
popq %rdi
callq 0x2300