// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %r14
movq $0x0, 0x10(%rsp)
pushq $0x1
popq %r15
leaq 0x13de3(%rip), %r12     # 0x18940
leaq 0x4(%rsp), %rbp
movslq (%r14), %rax
cmpq %rax, %r15
jge 0x4da7
movq 0x68(%r14), %rax
movq -0x8(%rax,%r15,8), %rbx
movq (%rax,%r15,8), %r13
leaq 0xa(%r13), %rdi
movq %r12, %rsi
callq 0x2150
testl %eax, %eax
je 0x4bb9
movq %r14, %rdi
movl %r15d, %esi
leaq 0x143a3(%rip), %rdx     # 0x18f3b
movq %rbp, %rcx
callq 0x4777
movq %r14, %rdi
movl %r15d, %esi
leaq 0x14fd3(%rip), %rdx     # 0x19b80
movq %rbp, %rcx
callq 0x4777
testl %eax, %eax
je 0x4bbe
incq %r15
jmp 0x4b62
movq %r14, %rdi
movl %r15d, %esi
leaq 0x13d53(%rip), %rdx     # 0x1891e
movq %rsp, %rcx
callq 0x4777
testl %eax, %eax
je 0x4bb9
leaq -0x1(%r15), %rsi
movq %r14, %rdi
leaq 0x149cf(%rip), %rdx     # 0x195b4
leaq 0xc(%rsp), %rcx
callq 0x4777
testl %eax, %eax
je 0x4bb9
movq %r14, %rdi
movl %r15d, %esi
leaq 0x151e8(%rip), %rdx     # 0x19de8
leaq 0x8(%rsp), %rcx
callq 0x4777
testl %eax, %eax
je 0x4bb9
movl (%r13), %eax
movl %eax, 0x4(%rsp)
leaq 0x188(%r13), %rax
movq %rax, 0x18(%rsp)
movslq (%rsp), %rax
imulq $0xc, %rax, %rax
leaq (%rax,%r13), %rdi
addq $0x188, %rdi            # imm = 0x188
movslq 0xc(%rsp), %rax
imulq $0xc, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x188, %rsi            # imm = 0x188
callq 0x3abc
movaps %xmm0, 0x20(%rsp)
movslq (%rsp), %rax
imulq $0xc, %rax, %rax
leaq (%rax,%r13), %rdi
addq $0x188, %rdi            # imm = 0x188
movslq 0x8(%rsp), %rax
imulq $0xc, %rax, %rax
leaq (%rax,%r13), %rsi
addq $0x188, %rsi            # imm = 0x188
callq 0x3abc
movaps 0x20(%rsp), %xmm3
movslq (%rsp), %rax
movslq 0xc(%rsp), %rcx
movslq 0x8(%rsp), %rdx
movslq 0x4(%rsp), %rsi
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
imulq $0xc, %rax, %rdi
leaq (%rdi,%r13), %rax
addq $0x188, %rax            # imm = 0x188
imulq $0xc, %rcx, %rcx
addq %rbx, %rcx
addq $0x188, %rcx            # imm = 0x188
imulq $0xc, %rdx, %rdx
addq %r13, %rdx
addq $0x188, %rdx            # imm = 0x188
imulq $0xc, %rsi, %rsi
leaq (%rsi,%r13), %r8
addq $0x188, %r8             # imm = 0x188
xorl %r9d, %r9d
cmpq $0xc, %r9
je 0x4d19
movss (%rax,%r9), %xmm0
movss (%rdx,%r9), %xmm1
movss (%rcx,%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
jmp 0x4cd6
movq 0x18(%rsp), %rax
addq %rax, %rdi
addq %rax, %rsi
callq 0x3abc
movslq (%rsp), %rcx
movslq 0x4(%rsp), %rax
cvtss2sd %xmm0, %xmm0
imulq $0xc, %rcx, %rcx
addq %r13, %rcx
addq $0x188, %rcx            # imm = 0x188
imulq $0xc, %rax, %rdx
addq %r13, %rdx
addq $0x188, %rdx            # imm = 0x188
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x4d86
movss (%rcx,%rsi,4), %xmm1
cvtss2sd %xmm1, %xmm2
movss (%rdx,%rsi,4), %xmm3
subss %xmm1, %xmm3
cvtss2sd %xmm3, %xmm1
divsd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rdx,%rsi,4)
incq %rsi
jmp 0x4d54
leaq (%rax,%rax,4), %rax
movw $0x48, 0x10(%r13,%rax)
incl (%r13)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
jmp 0x4bb9
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop