// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
andq $0x0, 0x30(%rsp)
movl %edi, 0x28(%rsp)
movq %rsi, 0x50(%rsp)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x2566
callq 0x804c
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movq %rax, 0x18(%rsp)
movb $0x1, %al
movl %eax, 0x40(%rsp)
leaq 0x6025b(%rip), %rbp     # 0x627d8
pushq $0x1
popq %r15
movl $0x0, 0x24(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
pushq $0x44
popq %r13
movl 0x28(%rsp), %edi
movq 0x50(%rsp), %rsi
callq 0x63fc
testq %rax, %rax
je 0x28ff
movq %rax, %r12
movq $0x43, 0x8(%rsp)
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x3c(%rsp)
cmpl $0x0, (%rbp)
je 0x25e6
movq %r12, %rdi
callq 0x6811
addq 0x8(%rsp), %rax
jmp 0x25f4
movq 0x58(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x58(%rsp)
cmpq $0x44, %rax
je 0x2740
cmpq $0x4a, %rax
je 0x26d3
cmpq $0x50, %rax
je 0x2725
cmpq $0x56, %rax
je 0x270a
cmpq $0x5c, %rax
je 0x2675
cmpq $0x64, %rax
je 0x26ae
cmpq $0x67, %rax
je 0x2693
cmpq $0x6c, %rax
je 0x26ee
cmpq $0x6f, %rax
je 0x2766
cmpl $0x0, (%rbp)
jne 0x2bdc
cmpl $0x0, 0x3c(%rsp)
jne 0x25d1
pushq $0x6f
popq %rdi
subq 0x8(%rsp), %rdi
callq 0x6b7e
movl $0x1, 0x3c(%rsp)
jmp 0x25d1
cmpl $0x0, (%rbp)
jne 0x2772
pushq $0x5c
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x89cd(%rip), %rdi      # 0xb05b
jmp 0x2759
cmpl $0x0, (%rbp)
jne 0x27da
pushq $0x67
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0xa113(%rip), %rdi      # 0xc7bf
jmp 0x26c7
cmpl $0x0, (%rbp)
jne 0x2bb9
pushq $0x64
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x89ad(%rip), %rdi      # 0xb074
xorl %edx, %edx
callq 0x6929
jmp 0x25d1
cmpl $0x0, (%rbp)
jne 0x2872
pushq $0x4a
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x8966(%rip), %rdi      # 0xb052
jmp 0x2759
cmpl $0x0, (%rbp)
jne 0x2be5
pushq $0x6c
popq %rdi
subq 0x8(%rsp), %rdi
callq 0x6af3
jmp 0x25d1
cmpl $0x0, (%rbp)
jne 0x281b
pushq $0x56
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x8935(%rip), %rdi      # 0xb058
jmp 0x2759
cmpl $0x0, (%rbp)
jne 0x2844
pushq $0x50
popq %rsi
subq 0x8(%rsp), %rsi
leaq 0x8917(%rip), %rdi      # 0xb055
jmp 0x2759
cmpl $0x0, (%rbp)
jne 0x27ef
movq %r13, %rsi
subq 0x8(%rsp), %rsi
leaq 0x88d8(%rip), %rdi      # 0xb031
movl %r15d, %edx
callq 0x6929
jmp 0x25d1
movl $0x1, (%rbp)
jmp 0x2599
movq %r14, %r13
movq %rbx, %r14
leaq 0x60051(%rip), %rax     # 0x627d0
movq (%rax), %rbx
testq %rbx, %rbx
je 0x2c64
cmpq $-0x1, 0x18(%rsp)
jne 0x2bfe
callq 0x20a0
movq %rax, 0x48(%rsp)
andl $0x0, (%rax)
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0x2050
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %rax
cmpq %rbx, %rax
je 0x28b3
cmpb $0x0, (%rax)
movq %r14, %rbx
je 0x28d5
pushq $0x16
popq %rax
jmp 0x28b9
cmpl $0x0, 0x24(%rsp)
movl %r15d, 0x24(%rsp)
je 0x2595
jmp 0x2bfe
leaq 0x5ffda(%rip), %rax     # 0x627d0
movq (%rax), %r13
testq %r13, %r13
je 0x2cc8
testq %r14, %r14
jne 0x2bfe
movq %r13, %rdi
callq 0x23e0
movq %rax, %r14
jmp 0x28a5
leaq 0x5ffae(%rip), %rax     # 0x627d0
movq (%rax), %r13
testq %r13, %r13
je 0x2c7d
testq %rbx, %rbx
jne 0x2bfe
movq %r13, %rdi
callq 0x23e0
movq %rax, %rbx
jmp 0x28a5
leaq 0x5ff85(%rip), %rax     # 0x627d0
movq (%rax), %r13
testq %r13, %r13
je 0x2c96
cmpq $0x0, 0x10(%rsp)
jne 0x2bfe
movq %r13, %rdi
callq 0x23e0
movq %rax, 0x10(%rsp)
jmp 0x28a5
leaq 0x5ff57(%rip), %rax     # 0x627d0
movq (%rax), %r13
testq %r13, %r13
je 0x2caf
testb $0x1, 0x40(%rsp)
je 0x2bfe
movq %r13, %rdi
callq 0x23e0
movq %rax, 0x30(%rsp)
movl $0x0, 0x40(%rsp)
testq %rax, %rax
jne 0x2595
jmp 0x2c03
pushq $0x16
popq %rax
movq %r14, %rbx
movq %r13, %r14
movq 0x48(%rsp), %r13
movl %eax, (%r13)
cmpl $0x0, (%r13)
je 0x2595
jmp 0x2c3f
movq 0x18(%rsp), %rax
movq $-0x15181, %rcx         # imm = 0xFFFEAE7F
addq %rcx, %rax
cmpq %rcx, %rax
movq %r13, %r14
movq 0x48(%rsp), %r13
ja 0x28c5
pushq $0x22
popq %rax
movq $0x0, 0x18(%rsp)
jmp 0x28c1
leaq 0xfc72(%rip), %rax      # 0x12578
movl 0x28(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0x2bfe
testq %r14, %r14
movq 0x10(%rsp), %r15
je 0x2bfe
testq %r15, %r15
je 0x2bfe
movq %r14, 0x28(%rsp)
testq %rbx, %rbx
je 0x2bfe
movq 0x18(%rsp), %rax
cmpq $-0x1, %rax
pushq $0x3c
popq %r14
cmovneq %rax, %r14
movq %r15, %rdi
callq 0x71d4
testq %rax, %rax
je 0x2ce5
movq %rax, %r12
cmpq $0x0, (%rax)
je 0x2d01
movq %rbx, %rdi
callq 0x71d4
testq %rax, %rax
je 0x2d0d
movq %rax, %r13
cmpq $0x0, (%rax)
je 0x2d34
cmpq $0x0, 0x8(%r12)
je 0x29a5
leaq 0x876c(%rip), %rdi      # 0xb0ff
movq %r15, %rsi
xorl %eax, %eax
callq 0x8258
callq 0x20a0
andl $0x0, (%rax)
movq (%r12), %rdi
callq 0x7805
cmpl $-0x1, %eax
je 0x2bb1
movl %eax, %ebp
movq %r13, %rdi
callq 0x79ad
cmpl $-0x1, %eax
je 0x2bb1
movl %eax, %r15d
movq %r13, 0x18(%rsp)
movq %r12, 0x50(%rsp)
movl %eax, %edi
callq 0x93cc
testq %rax, %rax
je 0x2d52
movq %rax, %r12
movq 0x28(%rsp), %rdi
callq 0x88b8
testq %rax, %rax
je 0x2d68
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x3578
testq %rax, %rax
je 0x2d7e
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
jne 0x2a47
leaq 0x8767(%rip), %rsi      # 0xb18f
leaq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x6124
cmpl $-0x1, %eax
je 0x2e10
movq 0x30(%rsp), %rdi
movq %rbx, 0x40(%rsp)
callq 0x6218
testl %eax, %eax
jne 0x2d94
movl %ebp, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2e9c
movq %rax, %rbx
testq %rax, %rax
je 0x2bb1
callq 0x415c
testl %eax, %eax
jne 0x2b83
movq %rbx, %rdi
callq 0x30af
testl %eax, %eax
jne 0x2a72
movq %rbx, %rdi
callq 0x30cc
cmpl $0x0, 0x24(%rsp)
je 0x2a59
movq %r14, %rdi
callq 0x3875
movq %r13, %rdi
callq 0x8f11
movq %r12, %rdi
callq 0x98af
movq %r12, %rdi
callq 0x98c3
movl %r15d, %edi
callq 0x21d0
testl %eax, %eax
movq 0x10(%rsp), %r14
movq 0x50(%rsp), %r15
movq 0x18(%rsp), %r12
je 0x2b03
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2af5
movq %rax, %rbx
leaq 0x9271(%rip), %rdi      # 0xbd5a
xorl %eax, %eax
callq 0x80c9
andl $0x0, (%rbx)
jmp 0x2b03
leaq 0x925e(%rip), %rdi      # 0xbd5a
xorl %eax, %eax
callq 0x8258
movl %ebp, %edi
callq 0x21d0
testl %eax, %eax
je 0x2b3c
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2b2e
movq %rax, %rbx
leaq 0x9238(%rip), %rdi      # 0xbd5a
xorl %eax, %eax
callq 0x80c9
andl $0x0, (%rbx)
jmp 0x2b3c
leaq 0x9225(%rip), %rdi      # 0xbd5a
xorl %eax, %eax
callq 0x8258
movq %r12, %rdi
callq 0x77d3
movq %r15, %rdi
callq 0x77d3
movq 0x40(%rsp), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq 0x30(%rsp), %rdi
callq 0x2040
movq 0x28(%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 0x2b9d
leaq 0x861f(%rip), %rdi      # 0xb1b3
xorl %eax, %eax
callq 0x8258
jmp 0x2bb1
movq %rax, %rbx
leaq 0x860c(%rip), %rdi      # 0xb1b3
xorl %eax, %eax
callq 0x80c9
andl $0x0, (%rbx)
pushq $0x1
popq %rdi
callq 0x23a0
movq 0xf438(%rip), %rax      # 0x11ff8
movq (%rax), %rcx
leaq 0x84b4(%rip), %rdi      # 0xb07e
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
callq 0x23c0
xorl %edi, %edi
callq 0x23a0
leaq 0x84ca(%rip), %rdi      # 0xb0ad
jmp 0x2bec
leaq 0x84aa(%rip), %rdi      # 0xb096
movq %r12, %rsi
xorl %eax, %eax
callq 0x8258
callq 0x20a0
andl $0x0, (%rax)
callq 0x2e35
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2c23
leaq 0x8420(%rip), %rdi      # 0xb034
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x8258
jmp 0x2bb1
movq %rax, %rbx
leaq 0x8407(%rip), %rdi      # 0xb034
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x80c9
jmp 0x2bae
leaq 0x5fb8a(%rip), %rax     # 0x627d0
movq (%rax), %rdx
leaq 0x840e(%rip), %rdi      # 0xb05e
movq %r12, %rsi
xorl %eax, %eax
callq 0x8258
andl $0x0, (%r13)
callq 0x2e35
leaq 0x8399(%rip), %rdi      # 0xb004
leaq 0x83a1(%rip), %rsi      # 0xb013
leaq 0x83a1(%rip), %rcx      # 0xb01a
pushq $0x5c
jmp 0x2cdf
leaq 0x8380(%rip), %rdi      # 0xb004
leaq 0x8388(%rip), %rsi      # 0xb013
leaq 0x8388(%rip), %rcx      # 0xb01a
pushq $0x56
jmp 0x2cdf
leaq 0x8367(%rip), %rdi      # 0xb004
leaq 0x836f(%rip), %rsi      # 0xb013
leaq 0x836f(%rip), %rcx      # 0xb01a
pushq $0x50
jmp 0x2cdf
leaq 0x834e(%rip), %rdi      # 0xb004
leaq 0x8356(%rip), %rsi      # 0xb013
leaq 0x8356(%rip), %rcx      # 0xb01a
pushq $0x4a
jmp 0x2cdf
leaq 0x8335(%rip), %rdi      # 0xb004
leaq 0x833d(%rip), %rsi      # 0xb013
leaq 0x833d(%rip), %rcx      # 0xb01a
pushq $0x44
popq %rdx
callq 0x21b0
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2daa
leaq 0x83c8(%rip), %rdi      # 0xb0c2
movq 0x10(%rsp), %rsi
jmp 0x2d28
leaq 0x83dd(%rip), %rdi      # 0xb0e5
movq %r15, %rsi
jmp 0x2d3e
movq %rbx, %r14
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2dbb
leaq 0x839d(%rip), %rdi      # 0xb0c2
movq %r14, %rsi
xorl %eax, %eax
callq 0x8258
jmp 0x2bb1
leaq 0x83aa(%rip), %rdi      # 0xb0e5
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8258
callq 0x20a0
andl $0x0, (%rax)
jmp 0x2bb1
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2dd4
leaq 0x83d2(%rip), %rdi      # 0xb135
jmp 0x2b94
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2de3
leaq 0x83d8(%rip), %rdi      # 0xb151
jmp 0x2b94
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2df2
leaq 0x83d7(%rip), %rdi      # 0xb166
jmp 0x2b94
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e01
leaq 0x83fa(%rip), %rdi      # 0xb19f
jmp 0x2b94
movq %rax, %rbx
leaq 0x830e(%rip), %rdi      # 0xb0c2
movq 0x10(%rsp), %rsi
jmp 0x2dc8
movq %rax, %rbx
leaq 0x82fd(%rip), %rdi      # 0xb0c2
movq %r14, %rsi
xorl %eax, %eax
callq 0x80c9
jmp 0x2bae
movq %rax, %rbx
leaq 0x8357(%rip), %rdi      # 0xb135
jmp 0x2ba7
movq %rax, %rbx
leaq 0x8364(%rip), %rdi      # 0xb151
jmp 0x2ba7
movq %rax, %rbx
leaq 0x836a(%rip), %rdi      # 0xb166
jmp 0x2ba7
movq %rax, %rbx
leaq 0x8394(%rip), %rdi      # 0xb19f
jmp 0x2ba7
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x2e26
leaq 0x8375(%rip), %rdi      # 0xb196
jmp 0x2b94
movq %rax, %rbx
leaq 0x8366(%rip), %rdi      # 0xb196
jmp 0x2ba7