// File: gjoni[P]iPot/src/Chain.cpp
// Function: Chain::SetTermini()
void Chain::SetTermini() {

	/* first residue is N-terminal */
	residue[0].ntFlag = true;

	/* last residue is C-terminal */
	residue[nRes - 1].ctFlag = true;

	/* check residues in between */
	double x, y, z, d;
	for (int i = 1; i < nRes; i++) {
		if (residue[i - 1].CA != NULL && residue[i].CA != NULL) {
			x = residue[i - 1].CA->x - residue[i].CA->x;
			y = residue[i - 1].CA->y - residue[i].CA->y;
			z = residue[i - 1].CA->z - residue[i].CA->z;
			d = sqrt(x * x + y * y + z * z);
			if (d > 4.25) { /* as in TM-align */
				residue[i - 1].ctFlag = true;
				residue[i].ntFlag = true;
			}
		}
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq 0x40(%rcx), %rax
movb $0x1, 0x158(%rax)
movq 0x40(%rcx), %rax
movl 0x48(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movb $0x1, 0x159(%rax)
movl $0x1, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x48(%rcx), %eax
jge 0x1ad5f
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
cmpq $0x0, 0x168(%rax)
je 0x1ad4f
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
cmpq $0x0, 0x168(%rax)
je 0x1ad4f
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
movsd 0x10(%rcx), %xmm0
movq 0x40(%rax), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
subsd 0x10(%rcx), %xmm0
movsd %xmm0, -0x10(%rbp)
movq 0x40(%rax), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
movsd 0x18(%rcx), %xmm0
movq 0x40(%rax), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
subsd 0x18(%rcx), %xmm0
movsd %xmm0, -0x18(%rbp)
movq 0x40(%rax), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
movsd 0x20(%rcx), %xmm0
movq 0x40(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movq 0x168(%rax), %rax
subsd 0x20(%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x10(%rbp), %xmm1
movsd -0x10(%rbp), %xmm2
movsd -0x18(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x20(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x3220
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x184fc(%rip), %xmm1    # 0x33208
ucomisd %xmm1, %xmm0
jbe 0x1ad4d
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movb $0x1, 0x159(%rcx)
movq 0x40(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movb $0x1, 0x158(%rax)
jmp 0x1ad4f
jmp 0x1ad51
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1ab94
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)