// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/lbs-s3/main.c
// Function: main
int
main(int argc, char * argv[])
{
	/* State variables. */
	struct wire_requestqueue * Q_S3;
	struct deleteto * deleter;
	struct s3state * S;
	struct dispatch_state * D;
	int s;
	int s_t;

	/* Command-line parameters. */
	char * opt_s = NULL;
	char * opt_t = NULL;
	size_t opt_b = (size_t)(-1);
	char * opt_B = NULL;
	char * opt_p = NULL;
	int opt_1 = 0;

	/* Working variables. */
	struct sock_addr ** sas_s;
	struct sock_addr ** sas_t;
	const char * ch;

	WARNP_INIT;

	/* Parse the command line. */
	while ((ch = GETOPT(argc, argv)) != NULL) {
		GETOPT_SWITCH(ch) {
		GETOPT_OPTARG("-B"):
			if (opt_B != NULL)
				usage();
			if ((opt_B = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		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]");
				exit(1);
			}
			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_OPTARG("-t"):
			if (opt_t != NULL)
				usage();
			if ((opt_t = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPT("--version"):
			fprintf(stderr, "kivaloo-lbs-s3 @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_t == NULL)
		usage();
	if (opt_B == NULL)
		usage();
	if (opt_b == (size_t)(-1))
		usage();

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

	/* Resolve the target (S3 daemon) address. */
	if ((sas_t = sock_resolve(opt_t)) == NULL) {
		warnp("Error resolving socket address: %s", opt_t);
		exit(1);
	}
	if (sas_t[0] == NULL) {
		warn0("No addresses found for %s", opt_t);
		exit(1);
	}

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

	/* Connect to the S3 daemon. */
	if ((s_t = sock_connect(sas_t)) == -1)
		exit(1);

	/* Create a queue of requests to the S3 daemon. */
	if ((Q_S3 = wire_requestqueue_init(s_t)) == NULL) {
		warnp("Cannot create S3 request queue");
		exit(1);
	}

	/* Create a deleter state. */
	if ((deleter = deleteto_init(Q_S3, opt_B)) == NULL) {
		warnp("Error initializing garbage collection for"
		    " S3 bucket: %s", opt_B);
		exit(1);
	}

	/* Initialize the S3 state. */
	if ((S = s3state_init(Q_S3, opt_B, opt_b, deleter)) == NULL) {
		warnp("Error initializing from S3 bucket: %s", opt_B);
		exit(1);
	}

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

	/* Handle connections, one at once. */
	do {
		/* Accept a connection. */
		if ((D = dispatch_accept(S, s)) == NULL)
			exit(1);

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

		/* Close and free the connection. */
		if (dispatch_done(D))
			exit(1);
	} while (opt_1 == 0);

	/* Clean up the S3 state. */
	s3state_free(S);

	/*
	 * Shut down deleting (cleanly if possible, but we don't care if we
	 * encounter an error at this point).
	 */
	deleteto_stop(deleter);

	/* Shut down the S3 request queue. */
	wire_requestqueue_destroy(Q_S3);
	wire_requestqueue_free(Q_S3);

	/* Close sockets. */
	if (close(s_t))
		warnp("close");
	if (close(s))
		warnp("close");

	/* Free socket addresses. */
	sock_addr_freelist(sas_t);
	sock_addr_freelist(sas_s);

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edi, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq %rsi, 0x50(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x2999
callq 0x97f8
movl 0x20(%rsp), %edi
movq 0x50(%rsp), %rsi
callq 0x7a6c
testq %rax, %rax
je 0x2d9d
movq %rax, %rbx
movq $0x0, 0x30(%rsp)
movq $-0x1, 0x18(%rsp)
leaq 0x21e2c(%rip), %rbp     # 0x247f8
leaq 0xa65e(%rip), %r15      # 0xd031
leaq 0xa6a3(%rip), %r13      # 0xd07d
leaq 0xa69f(%rip), %r12      # 0xd080
leaq 0xbf27(%rip), %r14      # 0xe90f
movq $0x0, 0x10(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x40, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x4c(%rsp)
cmpl $0x0, (%rbp)
je 0x2a36
movq %rbx, %rdi
callq 0x7d97
addq 0x8(%rsp), %rax
jmp 0x2a44
movq 0x58(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x58(%rsp)
cmpq $0x5a, %rax
jle 0x2a7f
cmpq $0x63, %rax
jle 0x2ab9
cmpq $0x64, %rax
je 0x2b6e
cmpq $0x69, %rax
jne 0x2b91
cmpl $0x0, (%rbp)
jne 0x3087
movl $0x69, %edi
subq 0x8(%rsp), %rdi
callq 0x7f6b
jmp 0x2a21
cmpq $0x4e, %rax
jg 0x2ae5
cmpq $0x41, %rax
je 0x2b2b
cmpq $0x47, %rax
jne 0x2b97
cmpl $0x0, (%rbp)
jne 0x2c99
movl $0x47, %esi
subq 0x8(%rsp), %rsi
leaq 0xa59e(%rip), %rdi      # 0xd052
jmp 0x2b5f
cmpq $0x5b, %rax
je 0x2b12
cmpq $0x61, %rax
jne 0x2b97
cmpl $0x0, (%rbp)
jne 0x30a8
movl $0x61, %esi
subq 0x8(%rsp), %rsi
movq %r12, %rdi
jmp 0x2b85
cmpq $0x4f, %rax
je 0x2b44
cmpq $0x55, %rax
jne 0x2b97
cmpl $0x0, (%rbp)
jne 0x2c46
movl $0x55, %esi
subq 0x8(%rsp), %rsi
leaq 0xa56a(%rip), %rdi      # 0xd07a
jmp 0x2b5f
cmpl $0x0, (%rbp)
jne 0x2bd4
movl $0x5b, %esi
subq 0x8(%rsp), %rsi
movq %r13, %rdi
jmp 0x2b5f
cmpl $0x0, (%rbp)
jne 0x2d25
movl $0x41, %esi
subq 0x8(%rsp), %rsi
movq %r15, %rdi
jmp 0x2b5f
cmpl $0x0, (%rbp)
jne 0x2c0d
movl $0x4f, %esi
subq 0x8(%rsp), %rsi
leaq 0xa518(%rip), %rdi      # 0xd077
movl $0x1, %edx
callq 0x7e54
jmp 0x2a21
cmpl $0x0, (%rbp)
jne 0x2c7f
movl $0x64, %esi
subq 0x8(%rsp), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x7e54
jmp 0x2a21
cmpq $0x6c, %rax
je 0x2bc8
cmpl $0x0, (%rbp)
jne 0x307e
cmpl $0x0, 0x4c(%rsp)
jne 0x2a21
movl $0x6c, %edi
subq 0x8(%rsp), %rdi
callq 0x7fab
movl $0x1, 0x4c(%rsp)
jmp 0x2a21
movl $0x1, (%rbp)
jmp 0x2d62
leaq 0x21c15(%rip), %rax     # 0x247f0
cmpq $0x0, (%rax)
je 0x3162
cmpq $0x0, 0x40(%rsp)
jne 0x30ad
leaq 0x21bf8(%rip), %rax     # 0x247f0
movq (%rax), %r15
movq %r15, %rdi
callq 0x2390
movq %rax, 0x40(%rsp)
jmp 0x2d59
leaq 0x21bdc(%rip), %rax     # 0x247f0
cmpq $0x0, (%rax)
je 0x31a0
cmpq $0x0, 0x28(%rsp)
jne 0x30ad
leaq 0x21bbf(%rip), %rax     # 0x247f0
movq (%rax), %r15
movq %r15, %rdi
callq 0x2390
movq %rax, 0x28(%rsp)
jmp 0x2d59
leaq 0x21ba3(%rip), %rax     # 0x247f0
cmpq $0x0, (%rax)
je 0x3181
cmpq $0x0, 0x10(%rsp)
jne 0x30ad
leaq 0x21b86(%rip), %rax     # 0x247f0
movq (%rax), %r15
movq %r15, %rdi
callq 0x2390
movq %rax, 0x10(%rsp)
jmp 0x2d59
cmpl $0x0, 0x30(%rsp)
movl $0x1, %eax
movq %rax, 0x30(%rsp)
je 0x2d62
jmp 0x30ad
leaq 0x21b50(%rip), %rax     # 0x247f0
cmpq $0x0, (%rax)
je 0x3124
cmpq $-0x1, 0x18(%rsp)
jne 0x30ad
callq 0x20a0
movq %rax, %rbx
movl $0x0, (%rax)
leaq 0x21b25(%rip), %rax     # 0x247f0
movq (%rax), %r15
testq %r15, %r15
je 0x3105
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0x2310
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %rcx
movl $0x16, %eax
cmpq %r15, %rcx
je 0x2d19
cmpb $0x0, (%rcx)
jne 0x2d19
movq 0x18(%rsp), %rax
leaq -0x20001(%rax), %rcx
movl $0x22, %eax
cmpq $-0x1fe02, %rcx         # imm = 0xFFFE01FE
ja 0x2d1b
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
je 0x2d62
jmp 0x30f2
leaq 0x21ac4(%rip), %rax     # 0x247f0
cmpq $0x0, (%rax)
je 0x3143
cmpq $0x0, 0x38(%rsp)
jne 0x30ad
leaq 0x21aa7(%rip), %rax     # 0x247f0
movq (%rax), %r15
movq %r15, %rdi
callq 0x2390
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x30b2
movl 0x20(%rsp), %edi
movq 0x50(%rsp), %rsi
callq 0x7a6c
movq %rax, %rbx
testq %rax, %rax
leaq 0xa2b4(%rip), %r15      # 0xd031
jne 0x2a03
cmpl $0x0, 0x30(%rsp)
sete %r15b
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %r14
movq 0x10(%rsp), %r12
jmp 0x2db1
movb $0x1, %r15b
movq $-0x1, 0x18(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
leaq 0x11790(%rip), %rax     # 0x14548
movl 0x20(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x30ad
testq %r12, %r12
je 0x30ad
testq %r14, %r14
je 0x30ad
testq %rbx, %rbx
je 0x30ad
cmpq $-0x1, 0x18(%rsp)
je 0x30ad
movq %r12, %rdi
callq 0x87d0
testq %rax, %rax
je 0x31bf
movq %rax, %r13
cmpq $0x0, (%rax)
je 0x31dc
movq %r14, %rdi
callq 0x87d0
testq %rax, %rax
je 0x31e8
cmpq $0x0, (%rax)
je 0x31ff
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x8(%r13)
je 0x2e4c
leaq 0xa2d6(%rip), %rdi      # 0xd10d
movq %r12, %rsi
xorl %eax, %eax
callq 0x9997
callq 0x20a0
movl $0x0, (%rax)
movq (%r13), %rdi
callq 0x8f2b
cmpl $-0x1, %eax
je 0x3074
movl %eax, %ebp
movq 0x20(%rsp), %rdi
callq 0x90ed
cmpl $-0x1, %eax
je 0x3074
movq %r13, 0x50(%rsp)
movq %r12, 0x10(%rsp)
movl %eax, 0x30(%rsp)
movl %eax, %edi
callq 0xafc4
testq %rax, %rax
je 0x3220
movq %rax, %r12
movq %r14, 0x40(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3d84
testq %rax, %rax
je 0x3236
movq %rax, %r13
movq %r12, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x39b4
testq %rax, %rax
je 0x324c
movq %rax, %r14
cmpq $0x0, 0x28(%rsp)
jne 0x2ef8
leaq 0xa2e2(%rip), %rsi      # 0xd1c0
leaq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x7778
cmpl $-0x1, %eax
je 0x32e3
movq %rbx, 0x38(%rsp)
movq 0x28(%rsp), %rdi
callq 0x787c
testl %eax, %eax
jne 0x326f
movq %r14, %rdi
movl %ebp, %esi
callq 0x334c
movq %rax, %rbx
testq %rax, %rax
je 0x3074
callq 0x5120
testl %eax, %eax
jne 0x3043
movq %rbx, %rdi
callq 0x3586
testl %eax, %eax
jne 0x2f25
movq %rbx, %rdi
callq 0x35a4
testl %eax, %eax
jne 0x3074
testb %r15b, %r15b
jne 0x2f0f
movq %r14, %rdi
callq 0x3d46
movq %r13, %rdi
callq 0x4129
movq %r12, %rdi
callq 0xb689
movq %r12, %rdi
callq 0xb69d
movl 0x30(%rsp), %edi
callq 0x21c0
testl %eax, %eax
movq 0x40(%rsp), %r14
movq 0x10(%rsp), %r15
movq 0x50(%rsp), %r12
je 0x2fc0
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2fb2
movq %rax, %rbx
leaq 0xaf69(%rip), %rdi      # 0xdf0c
xorl %eax, %eax
callq 0x9878
movl $0x0, (%rbx)
jmp 0x2fc0
leaq 0xaf53(%rip), %rdi      # 0xdf0c
xorl %eax, %eax
callq 0x9997
movl %ebp, %edi
callq 0x21c0
testl %eax, %eax
je 0x2ffc
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2fee
movq %rax, %rbx
leaq 0xaf2d(%rip), %rdi      # 0xdf0c
xorl %eax, %eax
callq 0x9878
movl $0x0, (%rbx)
jmp 0x2ffc
leaq 0xaf17(%rip), %rdi      # 0xdf0c
xorl %eax, %eax
callq 0x9997
movq 0x20(%rsp), %rdi
callq 0x8ee7
movq %r12, %rdi
callq 0x8ee7
movq %r15, %rdi
callq 0x2040
movq 0x28(%rsp), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq 0x38(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x305d
leaq 0xa190(%rip), %rdi      # 0xd1e4
xorl %eax, %eax
callq 0x9997
jmp 0x3074
movq %rax, %rbx
leaq 0xa17d(%rip), %rdi      # 0xd1e4
xorl %eax, %eax
callq 0x9878
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x2350
leaq 0xa036(%rip), %rdi      # 0xd0bb
jmp 0x308e
leaq 0xa016(%rip), %rdi      # 0xd0a4
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9997
callq 0x20a0
movl $0x0, (%rax)
callq 0x3308
callq 0x23f0
callq 0x3308
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x30d2
leaq 0x9f71(%rip), %rdi      # 0xd034
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x9997
jmp 0x3074
movq %rax, %r14
leaq 0x9f58(%rip), %rdi      # 0xd034
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x9878
movl $0x0, (%r14)
jmp 0x3074
leaq 0x9f5c(%rip), %rdi      # 0xd055
xorl %eax, %eax
callq 0x9997
jmp 0x306e
leaq 0xafac(%rip), %rdi      # 0xe0b8
leaq 0xa174(%rip), %rsi      # 0xd287
leaq 0xa18c(%rip), %rcx      # 0xd2a6
movl $0xbb, %edx
callq 0x21a0
leaq 0x9ed9(%rip), %rdi      # 0xd004
leaq 0x9ee1(%rip), %rsi      # 0xd013
leaq 0x9ee1(%rip), %rcx      # 0xd01a
movl $0x47, %edx
callq 0x21a0
leaq 0x9eba(%rip), %rdi      # 0xd004
leaq 0x9ec2(%rip), %rsi      # 0xd013
leaq 0x9ec2(%rip), %rcx      # 0xd01a
movl $0x41, %edx
callq 0x21a0
leaq 0x9e9b(%rip), %rdi      # 0xd004
leaq 0x9ea3(%rip), %rsi      # 0xd013
leaq 0x9ea3(%rip), %rcx      # 0xd01a
movl $0x5b, %edx
callq 0x21a0
leaq 0x9e7c(%rip), %rdi      # 0xd004
leaq 0x9e84(%rip), %rsi      # 0xd013
leaq 0x9e84(%rip), %rcx      # 0xd01a
movl $0x55, %edx
callq 0x21a0
leaq 0x9e5d(%rip), %rdi      # 0xd004
leaq 0x9e65(%rip), %rsi      # 0xd013
leaq 0x9e65(%rip), %rcx      # 0xd01a
movl $0x4f, %edx
callq 0x21a0
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3285
leaq 0x9efc(%rip), %rdi      # 0xd0d0
movq %r12, %rsi
jmp 0x3263
leaq 0x9f10(%rip), %rdi      # 0xd0f3
movq %r12, %rsi
jmp 0x3209
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3294
leaq 0x9ed3(%rip), %rdi      # 0xd0d0
jmp 0x3260
leaq 0x9eed(%rip), %rdi      # 0xd0f3
movq %r14, %rsi
xorl %eax, %eax
callq 0x9997
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3074
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x32a0
leaq 0x9f12(%rip), %rdi      # 0xd143
jmp 0x3054
movq %rbx, %r14
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x32af
leaq 0x9f18(%rip), %rdi      # 0xd162
jmp 0x3260
movq %rbx, %r14
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x32bb
leaq 0x9f3a(%rip), %rdi      # 0xd19a
movq %r14, %rsi
xorl %eax, %eax
callq 0x9997
jmp 0x3074
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x32d4
leaq 0x9f50(%rip), %rdi      # 0xd1d0
jmp 0x3054
movq %rax, %rbx
leaq 0x9e41(%rip), %rdi      # 0xd0d0
movq %r12, %rsi
jmp 0x32c8
movq %rax, %rbx
leaq 0x9e32(%rip), %rdi      # 0xd0d0
jmp 0x32c5
movq %rax, %rbx
leaq 0x9e99(%rip), %rdi      # 0xd143
jmp 0x3067
movq %rax, %rbx
leaq 0x9ea9(%rip), %rdi      # 0xd162
jmp 0x32c5
movq %rax, %rbx
leaq 0x9ed5(%rip), %rdi      # 0xd19a
movq %r14, %rsi
xorl %eax, %eax
callq 0x9878
jmp 0x306e
movq %rax, %rbx
leaq 0x9ef2(%rip), %rdi      # 0xd1d0
jmp 0x3067
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x32f9
leaq 0x9ed3(%rip), %rdi      # 0xd1c7
jmp 0x3054
movq %rax, %rbx
leaq 0x9ec4(%rip), %rdi      # 0xd1c7
jmp 0x3067