// File: tplinderoth[P]introDist/introDist.cpp
// Function: distAnalysis(int, char**)
int distAnalysis(int argc, char** argv) {

	int rv = 0;
	std::string dist_t(argv[1]);
	std::fstream freqfile;
	std::fstream genofile;
	std::string genofname;
	unsigned int window = 1;
	unsigned int step = 1;
	int useAvg = 1; // whether to use genome or window average for comp2Dist
	int avgtype = 0;
	double distance = -1;

	if ((rv = parseArgs(argc, argv, freqfile, genofile, window, step, &genofname, useAvg, avgtype, distance, &dist_t)) == 0) {
		if (dist_t.compare("comp2Dist") == 0) {
			double* dptr = distance >= 0 ? &distance : NULL;
			rv = comp2Dist(freqfile, genofile, window, step, useAvg, &genofname, dptr);
		}
		else if (dist_t.compare("comp3Dist") == 0) {
			rv = comp3Dist(freqfile, genofile, window, step);
		}
		else if (dist_t.compare("avgDist") == 0) {
			rv = avgDist(freqfile, genofile, avgtype);
		}
		else {
			rv = -1;
			std::cerr << "\n" << dist_t << " is an invalid function\n";
		}
	} else if (rv == 1) {
		rv = 0;
	}

	if (freqfile.is_open())
		freqfile.close();
	if (genofile.is_open())
		genofile.close();

	return rv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x4c0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
callq 0x34d0
movq -0x4c0(%rbp), %rsi
movq -0x4b8(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x9000
jmp 0x38e1
leaq -0x39(%rbp), %rdi
callq 0x3310
leaq -0x260(%rbp), %rdi
callq 0x3360
jmp 0x38f8
leaq -0x470(%rbp), %rdi
callq 0x3360
jmp 0x3906
leaq -0x490(%rbp), %rdi
movq %rdi, -0x4d0(%rbp)
callq 0x33d0
movq -0x4d0(%rbp), %rcx
movl $0x1, -0x494(%rbp)
movl $0x1, -0x498(%rbp)
movl $0x1, -0x49c(%rbp)
movl $0x0, -0x4a0(%rbp)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x4a8(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movq %rsp, %rax
leaq -0x38(%rbp), %rdx
movq %rdx, 0x20(%rax)
leaq -0x4a8(%rbp), %rdx
movq %rdx, 0x18(%rax)
leaq -0x4a0(%rbp), %rdx
movq %rdx, 0x10(%rax)
leaq -0x49c(%rbp), %rdx
movq %rdx, 0x8(%rax)
movq %rcx, (%rax)
leaq -0x260(%rbp), %rdx
leaq -0x470(%rbp), %rcx
leaq -0x494(%rbp), %r8
leaq -0x498(%rbp), %r9
callq 0x3c90
movl %eax, -0x4c4(%rbp)
jmp 0x39b8
movl -0x4c4(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jne 0x3bb6
leaq -0x38(%rbp), %rdi
leaq 0xb69b(%rip), %rsi      # 0xf070
callq 0x3100
cmpl $0x0, %eax
jne 0x3ad2
movsd -0x4a8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x3a04
leaq -0x4a8(%rbp), %rax
movq %rax, -0x4d8(%rbp)
jmp 0x3a0f
xorl %eax, %eax
movq %rax, -0x4d8(%rbp)
jmp 0x3a0f
movq -0x4d8(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movl -0x494(%rbp), %edx
movl -0x498(%rbp), %ecx
movl -0x49c(%rbp), %r8d
movq -0x4b0(%rbp), %rsi
movq %rsp, %rax
movq %rsi, (%rax)
leaq -0x260(%rbp), %rdi
leaq -0x470(%rbp), %rsi
leaq -0x490(%rbp), %r9
callq 0x4330
movl %eax, -0x4dc(%rbp)
jmp 0x3a5f
movl -0x4dc(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x3bb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x3310
jmp 0x3c7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3c76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3c6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x31b0
leaq -0x470(%rbp), %rdi
callq 0x30c0
jmp 0x3c6a
leaq -0x38(%rbp), %rdi
leaq 0xb59d(%rip), %rsi      # 0xf07a
callq 0x3100
cmpl $0x0, %eax
jne 0x3b1c
movl -0x494(%rbp), %edx
movl -0x498(%rbp), %ecx
leaq -0x260(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x4440
movl %eax, -0x4e0(%rbp)
jmp 0x3b0e
movl -0x4e0(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x3bb2
leaq -0x38(%rbp), %rdi
leaq 0xb55d(%rip), %rsi      # 0xf084
callq 0x3100
cmpl $0x0, %eax
jne 0x3b5d
movl -0x4a0(%rbp), %edx
leaq -0x260(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x50c0
movl %eax, -0x4e4(%rbp)
jmp 0x3b52
movl -0x4e4(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x3bb0
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq 0x11485(%rip), %rdi     # 0x14ff0
leaq 0xc07a(%rip), %rsi      # 0xfbec
callq 0x32c0
movq %rax, -0x4f0(%rbp)
jmp 0x3b80
movq -0x4f0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3280
movq %rax, -0x4f8(%rbp)
jmp 0x3b99
movq -0x4f8(%rbp), %rdi
leaq 0xb4e5(%rip), %rsi      # 0xf08c
callq 0x32c0
jmp 0x3bae
jmp 0x3bb0
jmp 0x3bb2
jmp 0x3bb4
jmp 0x3bc5
cmpl $0x1, -0x14(%rbp)
jne 0x3bc3
movl $0x0, -0x14(%rbp)
jmp 0x3bc5
leaq -0x260(%rbp), %rdi
callq 0x3490
movb %al, -0x4f9(%rbp)
jmp 0x3bd9
movb -0x4f9(%rbp), %al
testb $0x1, %al
jne 0x3be5
jmp 0x3bf5
leaq -0x260(%rbp), %rdi
callq 0x3050
jmp 0x3bf3
jmp 0x3bf5
leaq -0x470(%rbp), %rdi
callq 0x3490
movb %al, -0x4fa(%rbp)
jmp 0x3c09
movb -0x4fa(%rbp), %al
testb $0x1, %al
jne 0x3c15
jmp 0x3c25
leaq -0x470(%rbp), %rdi
callq 0x3050
jmp 0x3c23
jmp 0x3c25
movl -0x14(%rbp), %eax
movl %eax, -0x500(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x31b0
leaq -0x470(%rbp), %rdi
callq 0x30c0
leaq -0x260(%rbp), %rdi
callq 0x30c0
leaq -0x38(%rbp), %rdi
callq 0x31b0
movl -0x500(%rbp), %eax
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x30c0
leaq -0x38(%rbp), %rdi
callq 0x31b0
movq -0x48(%rbp), %rdi
callq 0x34c0
nopl (%rax,%rax)