// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/perf/main.c
// Function: main
int
main(int argc, char * argv[])
{
	/* State variables. */
	int sock_s;
	int sock_t;
	struct wire_requestqueue * Q_t;
	struct logging_file * logfile;
	struct perfstats * P;
	struct dispatch_state * dstate;

	/* Command-line parameters. */
	char * opt_l = NULL;
	char * opt_p = NULL;
	char * opt_s = NULL;
	char * opt_t = NULL;
	long opt_w = -1;
	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("-l"):
			if (opt_l != NULL)
				usage();
			if ((opt_l = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			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_OPTARG("-w"):
			if (opt_w != -1)
				usage();
			if (PARSENUM(&opt_w, optarg, 1, 86400)) {
				warn0("Invalid option: %s %s", ch, optarg);
				usage();
			}
			break;
		GETOPT_OPT("--version"):
			fprintf(stderr, "kivaloo-perf @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_l == NULL)
		usage();
	if (opt_s == NULL)
		usage();
	if (opt_t == NULL)
		usage();

	/* Set default value. */
	if (opt_w == -1)
		opt_w = 60;

	/* Resolve 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 target 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 ((sock_s = sock_listener(sas_s[0])) == -1)
		exit(1);

	/* Connect to the target. */
	if ((sock_t = sock_connect(sas_t)) == -1)
		exit(1);

	/* Create a queue of requests to the target. */
	if ((Q_t = wire_requestqueue_init(sock_t)) == NULL) {
		warnp("Cannot create request queue");
		exit(1);
	}

	/* Open log file. */
	if ((logfile = logging_open(opt_l)) == NULL) {
		warnp("Cannot open log file");
		exit(1);
	}

	/* Initialize performance tracking state. */
	if ((P = perfstats_init(logfile, opt_w)) == NULL) {
		warnp("Cannot initialize performance statistics");
		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 a time. */
	do {
		/* Accept a connection. */
		if ((dstate = dispatch_accept(sock_s, Q_t, P)) == NULL)
			exit(1);

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

		/* Close and free the connection. */
		dispatch_done(dstate);
	} while (opt_1 == 0);

	/* Output and free performance tracking state */
	perfstats_done(P);

	/* Close the log file. */
	logging_close(logfile);

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

	/* Close sockets. */
	if (close(sock_t))
		warnp("close");
	if (close(sock_s))
		warnp("close");

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

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edi, %r15d
movq $0x0, 0x18(%rsp)
movq %rsi, 0x38(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x29f8
callq 0x8e4c
movl %r15d, %edi
movq 0x38(%rsp), %rsi
callq 0x71c8
testq %rax, %rax
movl %r15d, 0x4(%rsp)
je 0x2e2a
movq %rax, %r12
movq $0x0, 0x20(%rsp)
movq $-0x1, 0x10(%rsp)
leaq 0x5fda9(%rip), %r13     # 0x627d8
leaq 0x95fb(%rip), %rbx      # 0xc031
leaq 0x9637(%rip), %r14      # 0xc074
movq $0x0, 0x28(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x30(%rsp)
movq $0x43, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0x0, (%r13)
je 0x2a85
movq %r12, %rdi
callq 0x74f3
addq 0x8(%rsp), %rax
jmp 0x2a93
movq 0x48(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%rsp)
cmpq $0x5b, %rax
jle 0x2acf
cmpq $0x66, %rax
jle 0x2b0a
cmpq $0x67, %rax
je 0x2bc8
cmpq $0x6c, %rax
jne 0x2bf0
cmpl $0x0, (%r13)
jne 0x3104
movl $0x6c, %edi
subq 0x8(%rsp), %rdi
callq 0x76c7
jmp 0x2a6f
cmpq $0x4f, %rax
jg 0x2b37
cmpq $0x44, %rax
je 0x2b83
cmpq $0x4a, %rax
jne 0x2bf6
cmpl $0x0, (%r13)
jne 0x2d69
movl $0x4a, %esi
subq 0x8(%rsp), %rsi
leaq 0x954d(%rip), %rdi      # 0xc052
jmp 0x2bb9
cmpq $0x5c, %rax
je 0x2b65
cmpq $0x64, %rax
jne 0x2bf6
cmpl $0x0, (%r13)
jne 0x3125
movl $0x64, %esi
subq 0x8(%rsp), %rsi
movq %r14, %rdi
jmp 0x2be4
cmpq $0x50, %rax
je 0x2b9d
cmpq $0x56, %rax
jne 0x2bf6
cmpl $0x0, (%r13)
jne 0x2d16
movl $0x56, %esi
subq 0x8(%rsp), %rsi
leaq 0x94f5(%rip), %rdi      # 0xc058
jmp 0x2bb9
cmpl $0x0, (%r13)
jne 0x2c35
movl $0x5c, %esi
subq 0x8(%rsp), %rsi
leaq 0x94da(%rip), %rdi      # 0xc05b
jmp 0x2bb9
cmpl $0x0, (%r13)
jne 0x2d9f
movl $0x44, %esi
subq 0x8(%rsp), %rsi
movq %rbx, %rdi
jmp 0x2bb9
cmpl $0x0, (%r13)
jne 0x2cd9
movl $0x50, %esi
subq 0x8(%rsp), %rsi
leaq 0x949c(%rip), %rdi      # 0xc055
movl $0x1, %edx
callq 0x75b0
jmp 0x2a6f
cmpl $0x0, (%r13)
jne 0x2d4f
movl $0x67, %esi
subq 0x8(%rsp), %rsi
leaq 0xac23(%rip), %rdi      # 0xd807
xorl %edx, %edx
callq 0x75b0
jmp 0x2a6f
cmpq $0x6f, %rax
je 0x2c28
cmpl $0x0, (%r13)
jne 0x30fb
cmpl $0x0, 0x44(%rsp)
jne 0x2a6f
movl $0x6f, %edi
subq 0x8(%rsp), %rdi
callq 0x7707
movl $0x1, 0x44(%rsp)
jmp 0x2a6f
movl $0x1, (%r13)
jmp 0x2df0
leaq 0x5fb94(%rip), %rax     # 0x627d0
cmpq $0x0, (%rax)
je 0x31f2
cmpq $-0x1, 0x10(%rsp)
jne 0x312a
movq %rbp, %r15
callq 0x20a0
movq %rax, %rbx
movl $0x0, (%rax)
leaq 0x5fb66(%rip), %rax     # 0x627d0
movq (%rax), %rbp
testq %rbp, %rbp
je 0x31d3
movq %rbp, %rdi
leaq 0x50(%rsp), %rsi
xorl %edx, %edx
callq 0x2050
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rcx
movl $0x16, %eax
cmpq %rbp, %rcx
je 0x2ddd
cmpb $0x0, (%rcx)
movq %r15, %rbp
jne 0x2de0
movq 0x10(%rsp), %rax
movq $-0x15181, %rcx         # imm = 0xFFFEAE7F
addq %rcx, %rax
cmpq %rcx, %rax
movl 0x4(%rsp), %r15d
ja 0x2de7
movl $0x22, %eax
movq $0x0, 0x10(%rsp)
jmp 0x2de5
leaq 0x5faf0(%rip), %rax     # 0x627d0
cmpq $0x0, (%rax)
je 0x3230
testq %rbp, %rbp
jne 0x312a
leaq 0x5fad6(%rip), %rax     # 0x627d0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x23e0
testq %rax, %rax
je 0x312f
movq %rax, %rbp
jmp 0x2df0
leaq 0x5fab3(%rip), %rax     # 0x627d0
cmpq $0x0, (%rax)
je 0x3211
cmpq $0x0, 0x30(%rsp)
jne 0x312a
leaq 0x5fa96(%rip), %rax     # 0x627d0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x23e0
movq %rax, 0x30(%rsp)
jmp 0x2dd3
cmpl $0x0, 0x20(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
je 0x2df0
jmp 0x312a
leaq 0x5fa60(%rip), %rax     # 0x627d0
cmpq $0x0, (%rax)
je 0x316f
cmpq $0x0, 0x18(%rsp)
jne 0x312a
leaq 0x5fa43(%rip), %rax     # 0x627d0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x23e0
movq %rax, 0x18(%rsp)
jmp 0x2dd3
leaq 0x5fa2a(%rip), %rax     # 0x627d0
cmpq $0x0, (%rax)
je 0x318e
cmpq $0x0, 0x28(%rsp)
jne 0x312a
leaq 0x5fa0d(%rip), %rax     # 0x627d0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x23e0
movq %rax, 0x28(%rsp)
testq %rax, %rax
jne 0x2df0
jmp 0x312f
movq %r15, %rbp
movl 0x4(%rsp), %r15d
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
jne 0x31ad
movl %r15d, %edi
movq 0x38(%rsp), %rsi
callq 0x71c8
movq %rax, %r12
testq %rax, %rax
leaq 0x9227(%rip), %rbx      # 0xc031
jne 0x2a51
cmpl $0x0, 0x20(%rsp)
sete %r15b
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rdx
jmp 0x2e3b
movb $0x1, %r15b
movq $-0x1, %rdx
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r13d, %r13d
leaq 0xf736(%rip), %rax      # 0x12578
movl 0x4(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x312a
testq %r13, %r13
je 0x312a
testq %rbp, %rbp
je 0x312a
testq %rbx, %rbx
je 0x312a
cmpq $-0x1, %rdx
movl $0x3c, %r14d
cmovneq %rdx, %r14
movq %rbp, %rdi
callq 0x7e24
testq %rax, %rax
je 0x324f
movq %rax, %r12
cmpq $0x0, (%rax)
je 0x3269
movq %rbx, %rdi
callq 0x7e24
testq %rax, %rax
je 0x3275
cmpq $0x0, (%rax)
je 0x329c
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x8(%r12)
je 0x2ed9
leaq 0x923b(%rip), %rdi      # 0xc0ff
movq %rbp, %rsi
xorl %eax, %eax
callq 0x8feb
callq 0x20a0
movl $0x0, (%rax)
movq %rbp, 0x10(%rsp)
movq (%r12), %rdi
callq 0x857f
cmpl $-0x1, %eax
je 0x30f1
movl %eax, %ebp
movq %r12, 0x20(%rsp)
movq 0x38(%rsp), %rdi
callq 0x8741
cmpl $-0x1, %eax
je 0x30f1
movq %rbx, 0x30(%rsp)
movl %eax, 0x4(%rsp)
movl %eax, %edi
callq 0xa3b4
testq %rax, %rax
je 0x32bd
movq %rax, %r12
movq %r13, 0x28(%rsp)
movq %r13, %rdi
callq 0x977c
testq %rax, %rax
je 0x32d3
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x3bdc
testq %rax, %rax
je 0x32e9
movq %rax, %r14
cmpq $0x0, 0x18(%rsp)
jne 0x2f7f
leaq 0x922a(%rip), %rsi      # 0xc18f
leaq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x6ed4
cmpl $-0x1, %eax
je 0x3379
movq 0x18(%rsp), %rdi
callq 0x6fd8
testl %eax, %eax
jne 0x32ff
movl %ebp, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x340c
movq %rax, %rbx
testq %rax, %rax
je 0x30f1
callq 0x487c
testl %eax, %eax
jne 0x30c0
movq %rbx, %rdi
callq 0x3637
testl %eax, %eax
jne 0x2faa
movq %rbx, %rdi
callq 0x3656
testb %r15b, %r15b
jne 0x2f91
movq %r14, %rdi
callq 0x3f0a
movq %r13, %rdi
callq 0x9e0d
movq %r12, %rdi
callq 0xaa79
movq %r12, %rdi
callq 0xaa8d
movl 0x4(%rsp), %edi
callq 0x21d0
testl %eax, %eax
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r12
je 0x3038
callq 0x20a0
cmpl $0x0, (%rax)
je 0x302a
movq %rax, %rbx
leaq 0x9d8f(%rip), %rdi      # 0xcdaa
xorl %eax, %eax
callq 0x8ecc
movl $0x0, (%rbx)
jmp 0x3038
leaq 0x9d79(%rip), %rdi      # 0xcdaa
xorl %eax, %eax
callq 0x8feb
movl %ebp, %edi
callq 0x21d0
testl %eax, %eax
movq 0x10(%rsp), %r14
je 0x3079
callq 0x20a0
cmpl $0x0, (%rax)
je 0x306b
movq %rax, %rbx
leaq 0x9d4e(%rip), %rdi      # 0xcdaa
xorl %eax, %eax
callq 0x8ecc
movl $0x0, (%rbx)
jmp 0x3079
leaq 0x9d38(%rip), %rdi      # 0xcdaa
xorl %eax, %eax
callq 0x8feb
movq 0x38(%rsp), %rdi
callq 0x853b
movq 0x20(%rsp), %rdi
callq 0x853b
movq %r15, %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq 0x18(%rsp), %rdi
callq 0x2040
movq %r12, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x30da
leaq 0x90e2(%rip), %rdi      # 0xc1b3
xorl %eax, %eax
callq 0x8feb
jmp 0x30f1
movq %rax, %rbx
leaq 0x90cf(%rip), %rdi      # 0xc1b3
xorl %eax, %eax
callq 0x8ecc
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x23a0
leaq 0x8fab(%rip), %rdi      # 0xc0ad
jmp 0x310b
leaq 0x8f8b(%rip), %rdi      # 0xc096
movq %r12, %rsi
xorl %eax, %eax
callq 0x8feb
callq 0x20a0
movl $0x0, (%rax)
callq 0x339e
callq 0x2450
callq 0x339e
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x314f
leaq 0x8ef4(%rip), %rdi      # 0xc034
movq %r12, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8feb
jmp 0x30f1
movq %rax, %r14
leaq 0x8edb(%rip), %rdi      # 0xc034
movq %r12, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8ecc
movl $0x0, (%r14)
jmp 0x30f1
leaq 0x8e8e(%rip), %rdi      # 0xc004
leaq 0x8e96(%rip), %rsi      # 0xc013
leaq 0x8e96(%rip), %rcx      # 0xc01a
movl $0x4a, %edx
callq 0x21b0
leaq 0x8e6f(%rip), %rdi      # 0xc004
leaq 0x8e77(%rip), %rsi      # 0xc013
leaq 0x8e77(%rip), %rcx      # 0xc01a
movl $0x44, %edx
callq 0x21b0
leaq 0x5f61c(%rip), %rax     # 0x627d0
movq (%rax), %rdx
leaq 0x8ea0(%rip), %rdi      # 0xc05e
movq %r12, %rsi
xorl %eax, %eax
callq 0x8feb
movl $0x0, (%rbx)
callq 0x339e
leaq 0x9d7c(%rip), %rdi      # 0xcf56
leaq 0x9082(%rip), %rsi      # 0xc263
leaq 0x909a(%rip), %rcx      # 0xc282
movl $0xa7, %edx
callq 0x21b0
leaq 0x8e0b(%rip), %rdi      # 0xc004
leaq 0x8e13(%rip), %rsi      # 0xc013
leaq 0x8e13(%rip), %rcx      # 0xc01a
movl $0x5c, %edx
callq 0x21b0
leaq 0x8dec(%rip), %rdi      # 0xc004
leaq 0x8df4(%rip), %rsi      # 0xc013
leaq 0x8df4(%rip), %rcx      # 0xc01a
movl $0x56, %edx
callq 0x21b0
leaq 0x8dcd(%rip), %rdi      # 0xc004
leaq 0x8dd5(%rip), %rsi      # 0xc013
leaq 0x8dd5(%rip), %rcx      # 0xc01a
movl $0x50, %edx
callq 0x21b0
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3315
leaq 0x8e5e(%rip), %rdi      # 0xc0c2
movq %rbp, %rsi
jmp 0x3290
leaq 0x8e75(%rip), %rdi      # 0xc0e5
movq %rbp, %rsi
jmp 0x32a6
movq %rbx, %r14
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3324
leaq 0x8e35(%rip), %rdi      # 0xc0c2
movq %r14, %rsi
xorl %eax, %eax
callq 0x8feb
jmp 0x30f1
leaq 0x8e42(%rip), %rdi      # 0xc0e5
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8feb
callq 0x20a0
movl $0x0, (%rax)
jmp 0x30f1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x333d
leaq 0x8e67(%rip), %rdi      # 0xc135
jmp 0x30d1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x334c
leaq 0x8e6d(%rip), %rdi      # 0xc151
jmp 0x30d1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x335b
leaq 0x8e6c(%rip), %rdi      # 0xc166
jmp 0x30d1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x336a
leaq 0x8e8f(%rip), %rdi      # 0xc19f
jmp 0x30d1
movq %rax, %rbx
leaq 0x8da3(%rip), %rdi      # 0xc0c2
movq %rbp, %rsi
jmp 0x3331
movq %rax, %rbx
leaq 0x8d94(%rip), %rdi      # 0xc0c2
movq %r14, %rsi
xorl %eax, %eax
callq 0x8ecc
jmp 0x30eb
movq %rax, %rbx
leaq 0x8dee(%rip), %rdi      # 0xc135
jmp 0x30e4
movq %rax, %rbx
leaq 0x8dfb(%rip), %rdi      # 0xc151
jmp 0x30e4
movq %rax, %rbx
leaq 0x8e01(%rip), %rdi      # 0xc166
jmp 0x30e4
movq %rax, %rbx
leaq 0x8e2b(%rip), %rdi      # 0xc19f
jmp 0x30e4
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x338f
leaq 0x8e0c(%rip), %rdi      # 0xc196
jmp 0x30d1
movq %rax, %rbx
leaq 0x8dfd(%rip), %rdi      # 0xc196
jmp 0x30e4