// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x2a39
callq 0x8eec
movl 0x10(%rsp), %edi
movq 0x28(%rsp), %rsi
callq 0x7220
testq %rax, %rax
je 0x3231
movq %rax, %r12
movq $-0x1, 0x8(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0x60d6c(%rip), %r13     # 0x637d8
leaq 0xa5be(%rip), %r15      # 0xd031
xorl %r14d, %r14d
xorl %ebp, %ebp
movl $0x0, 0x1c(%rsp)
xorl %ebx, %ebx
movq $0x43, (%rsp)
movq (%rsp), %rax
decq %rax
movq %rax, 0x48(%rsp)
movl $0x0, 0x3c(%rsp)
cmpl $0x0, (%r13)
je 0x2ab3
movq %r12, %rdi
callq 0x7567
addq (%rsp), %rax
jmp 0x2ac1
movq 0x48(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%rsp)
cmpq $0x5b, %rax
jle 0x2afc
cmpq $0x66, %rax
jle 0x2b36
cmpq $0x67, %rax
je 0x2bf3
cmpq $0x6c, %rax
jne 0x2c1a
cmpl $0x0, (%r13)
jne 0x3109
movl $0x6c, %edi
subq (%rsp), %rdi
callq 0x7735
jmp 0x2a9e
cmpq $0x4f, %rax
jg 0x2b66
cmpq $0x44, %rax
je 0x2bb0
cmpq $0x4a, %rax
jne 0x2c20
cmpl $0x0, (%r13)
jne 0x2d88
movl $0x4a, %esi
subq (%rsp), %rsi
leaq 0xa521(%rip), %rdi      # 0xd052
jmp 0x2be4
cmpq $0x5c, %rax
je 0x2b93
cmpq $0x64, %rax
jne 0x2c20
cmpl $0x0, (%r13)
jne 0x312a
movl $0x64, %esi
subq (%rsp), %rsi
leaq 0xa513(%rip), %rdi      # 0xd074
jmp 0x2c0e
cmpq $0x50, %rax
je 0x2bc9
cmpq $0x56, %rax
jne 0x2c20
cmpl $0x0, (%r13)
jne 0x2d3b
movl $0x56, %esi
subq (%rsp), %rsi
leaq 0xa4c7(%rip), %rdi      # 0xd058
jmp 0x2be4
cmpl $0x0, (%r13)
jne 0x2c5e
movl $0x5c, %esi
subq (%rsp), %rsi
leaq 0xa4ad(%rip), %rdi      # 0xd05b
jmp 0x2be4
cmpl $0x0, (%r13)
jne 0x2dc3
movl $0x44, %esi
subq (%rsp), %rsi
movq %r15, %rdi
jmp 0x2be4
cmpl $0x0, (%r13)
jne 0x2d06
movl $0x50, %esi
subq (%rsp), %rsi
leaq 0xa471(%rip), %rdi      # 0xd055
movl $0x1, %edx
callq 0x7624
jmp 0x2a9e
cmpl $0x0, (%r13)
jne 0x2d70
movl $0x67, %esi
subq (%rsp), %rsi
leaq 0xbc40(%rip), %rdi      # 0xe84e
xorl %edx, %edx
callq 0x7624
jmp 0x2a9e
cmpq $0x6f, %rax
je 0x2c51
cmpl $0x0, (%r13)
jne 0x3100
cmpl $0x0, 0x3c(%rsp)
jne 0x2a9e
movl $0x6f, %edi
subq (%rsp), %rdi
callq 0x7775
movl $0x1, 0x3c(%rsp)
jmp 0x2a9e
movl $0x1, (%r13)
jmp 0x2e1c
movq %r14, %r15
movq %rbx, %r14
movq %rbp, %rbx
leaq 0x60b62(%rip), %rax     # 0x637d0
movq (%rax), %rbp
testq %rbp, %rbp
je 0x31d4
cmpq $-0x1, 0x8(%rsp)
jne 0x312f
callq 0x20a0
movq %rax, 0x20(%rsp)
movl $0x0, (%rax)
movq %rbp, %rdi
leaq 0x50(%rsp), %rsi
xorl %edx, %edx
callq 0x2050
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %rcx
movl $0x16, %eax
cmpq %rbp, %rcx
je 0x2dfc
cmpb $0x0, (%rcx)
movq %rbx, %rbp
jne 0x2dff
movq 0x8(%rsp), %rax
movq $-0x15181, %rcx         # imm = 0xFFFEAE7F
addq %rcx, %rax
cmpq %rcx, %rax
movq %r14, %rbx
movq %r15, %r14
leaq 0xa349(%rip), %r15      # 0xd031
movq 0x20(%rsp), %rcx
ja 0x2e13
movl $0x22, %eax
movq $0x0, 0x8(%rsp)
jmp 0x2e11
leaq 0x60ac3(%rip), %rax     # 0x637d0
movq (%rax), %r15
testq %r15, %r15
je 0x3212
testq %rbp, %rbp
jne 0x312f
movq %r15, %rdi
callq 0x23e0
testq %rax, %rax
je 0x3134
movq %rax, %rbp
jmp 0x2df3
leaq 0x60a8e(%rip), %rax     # 0x637d0
movq (%rax), %r15
testq %r15, %r15
je 0x31f3
testq %rbx, %rbx
jne 0x312f
movq %r15, %rdi
callq 0x23e0
testq %rax, %rax
je 0x3134
movq %rax, %rbx
jmp 0x2df3
cmpl $0x0, 0x1c(%rsp)
movl $0x1, 0x1c(%rsp)
je 0x2e1c
jmp 0x312f
leaq 0x60a41(%rip), %rax     # 0x637d0
movq (%rax), %r15
testq %r15, %r15
je 0x316d
cmpq $0x0, 0x40(%rsp)
jne 0x312f
movq %r15, %rdi
callq 0x23e0
movq %rax, 0x30(%rsp)
movq %rax, 0x40(%rsp)
testq %rax, %rax
jne 0x2df3
jmp 0x3134
leaq 0x60a06(%rip), %rax     # 0x637d0
movq (%rax), %r15
testq %r15, %r15
je 0x318c
testq %r14, %r14
jne 0x312f
movq %r15, %rdi
callq 0x23e0
testq %rax, %rax
je 0x3134
movq %rax, %r14
leaq 0xa237(%rip), %r15      # 0xd031
jmp 0x2e1c
movq %rbx, %rbp
movq %r14, %rbx
movq %r15, %r14
leaq 0xa225(%rip), %r15      # 0xd031
movq 0x20(%rsp), %rcx
movl %eax, (%rcx)
cmpl $0x0, (%rcx)
jne 0x31ab
movl 0x10(%rsp), %edi
movq 0x28(%rsp), %rsi
callq 0x7220
movq %rax, %r12
testq %rax, %rax
jne 0x2a82
leaq 0x1073b(%rip), %rax     # 0x13578
movl 0x10(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x312f
testq %r14, %r14
je 0x312f
testq %rbp, %rbp
je 0x312f
movq %r14, 0x10(%rsp)
testq %rbx, %rbx
je 0x312f
movq 0x8(%rsp), %rax
cmpq $-0x1, %rax
movl $0x3c, %r14d
cmovneq %rax, %r14
movq %rbp, %rdi
callq 0x7ee8
testq %rax, %rax
je 0x3243
movq %rax, %r12
cmpq $0x0, (%rax)
je 0x325d
movq %rbx, %rdi
callq 0x7ee8
testq %rax, %rax
je 0x3269
movq %rax, %r13
cmpq $0x0, (%rax)
je 0x3290
cmpq $0x0, 0x8(%r12)
je 0x2edc
leaq 0xa238(%rip), %rdi      # 0xd0ff
movq %rbp, %rsi
xorl %eax, %eax
callq 0x908b
callq 0x20a0
movl $0x0, (%rax)
movq %rbp, 0x28(%rsp)
movq (%r12), %rdi
callq 0x863e
cmpl $-0x1, %eax
je 0x30f6
movl %eax, %ebp
movq %r13, %rdi
callq 0x8800
cmpl $-0x1, %eax
je 0x30f6
movl %eax, %r15d
movq %r13, 0x40(%rsp)
movq %r12, 0x8(%rsp)
movl %eax, %edi
callq 0xa428
testq %rax, %rax
je 0x32b1
movq %rax, %r12
movq 0x10(%rsp), %rdi
callq 0x97d8
testq %rax, %rax
je 0x32c7
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x3bf8
testq %rax, %rax
je 0x32dd
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
jne 0x2f83
leaq 0xa22b(%rip), %rsi      # 0xd18f
leaq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x6f2c
cmpl $-0x1, %eax
je 0x336d
movq 0x30(%rsp), %rdi
movq %rbx, 0x20(%rsp)
callq 0x7030
testl %eax, %eax
jne 0x32f3
movl %ebp, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3400
movq %rax, %rbx
testq %rax, %rax
je 0x30f6
callq 0x4888
testl %eax, %eax
jne 0x30c5
movq %rbx, %rdi
callq 0x362b
testl %eax, %eax
jne 0x2fae
movq %rbx, %rdi
callq 0x364a
cmpl $0x0, 0x1c(%rsp)
je 0x2f95
movq %r14, %rdi
callq 0x3f1c
movq %r13, %rdi
callq 0x9e69
movq %r12, %rdi
callq 0xab19
movq %r12, %rdi
callq 0xab2d
movl %r15d, %edi
callq 0x21d0
testl %eax, %eax
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %r12
je 0x303d
callq 0x20a0
cmpl $0x0, (%rax)
je 0x302f
movq %rax, %rbx
leaq 0xad3a(%rip), %rdi      # 0xdd5a
xorl %eax, %eax
callq 0x8f6c
movl $0x0, (%rbx)
jmp 0x303d
leaq 0xad24(%rip), %rdi      # 0xdd5a
xorl %eax, %eax
callq 0x908b
movl %ebp, %edi
callq 0x21d0
testl %eax, %eax
movq 0x28(%rsp), %r14
je 0x307e
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3070
movq %rax, %rbx
leaq 0xacf9(%rip), %rdi      # 0xdd5a
xorl %eax, %eax
callq 0x8f6c
movl $0x0, (%rbx)
jmp 0x307e
leaq 0xace3(%rip), %rdi      # 0xdd5a
xorl %eax, %eax
callq 0x908b
movq %r12, %rdi
callq 0x85fa
movq %r15, %rdi
callq 0x85fa
movq 0x20(%rsp), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq 0x30(%rsp), %rdi
callq 0x2040
movq 0x10(%rsp), %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 0x30df
leaq 0xa0dd(%rip), %rdi      # 0xd1b3
xorl %eax, %eax
callq 0x908b
jmp 0x30f6
movq %rax, %rbx
leaq 0xa0ca(%rip), %rdi      # 0xd1b3
xorl %eax, %eax
callq 0x8f6c
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x23a0
leaq 0x9fa6(%rip), %rdi      # 0xd0ad
jmp 0x3110
leaq 0x9f86(%rip), %rdi      # 0xd096
movq %r12, %rsi
xorl %eax, %eax
callq 0x908b
callq 0x20a0
movl $0x0, (%rax)
callq 0x3392
callq 0x2450
callq 0x3392
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3154
leaq 0x9eef(%rip), %rdi      # 0xd034
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x908b
jmp 0x30f6
movq %rax, %rbx
leaq 0x9ed6(%rip), %rdi      # 0xd034
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x8f6c
jmp 0x30f0
leaq 0x9e90(%rip), %rdi      # 0xd004
leaq 0x9e98(%rip), %rsi      # 0xd013
leaq 0x9e98(%rip), %rcx      # 0xd01a
movl $0x4a, %edx
callq 0x21b0
leaq 0x9e71(%rip), %rdi      # 0xd004
leaq 0x9e79(%rip), %rsi      # 0xd013
leaq 0x9e79(%rip), %rcx      # 0xd01a
movl $0x44, %edx
callq 0x21b0
leaq 0x6061e(%rip), %rax     # 0x637d0
movq (%rax), %rdx
leaq 0x9ea2(%rip), %rdi      # 0xd05e
movq %r12, %rsi
xorl %eax, %eax
movq %rcx, %rbx
callq 0x908b
movl $0x0, (%rbx)
callq 0x3392
leaq 0x9e29(%rip), %rdi      # 0xd004
leaq 0x9e31(%rip), %rsi      # 0xd013
leaq 0x9e31(%rip), %rcx      # 0xd01a
movl $0x5c, %edx
callq 0x21b0
leaq 0x9e0a(%rip), %rdi      # 0xd004
leaq 0x9e12(%rip), %rsi      # 0xd013
leaq 0x9e12(%rip), %rcx      # 0xd01a
movl $0x56, %edx
callq 0x21b0
leaq 0x9deb(%rip), %rdi      # 0xd004
leaq 0x9df3(%rip), %rsi      # 0xd013
leaq 0x9df3(%rip), %rcx      # 0xd01a
movl $0x50, %edx
callq 0x21b0
leaq 0x10340(%rip), %rax     # 0x13578
movl 0x10(%rsp), %ecx
cmpl %ecx, (%rax)
callq 0x3392
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3309
leaq 0x9e6a(%rip), %rdi      # 0xd0c2
movq %rbp, %rsi
jmp 0x3284
leaq 0x9e81(%rip), %rdi      # 0xd0e5
movq %rbp, %rsi
jmp 0x329a
movq %rbx, %r14
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3318
leaq 0x9e41(%rip), %rdi      # 0xd0c2
movq %r14, %rsi
xorl %eax, %eax
callq 0x908b
jmp 0x30f6
leaq 0x9e4e(%rip), %rdi      # 0xd0e5
movq %rbx, %rsi
xorl %eax, %eax
callq 0x908b
callq 0x20a0
movl $0x0, (%rax)
jmp 0x30f6
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3331
leaq 0x9e73(%rip), %rdi      # 0xd135
jmp 0x30d6
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3340
leaq 0x9e79(%rip), %rdi      # 0xd151
jmp 0x30d6
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x334f
leaq 0x9e78(%rip), %rdi      # 0xd166
jmp 0x30d6
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x335e
leaq 0x9e9b(%rip), %rdi      # 0xd19f
jmp 0x30d6
movq %rax, %rbx
leaq 0x9daf(%rip), %rdi      # 0xd0c2
movq %rbp, %rsi
jmp 0x3325
movq %rax, %rbx
leaq 0x9da0(%rip), %rdi      # 0xd0c2
movq %r14, %rsi
xorl %eax, %eax
callq 0x8f6c
jmp 0x30f0
movq %rax, %rbx
leaq 0x9dfa(%rip), %rdi      # 0xd135
jmp 0x30e9
movq %rax, %rbx
leaq 0x9e07(%rip), %rdi      # 0xd151
jmp 0x30e9
movq %rax, %rbx
leaq 0x9e0d(%rip), %rdi      # 0xd166
jmp 0x30e9
movq %rax, %rbx
leaq 0x9e37(%rip), %rdi      # 0xd19f
jmp 0x30e9
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x3383
leaq 0x9e18(%rip), %rdi      # 0xd196
jmp 0x30d6
movq %rax, %rbx
leaq 0x9e09(%rip), %rdi      # 0xd196
jmp 0x30e9