// File: /workspace/github_c_makefile_star2_O1/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 0x55f3
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
movl $0x1, %r15d
leaq 0x14597(%rip), %r12     # 0x19930
movq %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 0x53e7
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x14b9d(%rip), %rdx     # 0x19f63
movq %rbp, %rcx
callq 0x4f78
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x15805(%rip), %rdx     # 0x1abe0
movq %rbp, %rcx
callq 0x4f78
testl %eax, %eax
je 0x53f7
incq %r15
movslq (%rbx), %rax
cmpq %rax, %r15
jl 0x539c
jmp 0x55f3
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x1450a(%rip), %rdx     # 0x1990e
leaq 0x4(%rsp), %rcx
callq 0x4f78
testl %eax, %eax
je 0x53e7
leaq -0x1(%r15), %rsi
movq %rbx, %rdi
leaq 0x151d4(%rip), %rdx     # 0x1a5f4
leaq 0xc(%rsp), %rcx
callq 0x4f78
testl %eax, %eax
je 0x53e7
movq %rbx, %rdi
movl %r15d, %esi
leaq 0x15a0d(%rip), %rdx     # 0x1ae48
leaq 0x8(%rsp), %rcx
callq 0x4f78
testl %eax, %eax
je 0x53e7
movl (%r13), %eax
movl %eax, (%rsp)
leaq 0x188(%r13), %rax
movq %rax, 0x18(%rsp)
movslq 0x4(%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 0x40d5
movaps %xmm0, 0x20(%rsp)
movslq 0x4(%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 0x40d5
movaps 0x20(%rsp), %xmm3
movslq 0x4(%rsp), %rax
movslq 0xc(%rsp), %rcx
movslq 0x8(%rsp), %rdx
movslq (%rsp), %rsi
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
leaq (%rax,%rax,2), %rax
leaq 0x188(%r13,%rax,4), %rax
leaq (%rcx,%rcx,2), %rcx
leaq 0x188(%r14,%rcx,4), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq 0x188(,%rdx,4), %rdx
addq %r13, %rdx
leaq (%rsi,%rsi,2), %rsi
leaq 0x188(,%rsi,4), %rsi
addq %r13, %rsi
xorl %edi, %edi
movss (%rax,%rdi), %xmm0
movss (%rdx,%rdi), %xmm1
movss (%rcx,%rdi), %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, (%rsi,%rdi)
addq $0x4, %rdi
cmpq $0xc, %rdi
jne 0x550b
movslq 0x4(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movslq (%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,4), %rsi
callq 0x40d5
movslq 0x4(%rsp), %rax
movslq (%rsp), %rcx
cvtss2sd %xmm0, %xmm0
leaq (%rax,%rax,2), %rax
leaq 0x188(,%rax,4), %rax
addq %r13, %rax
leaq (%rcx,%rcx,2), %rcx
leaq 0x188(,%rcx,4), %rcx
addq %r13, %rcx
xorl %edx, %edx
movss (%rax,%rdx,4), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
movss (%rcx,%rdx,4), %xmm3
subss %xmm1, %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
divsd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rcx,%rdx,4)
incq %rdx
cmpq $0x3, %rdx
jne 0x5598
movslq (%rsp), %rax
leaq (%rax,%rax,4), %rax
movw $0x48, 0x10(%r13,%rax)
incl (%r13)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
jmp 0x53e7
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop