// File: /workspace/github_c_makefile_star2_O1/genevalab[P]msmove/streec.c
// Function: ca
int ca(int nsam, int nsites, int c1, int c2)
{
	int yes1, yes2, seg, start, end, desc, k;
	int seg1 = 0;
	int seg2 = 0;
	int tseg = -1;
	struct seg *pseg;
	struct node *ptree;

	if (!(pseg = (struct seg*)calloc((size_t)nsegs, sizeof(struct seg)))) 
		perror("alloc error.ca1");

	for (seg=0, k=0; k < nsegs; seg = seglst[seg].next, k++)
	{
		start = seglst[seg].beg;
		yes1 = isseg(start, c1, &seg1);
		yes2 = isseg(start, c2, &seg2);
		if (yes1 || yes2)
		{
			tseg++;
			(pseg+tseg)->beg = seglst[seg].beg;
			end = k < nsegs-1 ? seglst[seglst[seg].next].beg-1 : nsites-1;
			(pseg+tseg)->end = end;
			if (yes1 && yes2)
			{
				nnodes[seg]++;
				if (nnodes[seg] >= 2*nsam-2)
					tseg--;
				else
					(pseg+tseg)->desc = nnodes[seg];
				ptree = seglst[seg].ptree;
				desc = (chrom[c1].pseg+seg1)->desc;
				(ptree+desc)->abv = nnodes[seg];
				desc = (chrom[c2].pseg+seg2)-> desc;
				(ptree+desc)->abv = nnodes[seg];
				(ptree+nnodes[seg])->time = t;
			}
			else
				(pseg+tseg)->desc = yes1 ? (chrom[c1].pseg+seg1)->desc : (chrom[c2].pseg+seg2)->desc;
		}
	}
	nlinks -= links(c1);
	cleft -= 1.0-pow(pc, (double)links(c1));
	free(chrom[c1].pseg);
	if (tseg < 0)
	{
		free(pseg);
		chrom[c1].pseg = chrom[nchrom-1].pseg;
		chrom[c1].nseg = chrom[nchrom-1].nseg;
		chrom[c1].pop = chrom[nchrom-1].pop;
		if (c2 == nchrom-1)
			c2 = c1;
		nchrom--;
	}
	else
	{
		if(!(pseg = (struct seg*)realloc(pseg, (size_t)(tseg+1)*sizeof(struct seg))))
			perror(" realloc error. ca1");
		chrom[c1].pseg = pseg;
		chrom[c1].nseg = tseg+1;
		nlinks += links(c1);
	   	cleft += 1.0-pow(pc, (double)links(c1));
	}
	nlinks -= links(c2);
	cleft -= 1.0-pow(pc, (double)links(c2));
	free(chrom[c2].pseg);
	chrom[c2].pseg = chrom[nchrom-1].pseg;
	chrom[c2].nseg = chrom[nchrom-1].nseg;
	chrom[c2].pop = chrom[nchrom-1].pop;
	nchrom--;
	if (tseg < 0)
		return 2;
	else 
		return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %ecx, %ebx
movl %edx, %r14d
movl %esi, -0x4c(%rbp)
movl %edi, %r13d
movslq 0x5b85(%rip), %rdi      # 0xb560
movl $0xc, %esi
callq 0x1050
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x5eb3
movl 0x5b68(%rip), %edx      # 0xb560
movl %r14d, -0x44(%rbp)
movslq %r14d, %rsi
testl %edx, %edx
movl %ebx, -0x2c(%rbp)
movq %rsi, -0x70(%rbp)
jle 0x5c90
movq 0x5b33(%rip), %r8       # 0xb548
movq 0x5b14(%rip), %rcx      # 0xb530
shlq $0x4, %rsi
leaq (%rcx,%rsi), %rax
movq %rax, -0xa0(%rbp)
leaq (%rcx,%rsi), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
movq (%rax), %rax
movslq %ebx, %rsi
shlq $0x4, %rsi
leaq (%rcx,%rsi), %rdi
movq %rdi, -0x98(%rbp)
addq %rsi, %rcx
addq $0x8, %rcx
movq %rcx, -0x60(%rbp)
movq (%rcx), %rcx
movq 0x5adf(%rip), %rsi      # 0xb540
movq %rsi, -0x58(%rbp)
leal -0x2(%r13,%r13), %esi
movl %esi, -0x48(%rbp)
movq %rax, -0x90(%rbp)
addq $0xc, %rax
movq %rax, -0x80(%rbp)
movq %rcx, -0x88(%rbp)
leaq 0xc(%rcx), %rax
movq %rax, -0x78(%rbp)
xorl %r11d, %r11d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r8, -0x40(%rbp)
movslq %ecx, %rsi
leaq (%rsi,%rsi,2), %r12
movl (%r8,%r12,8), %r8d
movq -0xa0(%rbp), %rax
movl (%rax), %ecx
cmpl %ecx, %r14d
jge 0x5ad0
movslq %r14d, %rdi
leaq (%rdi,%rdi,2), %rdi
movq -0x90(%rbp), %rax
cmpl %r8d, (%rax,%rdi,4)
jle 0x5bd4
xorl %r9d, %r9d
movq -0x98(%rbp), %rax
movl (%rax), %r15d
cmpl %r15d, %r13d
jge 0x5afa
movslq %r13d, %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x88(%rbp), %rax
cmpl %r8d, (%rax,%rcx,4)
jle 0x5c0a
xorl %ecx, %ecx
movl %r9d, %eax
orb %cl, %al
cmpb $0x1, %al
jne 0x5bcc
leal 0x1(%rbx), %r15d
movslq %r15d, %rax
leaq (%rax,%rax,2), %rdi
movq -0x38(%rbp), %rax
movl %r8d, (%rax,%rdi,4)
decl %edx
movl -0x4c(%rbp), %r8d
cmpl %edx, %r11d
jge 0x5b38
movq -0x40(%rbp), %rdx
movslq 0x10(%rdx,%r12,8), %rax
leaq (%rax,%rax,2), %rax
movl (%rdx,%rax,8), %r8d
movq -0x38(%rbp), %rax
leaq (%rax,%rdi,4), %rdx
decl %r8d
movl %r8d, 0x4(%rdx)
andb %r9b, %cl
cmpb $0x1, %cl
jne 0x5c3c
movq -0x58(%rbp), %rax
movl (%rax,%rsi,4), %ecx
incl %ecx
movl %ecx, (%rax,%rsi,4)
cmpl -0x48(%rbp), %ecx
movq -0x40(%rbp), %r8
jge 0x5b6e
movl %ecx, 0x8(%rdx)
movl %r15d, %ebx
movq 0x8(%r8,%r12,8), %rax
movq -0x68(%rbp), %rdx
movq (%rdx), %rdx
movslq %r14d, %rdi
leaq (%rdi,%rdi,2), %rdi
movslq 0x8(%rdx,%rdi,4), %rdx
shlq $0x4, %rdx
movl %ecx, (%rax,%rdx)
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
movslq %r13d, %rdx
leaq (%rdx,%rdx,2), %rdx
movslq 0x8(%rcx,%rdx,4), %rcx
movq -0x58(%rbp), %rdi
movl (%rdi,%rsi,4), %edx
shlq $0x4, %rcx
movl %edx, (%rax,%rcx)
movsd 0x59b2(%rip), %xmm0     # 0xb568
movslq (%rdi,%rsi,4), %rcx
shlq $0x4, %rcx
movsd %xmm0, 0x8(%rax,%rcx)
movl %ebx, %r15d
jmp 0x5c64
movl %ebx, %r15d
jmp 0x5c60
movq -0x80(%rbp), %rax
leaq (%rax,%rdi,4), %r15
leal -0x1(%rcx), %edi
cmpl %r8d, -0x8(%r15)
setge %r9b
jge 0x5ad3
cmpl %r14d, %edi
je 0x5c80
incl %r14d
leaq 0xc(%r15), %r10
cmpl %r8d, (%r15)
movq %r10, %r15
jle 0x5bdf
jmp 0x5ad3
movq -0x78(%rbp), %rax
leaq (%rax,%rcx,4), %rdi
leal -0x1(%r15), %r10d
cmpl %r8d, -0x8(%rdi)
setge %cl
jge 0x5afc
cmpl %r13d, %r10d
je 0x5c88
incl %r13d
leaq 0xc(%rdi), %rax
cmpl %r8d, (%rdi)
movq %rax, %rdi
jle 0x5c16
jmp 0x5afc
testb %r9b, %r9b
movq -0x60(%rbp), %rax
cmovneq -0x68(%rbp), %rax
movl %r13d, %ecx
cmovnel %r14d, %ecx
movq (%rax), %rax
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,4), %eax
movl %eax, 0x8(%rdx)
movq -0x40(%rbp), %r8
movl 0x10(%r8,%r12,8), %ecx
incl %r11d
movl 0x58ee(%rip), %edx      # 0xb560
movl %r15d, %ebx
cmpl %edx, %r11d
jl 0x5a9f
jmp 0x5c96
movl %ecx, %r14d
jmp 0x5ad3
movl %r15d, %r13d
jmp 0x5afc
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq 0x5893(%rip), %rax      # 0xb530
movq -0x70(%rbp), %r12
shlq $0x4, %r12
movslq (%rax,%r12), %rcx
movq 0x8(%rax,%r12), %rax
leaq (%rcx,%rcx,2), %rcx
movslq -0x8(%rax,%rcx,4), %rcx
movslq (%rax), %rax
subq %rax, %rcx
subq %rcx, 0x5894(%rip)      # 0xb558
movsd 0x58a4(%rip), %xmm0     # 0xb570
cvtsi2sd %ecx, %xmm1
callq 0x1190
movsd 0x132b(%rip), %xmm1     # 0x7008
subsd %xmm0, %xmm1
movsd 0x5897(%rip), %xmm0     # 0xb580
subsd %xmm1, %xmm0
movsd %xmm0, 0x588b(%rip)     # 0xb580
movq 0x5834(%rip), %rbx      # 0xb530
movq 0x8(%rbx,%r12), %rdi
callq 0x10e0
testl %r15d, %r15d
js 0x5d9a
movl %r15d, %eax
incl %r15d
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
addq $0xc, %rsi
movq -0x38(%rbp), %rdi
callq 0x1170
movq %rax, %r14
testq %rax, %rax
je 0x5ec4
movq 0x57f3(%rip), %rax      # 0xb530
movq %r14, 0x8(%rax,%r12)
movl %r15d, (%rax,%r12)
movl %r15d, %eax
leaq (%rax,%rax,2), %rax
movslq -0x8(%r14,%rax,4), %rax
movslq (%r14), %rcx
subq %rcx, %rax
addq %rax, 0x57f9(%rip)      # 0xb558
movsd 0x5809(%rip), %xmm0     # 0xb570
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
callq 0x1190
movsd 0x128d(%rip), %xmm1     # 0x7008
subsd %xmm0, %xmm1
addsd 0x57f9(%rip), %xmm1     # 0xb580
movsd %xmm1, 0x57f1(%rip)     # 0xb580
movl $0x1, %r14d
movl -0x2c(%rbp), %ecx
jmp 0x5df6
leaq (%rbx,%r12), %r14
addq $0x8, %r14
movq -0x38(%rbp), %rdi
callq 0x10e0
movslq 0x579e(%rip), %rax      # 0xb550
shlq $0x4, %rax
movq -0x8(%rbx,%rax), %rcx
movq %rcx, (%r14)
movl -0x10(%rbx,%rax), %eax
movl %eax, -0x8(%r14)
movslq 0x5783(%rip), %rax      # 0xb550
shlq $0x4, %rax
movl -0xc(%rbx,%rax), %eax
movl %eax, -0x4(%r14)
movl 0x5771(%rip), %eax      # 0xb550
decl %eax
movl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
cmovel -0x44(%rbp), %ecx
movl %eax, 0x5760(%rip)      # 0xb550
movl $0x2, %r14d
movq 0x5733(%rip), %rax      # 0xb530
movslq %ecx, %rbx
shlq $0x4, %rbx
movslq (%rax,%rbx), %rcx
movq 0x8(%rax,%rbx), %rax
leaq (%rcx,%rcx,2), %rcx
movslq -0x8(%rax,%rcx,4), %rcx
movslq (%rax), %rax
subq %rax, %rcx
subq %rcx, 0x5735(%rip)      # 0xb558
movsd 0x5745(%rip), %xmm0     # 0xb570
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
callq 0x1190
movsd 0x11c9(%rip), %xmm1     # 0x7008
subsd %xmm0, %xmm1
movsd 0x5735(%rip), %xmm0     # 0xb580
subsd %xmm1, %xmm0
movsd %xmm0, 0x5729(%rip)     # 0xb580
movq 0x56d2(%rip), %r15      # 0xb530
movq 0x8(%r15,%rbx), %rdi
callq 0x10e0
movslq 0x56e1(%rip), %rax      # 0xb550
shlq $0x4, %rax
movq -0x8(%r15,%rax), %rcx
movq %rcx, 0x8(%r15,%rbx)
movl -0x10(%r15,%rax), %eax
movl %eax, (%r15,%rbx)
movslq 0x56c3(%rip), %rax      # 0xb550
shlq $0x4, %rax
movl -0xc(%r15,%rax), %eax
movl %eax, 0x4(%r15,%rbx)
decl 0x56af(%rip)            # 0xb550
movl %r14d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2019(%rip), %rdi      # 0x7ed3
callq 0x1090
jmp 0x59f2
leaq 0x2018(%rip), %rdi      # 0x7ee3
callq 0x1090
jmp 0x5d36