// File: /workspace/github_c_makefile_star2_O3/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 0x295f
callq 0x3bbc
movl %r15d, %edi
movq 0x30(%rsp), %rsi
callq 0x32e8
testq %rax, %rax
jne 0x2980
leaq 0xf868(%rip), %rax      # 0x121e0
cmpl %r15d, (%rax)
callq 0x2ea3
movq %rax, %r12
movq $0x0, 0x28(%rsp)
leaq 0xfccd(%rip), %r13      # 0x12660
leaq 0x9676(%rip), %rbx      # 0xc010
leaq 0x96ea(%rip), %r14      # 0xc08b
leaq 0x96e6(%rip), %rbp      # 0xc08e
movl $0x0, 0x1c(%rsp)
movq $0x0, 0x10(%rsp)
movl %r15d, 0x20(%rsp)
movq $0x8e, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x24(%rsp)
cmpl $0x0, (%r13)
je 0x29f2
movq %r12, %rdi
callq 0x362f
addq 0x8(%rsp), %rax
jmp 0x2a00
movq 0x38(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x38(%rsp)
leaq -0x9b(%rax), %rcx
cmpq $0x9, %rcx
ja 0x2a33
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
cmpl $0x0, (%r13)
jne 0x2b0e
movl $0x9b, %esi
subq 0x8(%rsp), %rsi
movq %r14, %rdi
jmp 0x2af5
cmpq $0x95, %rax
je 0x2add
cmpq $0x8f, %rax
jne 0x2a68
cmpl $0x0, (%r13)
jne 0x2b25
movl $0x8f, %esi
subq 0x8(%rsp), %rsi
leaq 0x9602(%rip), %rdi      # 0xc065
jmp 0x2af5
cmpl $0x0, (%r13)
jne 0x2bf4
cmpl $0x0, 0x24(%rsp)
jne 0x29dc
movl $0xa4, %edi
subq 0x8(%rsp), %rdi
callq 0x383d
movl $0x1, 0x24(%rsp)
jmp 0x29dc
cmpl $0x0, (%r13)
jne 0x2bfd
movl $0xa1, %edi
subq 0x8(%rsp), %rdi
callq 0x37fd
jmp 0x29dc
cmpl $0x0, (%r13)
jne 0x2c1e
movl $0x9e, %esi
subq 0x8(%rsp), %rsi
movq %rbp, %rdi
xorl %edx, %edx
callq 0x36ec
jmp 0x29dc
cmpl $0x0, (%r13)
jne 0x2b53
movl $0x95, %esi
subq 0x8(%rsp), %rsi
leaq 0x9593(%rip), %rdi      # 0xc088
movl $0x1, %edx
callq 0x36ec
jmp 0x29dc
movl $0x1, (%r13)
jmp 0x2b8d
leaq 0xfb43(%rip), %rax      # 0x12658
cmpq $0x0, (%rax)
je 0x2c68
incl 0x1c(%rsp)
jmp 0x2b8d
leaq 0xfb2c(%rip), %rax      # 0x12658
movq (%rax), %r15
testq %r15, %r15
je 0x2c87
cmpq $0x0, 0x28(%rsp)
jne 0x297b
movq %r15, %rdi
callq 0x2350
movq %rax, 0x28(%rsp)
jmp 0x2b7f
leaq 0xfafe(%rip), %rax      # 0x12658
movq (%rax), %r15
testq %r15, %r15
je 0x2ca6
cmpq $0x0, 0x10(%rsp)
jne 0x297b
movq %r15, %rdi
callq 0x2350
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2c45
movl 0x20(%rsp), %r15d
movl %r15d, %edi
movq 0x30(%rsp), %rsi
callq 0x32e8
movq %rax, %r12
testq %rax, %rax
jne 0x29be
leaq 0xf633(%rip), %rax      # 0x121e0
cmpl %r15d, (%rax)
jne 0x297b
cmpq $0x0, 0x10(%rsp)
je 0x297b
leaq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x3fbc
testq %rax, %rax
jne 0x2ce1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2d26
leaq 0x94f3(%rip), %rdi      # 0xc0e2
jmp 0x2e79
leaq 0x94d2(%rip), %rdi      # 0xc0cd
jmp 0x2c04
leaq 0x94b2(%rip), %rdi      # 0xc0b6
movq %r12, %rsi
xorl %eax, %eax
callq 0x3d5b
callq 0x20a0
movl $0x0, (%rax)
callq 0x2ea3
movq 0xf3d3(%rip), %rax      # 0x11ff8
movq (%rax), %rcx
leaq 0x9469(%rip), %rdi      # 0xc098
movl $0x1d, %esi
movl $0x1, %edx
callq 0x2330
xorl %edi, %edi
callq 0x2310
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2cc5
leaq 0x9414(%rip), %rdi      # 0xc06a
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3d5b
jmp 0x2e99
leaq 0x93c9(%rip), %rdi      # 0xc038
leaq 0x93d1(%rip), %rsi      # 0xc047
leaq 0x93d1(%rip), %rcx      # 0xc04e
movl $0x9b, %edx
callq 0x2190
leaq 0x93aa(%rip), %rdi      # 0xc038
leaq 0x93b2(%rip), %rsi      # 0xc047
leaq 0x93b2(%rip), %rcx      # 0xc04e
movl $0x8f, %edx
callq 0x2190
leaq 0x938b(%rip), %rdi      # 0xc038
leaq 0x9393(%rip), %rsi      # 0xc047
leaq 0x9393(%rip), %rcx      # 0xc04e
movl $0x95, %edx
callq 0x2190
movq %rax, %rbx
leaq 0x939b(%rip), %rdi      # 0xc06a
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3c3c
jmp 0x2e93
movq %rax, %rbx
movq 0x28(%rsp), %r15
testq %r15, %r15
je 0x2cfe
movq %r15, %rdi
callq 0x2140
testl %eax, %eax
jne 0x2e0a
xorl %edi, %edi
xorl %esi, %esi
callq 0x3e80
testq %rax, %rax
jne 0x2d35
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e3a
leaq 0x93ed(%rip), %rdi      # 0xc10e
jmp 0x2e79
movq %rax, %rbx
leaq 0x93b2(%rip), %rdi      # 0xc0e2
jmp 0x2e8c
movq %rax, %r14
xorl %eax, %eax
testq %r15, %r15
setne %al
movl %eax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x3980
testl %eax, %eax
jne 0x2e27
movq 0x50(%rsp), %rdi
leaq 0x17c(%rip), %rcx       # 0x2ee7
leaq 0x40(%rsp), %r8
movq %r14, %rsi
movq %r14, %rdx
callq 0x42f1
testl %eax, %eax
jne 0x2e68
leaq 0x58(%rsp), %rdi
callq 0x3980
testl %eax, %eax
jne 0x2e27
cmpl $0x0, 0x1c(%rsp)
je 0x2de3
movq 0xf255(%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 0x9237(%rip), %xmm0     # 0xc008
addsd %xmm1, %xmm0
leaq 0x937d(%rip), %rsi      # 0xc159
movb $0x1, %al
callq 0x2210
movq %r14, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x4105
movq 0x10(%rsp), %rdi
callq 0x2040
movq %r15, %rdi
callq 0x2040
jmp 0x2c3e
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e46
leaq 0x92e9(%rip), %rdi      # 0xc104
movq %r15, %rsi
xorl %eax, %eax
callq 0x3d5b
jmp 0x2e99
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e5c
leaq 0x92e6(%rip), %rdi      # 0xc11e
jmp 0x2e79
movq %rax, %rbx
leaq 0x92ca(%rip), %rdi      # 0xc10e
jmp 0x2e8c
movq %rax, %rbx
leaq 0x92b4(%rip), %rdi      # 0xc104
movq %r15, %rsi
xorl %eax, %eax
callq 0x3c3c
jmp 0x2e93
movq %rax, %rbx
leaq 0x92b8(%rip), %rdi      # 0xc11e
jmp 0x2e8c
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e82
leaq 0x92b3(%rip), %rdi      # 0xc12c
xorl %eax, %eax
callq 0x3d5b
jmp 0x2e99
movq %rax, %rbx
leaq 0x92a0(%rip), %rdi      # 0xc12c
xorl %eax, %eax
callq 0x3c3c
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x2310