// File: /workspace/github_c_makefile_star2_O3/josch[P]stride/place_h.c
// Function: PlaceHydrogens
int PlaceHydrogens(CHAIN *Chain)
{

  int Res, i, N, C, CA, H, PlacedCnt=0;
  float Length_N_C, Length_N_CA, Length_N_H;
  RESIDUE *r, *rr;
  
  for( Res=1; Res<Chain->NRes; Res++ ) {
    
    r  = Chain->Rsd[Res];
    rr = Chain->Rsd[Res-1];

      if( !strcmp(r->ResType,"PRO") ) continue;

      /* Replace deiterium atoms by hydrogens */
      if( FindAtom(Chain,Res,"D",&H) ) 
	strcmp(r->AtomType[H],"H");

      if( !FindAtom(Chain,Res,"H",&H)  && FindAtom(Chain,Res,"N",&N)   &&
	   FindAtom(Chain,Res-1,"C",&C) && FindAtom(Chain,Res,"CA",&CA) ) {

	H = r->NAtom;
	
	Length_N_C   = Dist(r->Coord[N],rr->Coord[C]);
	Length_N_CA  = Dist(r->Coord[N],r->Coord[CA]);
	
	for( i=0; i<3; i++ )
	  r->Coord[H][i] = r->Coord[N][i] - 
	      ( (rr->Coord[C][i] -  r->Coord[N][i])/Length_N_C +
	        (r->Coord[CA][i]  -  r->Coord[N][i])/Length_N_CA );

	Length_N_H = Dist(r->Coord[N],r->Coord[H]);

	for( i=0; i<3; i++ )
	  r->Coord[H][i] = r->Coord[N][i] + 
	    DIST_N_H*(r->Coord[H][i]-r->Coord[N][i])/Length_N_H;

	strcpy(r->AtomType[H],"H");
	r->NAtom++;
	PlacedCnt++;
      }
    }
  return(PlacedCnt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq $0x0, 0x10(%rsp)
cmpl $0x2, (%rdi)
jl 0x550e
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
movl $0x1, %r15d
leaq 0x1467b(%rip), %r12     # 0x19940
leaq 0x4(%rsp), %rbp
movq 0x68(%rbx), %rax
movq -0x8(%rax,%r15,8), %r14
movq (%rax,%r15,8), %r13
leaq 0xa(%r13), %rdi
movq %r12, %rsi
callq 0x2150
testl %eax, %eax
je 0x5315
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x14c77(%rip), %rdx     # 0x19f6b
movq %rbp, %rcx
callq 0x4ea0
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x158c7(%rip), %rdx     # 0x1abd0
movq %rbp, %rcx
callq 0x4ea0
testl %eax, %eax
je 0x5325
incq %r15
movslq (%rbx), %rax
cmpq %rax, %r15
jl 0x52ca
jmp 0x550e
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x145ec(%rip), %rdx     # 0x1991e
movq %rsp, %rcx
callq 0x4ea0
testl %eax, %eax
je 0x5315
leaq -0x1(%r15), %rsi
movq %rbx, %rdi
leaq 0x15298(%rip), %rdx     # 0x1a5e4
leaq 0xc(%rsp), %rcx
callq 0x4ea0
testl %eax, %eax
je 0x5315
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x15ad1(%rip), %rdx     # 0x1ae38
leaq 0x8(%rsp), %rcx
callq 0x4ea0
testl %eax, %eax
je 0x5315
movl (%r13), %eax
movl %eax, 0x4(%rsp)
leaq 0x188(%r13), %rax
movq %rax, 0x18(%rsp)
movslq (%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0x188(%r13,%rax,4), %rdi
movslq 0xc(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq (%r14,%rax,4), %rsi
addq $0x188, %rsi            # imm = 0x188
callq 0x40c3
movaps %xmm0, 0x20(%rsp)
movslq (%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0x188(,%rax,4), %rdi
addq %r13, %rdi
movslq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0x188(,%rax,4), %rsi
addq %r13, %rsi
callq 0x40c3
movaps 0x20(%rsp), %xmm3
movslq (%rsp), %rax
movslq 0xc(%rsp), %rdx
movslq 0x8(%rsp), %rsi
movslq 0x4(%rsp), %r8
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
leaq (%rax,%rax,2), %rax
leaq 0x188(%r13,%rax,4), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq 0x188(%r14,%rdx,4), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq 0x188(,%rsi,4), %rdi
addq %r13, %rdi
leaq (%r8,%r8,2), %rsi
leaq 0x188(,%rsi,4), %r8
addq %r13, %r8
xorl %r9d, %r9d
movss (%rcx,%r9), %xmm0
movss (%rdi,%r9), %xmm1
movss (%rdx,%r9), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
movaps %xmm0, %xmm1
shufps $0x0, %xmm0, %xmm1      # xmm1 = xmm1[0,0],xmm0[0,0]
subps %xmm1, %xmm2
divps %xmm3, %xmm2
movaps %xmm2, %xmm1
shufps $0x55, %xmm2, %xmm1     # xmm1 = xmm1[1,1],xmm2[1,1]
addss %xmm2, %xmm1
subss %xmm1, %xmm0
movss %xmm0, (%r8,%r9)
addq $0x4, %r9
cmpq $0xc, %r9
jne 0x5437
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
leaq (%rcx,%rsi,4), %rsi
callq 0x40c3
movslq (%rsp), %rcx
movslq 0x4(%rsp), %rax
cvtss2sd %xmm0, %xmm0
leaq (%rcx,%rcx,2), %rcx
leaq 0x188(,%rcx,4), %rcx
addq %r13, %rcx
leaq (%rax,%rax,2), %rdx
leaq 0x188(,%rdx,4), %rdx
addq %r13, %rdx
xorl %esi, %esi
movss (%rcx,%rsi,4), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
movss (%rdx,%rsi,4), %xmm3
subss %xmm1, %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
divsd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rdx,%rsi,4)
incq %rsi
cmpq $0x3, %rsi
jne 0x54b7
leaq (%rax,%rax,4), %rax
movw $0x48, 0x10(%r13,%rax)
incl (%r13)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
jmp 0x5315
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop