// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/output_tnm.c
// Function: Write_coord
int Write_coord(char *name_out, double *atoms_ref,
		atom *atoms, int *atom_num, int N_atom_ref,
		struct residue *seq, char chain, int i_model)
{
  int i, ini=0, m=0, ires=0, iatom=0, print_bb=1, nprint_B, nprint_S;
  int *printed=malloc(N_atom_ref*sizeof(int));
  struct residue *res;
  char aaname3[4]; FILE *fh;
  atom *atom1=NULL;

  // printf("Printing PDB %d\n", i_model);
  if(i_model==0){
    fh=fopen(name_out, "w");
  }else{
    fh=fopen(name_out, "a");
  }
  fprintf(fh, "MODEL %d: ", i_model+1);
  if(i_model==0){
    fprintf(fh, "STR.1\n");
  }else if(i_model > 0){
    fprintf(fh, "%d normal modes\n", i_model);
  }else if(i_model<0){
    fprintf(fh, "STR.2\n");
  }
  for(i=0; i<4; i++)aaname3[i]='\0';


  int jatom=0;
  ires=0; ini=0; print_bb=1; iatom=0;
  for (i=ini;i<N_atom_ref;i++)printed[i]=0;
  while(iatom < N_atom_ref){

    nprint_B=0;  nprint_S=0;
    for (i=ini;i<N_atom_ref;i++){
      if(printed[i])continue;
      atom1=atoms+atom_num[i];
      if(atom1->res > ires)break;
      if((strncmp(atom1->name, "N ", 2)==0)||
	 (strncmp(atom1->name, "CA", 2)==0)||
	 (strncmp(atom1->name, "C ", 2)==0)||
	 (strncmp(atom1->name, "O ", 2)==0)){
	if(print_bb){nprint_B=1; break;}
      }else{
	if(print_bb==0){nprint_S=1; break;}
      }
    }
    if((print_bb) && (nprint_B==0)){print_bb=0; continue;}
    if((print_bb==0) && (nprint_S==0)){
      ires=ires+1; ini=i; print_bb=1; continue;
    }

    printed[i]=1; iatom++;
    if(jatom < 99999)jatom++;
    res=seq+atom1->res;
    m=3*i;

    Name3(aaname3, res->i_aa);
    if (strlen(atom1->name)==4){
      fprintf(fh,"%-6s%5d %-4s%1s%3s %c%4d%1s   %8.3f%8.3f%8.3f%6.2f\n",
	      "ATOM", jatom, atom1->name," ", aaname3,chain,
	      //res->pdbres," ",atoms_ref[m],atoms_ref[m+1],atoms_ref[m+2],
	      atom1->res+1," ",atoms_ref[m],atoms_ref[m+1],atoms_ref[m+2],
	      atom1->occupancy);
    }else{
      fprintf(fh,"%-6s%5d  %-3s%1s%3s %c%4d%s   %8.3f%8.3f%8.3f%6.2f\n",
	      "ATOM", jatom, atom1->name," ",aaname3,chain,
	      //res->pdbres," ",atoms_ref[m],atoms_ref[m+1],atoms_ref[m+2],
	      atom1->res+1," ",atoms_ref[m],atoms_ref[m+1],atoms_ref[m+2],
	      atom1->occupancy);
    }
  }
  fprintf(fh,"TER\n");
  fclose(fh); free(printed);
  return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x48(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, %r13
movl 0xa8(%rsp), %r14d
movl %r8d, 0xc(%rsp)
movslq %r8d, %rdi
shlq $0x2, %rdi
callq 0x21d0
movq %rax, %rbx
testl %r14d, %r14d
leaq 0x14dea(%rip), %rax     # 0x57240
leaq 0x1775a(%rip), %rsi     # 0x59bb7
cmoveq %rax, %rsi
movq %r13, %rdi
callq 0x2210
movq %rax, %r15
leal 0x1(%r14), %edx
leaq 0x1aaf5(%rip), %rsi     # 0x5cf6c
movq %rax, %rdi
xorl %eax, %eax
callq 0x2190
testl %r14d, %r14d
movq %r15, 0x28(%rsp)
je 0x424a3
jle 0x424ac
leaq 0x187a6(%rip), %rsi     # 0x5ac3a
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x2190
jmp 0x424c5
leaq 0x1aacd(%rip), %rdi     # 0x5cf77
jmp 0x424b3
leaq 0x1aacb(%rip), %rdi     # 0x5cf7e
movl $0x6, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
movl $0x0, 0x10(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r14d
testl %eax, %eax
jle 0x424ea
leaq (,%r14,4), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
cmpl $0x0, 0xc(%rsp)
jle 0x42784
movsbl 0xa0(%rsp), %eax
movq %rax, 0x38(%rsp)
xorl %esi, %esi
movb $0x1, 0x7(%rsp)
leaq 0x10(%rsp), %rdi
xorl %r8d, %r8d
xorl %r12d, %r12d
xorl %ecx, %ecx
movl $0x0, 0x1c(%rsp)
movq %r14, 0x20(%rsp)
movl %r12d, 0x34(%rsp)
movslq %r12d, %rax
movq %rax, 0x50(%rsp)
leal 0x1(%rax), %edx
movl 0xc(%rsp), %eax
cmpl %edx, %eax
cmovgl %eax, %edx
movl %edx, 0x30(%rsp)
movl $0x1, 0x8(%rsp)
movl %esi, %r15d
movl %ecx, 0x14(%rsp)
movl %r15d, %esi
movl 0x8(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0x18(%rsp)
testb $0x1, 0x7(%rsp)
je 0x42645
movq 0x50(%rsp), %r12
cmpl $0x0, (%rbx,%r12,4)
jne 0x42633
movq 0x60(%rsp), %rax
movslq (%rax,%r12,4), %rax
imulq $0x70, %rax, %rax
movq 0x58(%rsp), %rcx
leaq (%rcx,%rax), %r8
movl 0x1c(%rsp), %edx
cmpl %edx, 0x64(%rcx,%rax)
jg 0x4264c
movq %rbx, %rbp
movq %rsi, %rbx
movq %rdi, %r14
movq %r8, %r15
leaq 0x18(%r8), %r13
movl $0x2, %edx
movq %r13, %rdi
leaq 0x13965(%rip), %rsi     # 0x55f23
callq 0x2070
testl %eax, %eax
je 0x4261b
movl $0x2, %edx
movq %r13, %rdi
leaq 0x12b94(%rip), %rsi     # 0x5516a
callq 0x2070
testl %eax, %eax
je 0x4261b
movl $0x2, %edx
movq %r13, %rdi
leaq 0x13938(%rip), %rsi     # 0x55f26
callq 0x2070
testl %eax, %eax
je 0x4261b
movl $0x2, %edx
movq %r13, %rdi
leaq 0x13923(%rip), %rsi     # 0x55f29
callq 0x2070
testl %eax, %eax
je 0x4261b
cmpl $0x0, 0x8(%rsp)
movq %r14, %rdi
jne 0x42625
jmp 0x42673
cmpl $0x0, 0x8(%rsp)
movq %r14, %rdi
jne 0x42661
movq %rbx, %rsi
movq %rbp, %rbx
movq 0x20(%rsp), %r14
movq %r15, %r8
incq %r12
cmpq %r14, %r12
jl 0x42570
movl 0x30(%rsp), %eax
jmp 0x42649
movl 0x34(%rsp), %eax
movl %eax, %r12d
movb $0x1, %al
cmpl $0x0, 0x8(%rsp)
je 0x4267f
xorl %ecx, %ecx
testb %al, %al
jne 0x42556
jmp 0x4267f
xorl %eax, %eax
movq %rbx, %rsi
movq %rbp, %rbx
movq 0x20(%rsp), %r14
movq %r15, %r8
jmp 0x4264e
movl $0x0, 0x18(%rsp)
movb $0x1, %al
jmp 0x42663
cmpl $0x0, 0x8(%rsp)
setne %al
movl 0x18(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
je 0x42768
movslq %r12d, %rax
movl $0x1, (%rbx,%rax,4)
xorl %r15d, %r15d
cmpl $0x1869f, %esi          # imm = 0x1869F
setl %r15b
addl %esi, %r15d
movslq 0x64(%r8), %rcx
leal (%rax,%rax,2), %r12d
shlq $0x5, %rcx
movq 0x48(%rsp), %rax
movswl 0x14(%rax,%rcx), %esi
movq %r8, %rbp
callq 0x271f8
leaq 0x18(%rbp), %r13
movq %r13, %rdi
callq 0x20d0
movl 0x64(%rbp), %r10d
incl %r10d
movslq %r12d, %rcx
movq 0x40(%rsp), %rdx
movsd (%rdx,%rcx,8), %xmm0
movsd 0x8(%rdx,%rcx,8), %xmm1
movsd 0x10(%rdx,%rcx,8), %xmm2
movq %rbp, %r12
cvtss2sd 0x44(%rbp), %xmm3
cmpq $0x4, %rax
jne 0x42716
movq 0x28(%rsp), %rdi
leaq 0x1a871(%rip), %rsi     # 0x5cf85
jmp 0x42722
movq 0x28(%rsp), %rdi
leaq 0x1a89c(%rip), %rsi     # 0x5cfbe
leaq 0x1a890(%rip), %rdx     # 0x5cfb9
movl %r15d, %ecx
movq %r13, %r8
leaq 0x16c8c(%rip), %r9      # 0x593c2
movb $0x4, %al
pushq %r9
pushq %r10
pushq 0x48(%rsp)
leaq 0x28(%rsp), %r13
pushq %r13
callq 0x2190
addq $0x20, %rsp
movq %r13, %rdi
movl 0x14(%rsp), %ecx
incl %ecx
cmpl 0xc(%rsp), %ecx
movq %r12, %r8
jl 0x4254b
jmp 0x42784
incl 0x1c(%rsp)
movl 0xc(%rsp), %eax
cmpl %eax, %r12d
setl 0x7(%rsp)
movl 0x14(%rsp), %ecx
cmpl %eax, %ecx
jl 0x42523
leaq 0x1a7c3(%rip), %rdi     # 0x5cf4e
movl $0x4, %esi
movl $0x1, %edx
movq 0x28(%rsp), %r14
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2050
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq