// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs/main.c
// Function: main
int
main(int argc, char * argv[])
{
	/* State variables. */
	struct storage_state * S;
	struct dispatch_state * D;
	int s;

	/* Command-line parameters. */
	char * opt_s = NULL;
	char * opt_d = NULL;
	size_t opt_b = (size_t)(-1);
	size_t opt_n = 16;
	char * opt_p = NULL;
	int opt_1 = 0;
	long opt_l = 0;
	int opt_L = 0;

	/* Working variables. */
	struct sock_addr ** sas;
	const char * ch;

	WARNP_INIT;

	/* Parse the command line. */
	while ((ch = GETOPT(argc, argv)) != NULL) {
		GETOPT_SWITCH(ch) {
		GETOPT_OPTARG("-b"):
			if (opt_b != (size_t)(-1))
				usage();
			if (PARSENUM(&opt_b, optarg, 512, 128 * 1024)) {
				warn0("Block size must be in [2^9, 2^17]");
				goto err1;
			}
			break;
		GETOPT_OPTARG("-d"):
			if (opt_d != NULL)
				usage();
			if ((opt_d = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-l"):
			if (opt_l != 0)
				usage();
			if (PARSENUM(&opt_l, optarg, 0, 999999999)) {
				warn0("Read latency must be in [0, 10^9) ns");
				goto err1;
			}
			break;
		GETOPT_OPT("-L"):
			if (opt_L != 0)
				usage();
			opt_L = 1;
			break;
		GETOPT_OPTARG("-n"):
			if (opt_n != 16)
				usage();
			if (PARSENUM(&opt_n, optarg, 1, 1000)) {
				warn0("Number of readers must be in [1, 1000]");
				goto err1;
			}
			break;
		GETOPT_OPTARG("-p"):
			if (opt_p != NULL)
				usage();
			if ((opt_p = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-s"):
			if (opt_s != NULL)
				usage();
			if ((opt_s = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPT("--version"):
			fprintf(stderr, "kivaloo-lbs @VERSION@\n");
			exit(0);
		GETOPT_OPT("-1"):
			if (opt_1 != 0)
				usage();
			opt_1 = 1;
			break;
		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_s == NULL)
		usage();
	if (opt_d == NULL)
		usage();
	if (opt_b == (size_t)(-1))
		usage();

	/* Resolve the listening address. */
	if ((sas = sock_resolve(opt_s)) == NULL) {
		warnp("Error resolving socket address: %s", opt_s);
		goto err1;
	}
	if (sas[0] == NULL) {
		warn0("No addresses found for %s", opt_s);
		goto err2;
	}

	/* Create and bind a socket, and mark it as listening. */
	if (sas[1] != NULL)
		warn0("Listening on first of multiple addresses found for %s",
		    opt_s);
	if ((s = sock_listener(sas[0])) == -1)
		goto err2;

	/* Initialize the storage back-end. */
	if ((S = storage_init(opt_d, opt_b, opt_l, opt_L)) == NULL) {
		warnp("Error initializing storage directory: %s", opt_d);
		goto err3;
	}

	/* Daemonize and write pid. */
	if (opt_p == NULL) {
		if (asprintf(&opt_p, "%s.pid", opt_s) == -1) {
			warnp("asprintf");
			goto err4;
		}
	}
	if (daemonize(opt_p)) {
		warnp("Failed to daemonize");
		goto err4;
	}

	/* Initialize the dispatcher. */
	if ((D = dispatch_init(S, opt_b, opt_n)) == NULL) {
		warnp("Error initializing work dispatcher");
		goto err4;
	}

	/* Handle connections, one at once. */
	do {
		/* Get a connection and perform associated initialization. */
		if (dispatch_accept(D, s)) {
			warnp("Error accepting new connection");
			goto err5;
		}

		/* Loop until the connection dies. */
		do {
			if (events_run()) {
				warnp("Error running event loop");
				goto err5;
			}
		} while (dispatch_alive(D));

		/* Clean up the connection. */
		if (dispatch_close(D))
			goto err5;
	} while (opt_1 == 0);

	if (dispatch_done(D)) {
		warnp("Failed to shut down dispatcher");
		goto err4;
	}

	/* We're done with the storage state. */
	storage_done(S);

	/* Close the listening socket. */
	if (close(s))
		warnp("close");

	/* Free the address structures. */
	sock_addr_freelist(sas);

	/* Free option strings. */
	free(opt_s);
	free(opt_p);
	free(opt_d);

	/* Success! */
	exit(0);

err5:
	dispatch_done(D);
err4:
	storage_done(S);
err3:
	if (close(s))
		warnp("close");
err2:
	sock_addr_freelist(sas);
err1:
	free(opt_s);
	free(opt_p);
	free(opt_d);

	/* Failure! */
	exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
andq $0x0, 0x20(%rsp)
movl %edi, 0x38(%rsp)
movq %rsi, 0x58(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x26a6
callq 0x9cbc
movq $0x0, 0x10(%rsp)
pushq $0x10
popq %rax
movq %rax, 0x40(%rsp)
pushq $-0x1
popq %rax
movq %rax, 0x48(%rsp)
leaq 0x21152(%rip), %r12     # 0x23818
pushq $0x1
popq %rbp
leaq 0x9a02(%rip), %r15      # 0xc0d2
pushq $0x75
popq %r13
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movl 0x38(%rsp), %edi
movq 0x58(%rsp), %rsi
callq 0x7f8c
testq %rax, %rax
je 0x2b52
movq %rax, %rbx
movq $0x3d, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x50(%rsp)
movl $0x0, 0x3c(%rsp)
cmpl $0x0, (%r12)
je 0x2744
movq %rbx, %rdi
callq 0x83a1
addq 0x8(%rsp), %rax
jmp 0x2752
movq 0x50(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x50(%rsp)
cmpq $0x3e, %rax
je 0x2868
cmpq $0x46, %rax
je 0x28a1
cmpq $0x4c, %rax
je 0x280b
cmpq $0x54, %rax
je 0x282a
cmpq $0x59, %rax
je 0x28d5
cmpq $0x61, %rax
je 0x27ec
cmpq $0x67, %rax
je 0x2849
cmpq $0x6d, %rax
je 0x28bd
cmpq $0x70, %rax
je 0x28f7
cmpq $0x75, %rax
je 0x2884
cmpq $0x78, %rax
je 0x291d
cmpl $0x0, (%r12)
jne 0x2b2b
cmpl $0x0, 0x3c(%rsp)
jne 0x272e
pushq $0x78
popq %rdi
subq 0x8(%rsp), %rdi
callq 0x870e
movl $0x1, 0x3c(%rsp)
jmp 0x272e
cmpl $0x0, (%r12)
jne 0x2a80
pushq $0x61
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x98c6(%rip), %rdi      # 0xc0cc
jmp 0x28eb
cmpl $0x0, (%r12)
jne 0x2977
pushq $0x4c
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x9852(%rip), %rdi      # 0xc077
jmp 0x28eb
cmpl $0x0, (%r12)
jne 0x29db
pushq $0x54
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x985b(%rip), %rdi      # 0xc09f
jmp 0x2911
cmpl $0x0, (%r12)
jne 0x2aae
pushq $0x67
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x986c(%rip), %rdi      # 0xc0cf
jmp 0x28eb
cmpl $0x0, (%r12)
jne 0x29ef
pushq $0x3e
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x97af(%rip), %rdi      # 0xc031
jmp 0x28eb
cmpl $0x0, (%r12)
jne 0x2b34
movq %r13, %rdi
subq 0x8(%rsp), %rdi
callq 0x8683
jmp 0x272e
cmpl $0x0, (%r12)
jne 0x2a3e
pushq $0x46
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x979b(%rip), %rdi      # 0xc056
jmp 0x28eb
cmpl $0x0, (%r12)
jne 0x2b08
pushq $0x6d
popq %rsi
subq 0x8(%rsp), %rsi
movq %r15, %rdi
jmp 0x2911
cmpl $0x0, (%r12)
jne 0x292a
pushq $0x59
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x97b7(%rip), %rdi      # 0xc0a2
movl %ebp, %edx
callq 0x84b9
jmp 0x272e
cmpl $0x0, (%r12)
jne 0x2a6c
pushq $0x70
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x97e2(%rip), %rdi      # 0xc0f3
xorl %edx, %edx
callq 0x84b9
jmp 0x272e
movl $0x1, (%r12)
jmp 0x26f6
leaq 0x20edf(%rip), %rax     # 0x23810
movq (%rax), %r14
testq %r14, %r14
je 0x2bcc
cmpq $0x10, 0x40(%rsp)
jne 0x2b84
callq 0x20a0
movq %rax, %rbx
andl $0x0, (%rax)
movl $0x3e8, %edx            # imm = 0x3E8
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x3074
movq %rax, 0x40(%rsp)
cmpl $0x0, (%rbx)
je 0x26f6
jmp 0x2c66
leaq 0x20e92(%rip), %rax     # 0x23810
movq (%rax), %r14
testq %r14, %r14
je 0x2be5
cmpq $0x0, 0x30(%rsp)
jne 0x2b84
callq 0x20a0
movq %rax, %rbx
andl $0x0, (%rax)
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0x2050
movq %rax, 0x30(%rsp)
movq 0x60(%rsp), %rax
cmpq %r14, %rax
je 0x29c8
cmpb $0x0, (%rax)
je 0x2ae8
pushq $0x16
popq %rax
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
je 0x26f6
jmp 0x2c6f
cmpl $0x0, 0x28(%rsp)
movl %ebp, 0x28(%rsp)
je 0x26f6
jmp 0x2b84
leaq 0x20e1a(%rip), %rax     # 0x23810
movq (%rax), %r14
testq %r14, %r14
je 0x2bfe
cmpq $-0x1, 0x48(%rsp)
jne 0x2b84
callq 0x20a0
movq %rax, %rbx
andl $0x0, (%rax)
movl $0x200, %esi            # imm = 0x200
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
callq 0x3074
movq %rax, 0x48(%rsp)
cmpl $0x0, (%rbx)
je 0x26f6
jmp 0x2c78
leaq 0x20dcb(%rip), %rax     # 0x23810
movq (%rax), %r14
testq %r14, %r14
je 0x2c17
cmpq $0x0, 0x10(%rsp)
jne 0x2b84
movq %r14, %rdi
callq 0x2510
movq %rax, 0x10(%rsp)
jmp 0x2ada
cmpl $0x0, 0x2c(%rsp)
movl %ebp, 0x2c(%rsp)
je 0x26f6
jmp 0x2b84
leaq 0x20d89(%rip), %rax     # 0x23810
movq (%rax), %r14
testq %r14, %r14
je 0x2c30
cmpq $0x0, 0x20(%rsp)
jne 0x2b84
movq %r14, %rdi
callq 0x2510
movq %rax, 0x20(%rsp)
jmp 0x2ada
leaq 0x20d5b(%rip), %rax     # 0x23810
movq (%rax), %r14
testq %r14, %r14
je 0x2c49
cmpq $0x0, 0x18(%rsp)
jne 0x2b84
movq %r14, %rdi
callq 0x2510
movq %rax, 0x18(%rsp)
testq %rax, %rax
jne 0x26f6
jmp 0x2b89
cmpq $0x3b9aca00, 0x30(%rsp) # imm = 0x3B9ACA00
jb 0x29cd
pushq $0x22
popq %rax
movq $0x0, 0x30(%rsp)
jmp 0x29cb
movq 0x104e9(%rip), %rax     # 0x12ff8
movq (%rax), %rcx
leaq 0x95c3(%rip), %rdi      # 0xc0dc
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x24e0
xorl %edi, %edi
callq 0x24c0
leaq 0x95db(%rip), %rdi      # 0xc10d
jmp 0x2b3b
leaq 0x95bb(%rip), %rdi      # 0xc0f6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
callq 0x3032
leaq 0x10a7f(%rip), %rax     # 0x135d8
movl 0x38(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x2b84
movq 0x18(%rsp), %r13
testq %r13, %r13
je 0x2b84
movq 0x10(%rsp), %r12
testq %r12, %r12
je 0x2b84
movq 0x48(%rsp), %r15
cmpq $-0x1, %r15
jne 0x2cb5
callq 0x3032
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2bac
leaq 0x94bf(%rip), %rdi      # 0xc059
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x9ec8
jmp 0x2cad
movq %rax, %r15
leaq 0x94a3(%rip), %rdi      # 0xc059
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r15)
jmp 0x2cad
leaq 0x9431(%rip), %rdi      # 0xc004
leaq 0x9439(%rip), %rsi      # 0xc013
leaq 0x9439(%rip), %rcx      # 0xc01a
pushq $0x59
jmp 0x2c60
leaq 0x9418(%rip), %rdi      # 0xc004
leaq 0x9420(%rip), %rsi      # 0xc013
leaq 0x9420(%rip), %rcx      # 0xc01a
pushq $0x4c
jmp 0x2c60
leaq 0x93ff(%rip), %rdi      # 0xc004
leaq 0x9407(%rip), %rsi      # 0xc013
leaq 0x9407(%rip), %rcx      # 0xc01a
pushq $0x3e
jmp 0x2c60
leaq 0x93e6(%rip), %rdi      # 0xc004
leaq 0x93ee(%rip), %rsi      # 0xc013
leaq 0x93ee(%rip), %rcx      # 0xc01a
pushq $0x46
jmp 0x2c60
leaq 0x93cd(%rip), %rdi      # 0xc004
leaq 0x93d5(%rip), %rsi      # 0xc013
leaq 0x93d5(%rip), %rcx      # 0xc01a
pushq $0x61
jmp 0x2c60
leaq 0x93b4(%rip), %rdi      # 0xc004
leaq 0x93bc(%rip), %rsi      # 0xc013
leaq 0x93bc(%rip), %rcx      # 0xc01a
pushq $0x67
popq %rdx
callq 0x2220
leaq 0x9438(%rip), %rdi      # 0xc0a5
jmp 0x2c7f
leaq 0x9404(%rip), %rdi      # 0xc07a
jmp 0x2c7f
leaq 0x93b5(%rip), %rdi      # 0xc034
xorl %eax, %eax
callq 0x9ec8
andl $0x0, (%rbx)
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x2040
movq 0x20(%rsp), %rdi
callq 0x2040
movq %r12, %rdi
callq 0x2040
pushq $0x1
popq %rdi
callq 0x24c0
movq %r13, %rdi
callq 0x8e44
testq %rax, %rax
jne 0x2cdf
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2d08
leaq 0x944f(%rip), %rdi      # 0xc122
movq %r13, %rsi
xorl %eax, %eax
callq 0x9ec8
jmp 0x2c93
movq %rax, %rbx
movq (%rax), %rdi
testq %rdi, %rdi
jne 0x2d24
leaq 0x9454(%rip), %rdi      # 0xc145
movq %r13, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
jmp 0x2f9b
movq %rax, %rbx
leaq 0x9410(%rip), %rdi      # 0xc122
movq %r13, %rsi
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%rbx)
jmp 0x2c93
cmpq $0x0, 0x8(%rbx)
je 0x2d47
leaq 0x942d(%rip), %rdi      # 0xc15f
movq %r13, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
movq (%rbx), %rdi
callq 0x9475
cmpl $-0x1, %eax
je 0x2f9b
movl %eax, %ebp
movq %r12, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %rdx
movl 0x28(%rsp), %ecx
callq 0x4590
testq %rax, %rax
jne 0x2d90
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2dcf
leaq 0x9414(%rip), %rdi      # 0xc195
movq %r12, %rsi
xorl %eax, %eax
callq 0x9ec8
jmp 0x2f61
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0x2df1
leaq 0x941a(%rip), %rsi      # 0xc1be
leaq 0x20(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x7cb4
cmpl $-0x1, %eax
jne 0x2dec
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2f03
leaq 0x93f8(%rip), %rdi      # 0xc1c5
jmp 0x2e45
movq %rax, %r14
leaq 0x93bc(%rip), %rdi      # 0xc195
movq %r12, %rsi
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r14)
jmp 0x2f61
movq 0x20(%rsp), %rdi
callq 0x7da8
testl %eax, %eax
jne 0x2e30
movq %r14, %rdi
movq %r15, %rsi
movq 0x40(%rsp), %rdx
callq 0x30fc
testq %rax, %rax
jne 0x2e51
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2f1a
leaq 0x93be(%rip), %rdi      # 0xc1e2
xorl %eax, %eax
callq 0x9ec8
jmp 0x2f4f
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2edd
leaq 0x9389(%rip), %rdi      # 0xc1ce
xorl %eax, %eax
callq 0x9ec8
jmp 0x2f59
movq %rax, %r15
movl 0x2c(%rsp), %r12d
movq %r15, %rdi
movl %ebp, %esi
callq 0x354d
testl %eax, %eax
jne 0x2fa8
callq 0x5cec
testl %eax, %eax
jne 0x2ee9
movq %r15, %rdi
callq 0x373f
testl %eax, %eax
jne 0x2e6b
movq %r15, %rdi
callq 0x375b
testl %eax, %eax
jne 0x2f47
testl %r12d, %r12d
je 0x2e59
movq %r15, %rdi
callq 0x3809
testl %eax, %eax
jne 0x2fbe
movq %r14, %rdi
callq 0x4c5f
movl %ebp, %edi
callq 0x2240
testl %eax, %eax
je 0x3007
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2ff2
leaq 0xa59b(%rip), %rdi      # 0xd46c
xorl %eax, %eax
callq 0x9ec8
jmp 0x3007
movq %rax, %r15
leaq 0x92e7(%rip), %rdi      # 0xc1ce
jmp 0x2f0d
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2f31
leaq 0x932a(%rip), %rdi      # 0xc224
xorl %eax, %eax
callq 0x9ec8
jmp 0x2f47
movq %rax, %r15
leaq 0x92b8(%rip), %rdi      # 0xc1c5
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r15)
jmp 0x2f59
movq %rax, %r15
leaq 0x92be(%rip), %rdi      # 0xc1e2
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r15)
jmp 0x2f4f
movq %rax, %r12
leaq 0x92e9(%rip), %rdi      # 0xc224
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r12)
movq %r15, %rdi
callq 0x3809
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
movq %r14, %rdi
callq 0x4c5f
movl %ebp, %edi
callq 0x2240
testl %eax, %eax
je 0x2f9b
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2f86
leaq 0xa4ef(%rip), %rdi      # 0xd46c
xorl %eax, %eax
callq 0x9ec8
jmp 0x2f9b
movq %rax, %r14
leaq 0xa4dc(%rip), %rdi      # 0xd46c
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r14)
movq %rbx, %rdi
callq 0x9443
jmp 0x2c93
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2fd4
leaq 0x924c(%rip), %rdi      # 0xc205
jmp 0x2efa
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2fe3
leaq 0x926e(%rip), %rdi      # 0xc23d
jmp 0x2e24
movq %rax, %r12
leaq 0x9227(%rip), %rdi      # 0xc205
jmp 0x2f3b
movq %rax, %r15
leaq 0x9250(%rip), %rdi      # 0xc23d
jmp 0x2f24
movq %rax, %r14
leaq 0xa470(%rip), %rdi      # 0xd46c
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r14)
movq %rbx, %rdi
callq 0x9443
movq 0x18(%rsp), %rdi
callq 0x2040
movq 0x20(%rsp), %rdi
callq 0x2040
movq 0x10(%rsp), %rdi
callq 0x2040
jmp 0x2b24