// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0xa8, %rsp
movl 0x18(%rbp), %eax
movb 0x10(%rbp), %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x1, -0x50(%rbp)
movslq -0x2c(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x60(%rbp)
movq $0x0, -0x80(%rbp)
cmpl $0x0, 0x18(%rbp)
jne 0x5e932
movq -0x10(%rbp), %rdi
leaq 0x1da4b(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0x78(%rbp)
jmp 0x5e946
movq -0x10(%rbp), %rdi
leaq 0x2030d(%rip), %rsi     # 0x7ec4a
callq 0x11b0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movl 0x18(%rbp), %edx
addl $0x1, %edx
leaq 0x23951(%rip), %rsi     # 0x822a8
movb $0x0, %al
callq 0x1150
cmpl $0x0, 0x18(%rbp)
jne 0x5e978
movq -0x78(%rbp), %rdi
leaq 0x23944(%rip), %rsi     # 0x822b3
movb $0x0, %al
callq 0x1150
jmp 0x5e9b1
cmpl $0x0, 0x18(%rbp)
jle 0x5e995
movq -0x78(%rbp), %rdi
movl 0x18(%rbp), %edx
leaq 0x215c0(%rip), %rsi     # 0x7ff4c
movb $0x0, %al
callq 0x1150
jmp 0x5e9af
cmpl $0x0, 0x18(%rbp)
jge 0x5e9ad
movq -0x78(%rbp), %rdi
leaq 0x23914(%rip), %rsi     # 0x822ba
movb $0x0, %al
callq 0x1150
jmp 0x5e9af
jmp 0x5e9b1
movl $0x0, -0x3c(%rbp)
cmpl $0x4, -0x3c(%rbp)
jge 0x5e9d2
movslq -0x3c(%rbp), %rax
movb $0x0, -0x6c(%rbp,%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5e9b8
movl $0x0, -0x84(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x1, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5ea20
movq -0x60(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5e9fe
jmp 0x5ea22
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5ed27
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5eb37
movq -0x60(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x5ea61
jmp 0x5eb29
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x48(%rbp), %eax
jle 0x5ea8d
jmp 0x5eb37
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1c591(%rip), %rsi     # 0x7b02d
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
je 0x5eb05
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1784e(%rip), %rsi     # 0x76308
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
je 0x5eb05
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1c558(%rip), %rsi     # 0x7b030
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
je 0x5eb05
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1c53d(%rip), %rsi     # 0x7b033
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x5eb16
cmpl $0x0, -0x50(%rbp)
je 0x5eb14
movl $0x1, -0x54(%rbp)
jmp 0x5eb37
jmp 0x5eb27
cmpl $0x0, -0x50(%rbp)
jne 0x5eb25
movl $0x1, -0x58(%rbp)
jmp 0x5eb37
jmp 0x5eb27
jmp 0x5eb29
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5ea42
cmpl $0x0, -0x50(%rbp)
je 0x5eb4f
cmpl $0x0, -0x54(%rbp)
jne 0x5eb4f
movl $0x0, -0x50(%rbp)
jmp 0x5ea22
cmpl $0x0, -0x50(%rbp)
jne 0x5eb76
cmpl $0x0, -0x58(%rbp)
jne 0x5eb76
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x5ea22
movq -0x60(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x1869f, -0x84(%rbp)   # imm = 0x1869F
jge 0x5eba9
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movq -0x38(%rbp), %rax
movq -0x80(%rbp), %rcx
movslq 0x64(%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
imull $0x3, -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
leaq -0x6c(%rbp), %rdi
movq -0x68(%rbp), %rax
movswl 0x14(%rax), %esi
callq 0x37330
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x10b0
cmpq $0x4, %rax
jne 0x5ec8b
movq -0x78(%rbp), %rdi
movl -0x84(%rbp), %ecx
movq -0x80(%rbp), %r8
addq $0x18, %r8
leaq -0x6c(%rbp), %rbx
movsbl 0x10(%rbp), %r11d
movq -0x80(%rbp), %rax
movl 0x64(%rax), %r10d
addl $0x1, %r10d
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm0
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rax,%rdx,8), %xmm1
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movsd (%rax,%rdx,8), %xmm2
movq -0x80(%rbp), %rax
movss 0x44(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x23666(%rip), %rsi     # 0x822c1
leaq 0x1c0e8(%rip), %rdx     # 0x7ad4a
leaq 0x1f918(%rip), %rax     # 0x7e581
movq %rax, %r9
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x4, %al
callq 0x1150
jmp 0x5ed22
movq -0x78(%rbp), %rdi
movl -0x84(%rbp), %ecx
movq -0x80(%rbp), %r8
addq $0x18, %r8
leaq -0x6c(%rbp), %rbx
movsbl 0x10(%rbp), %r11d
movq -0x80(%rbp), %rax
movl 0x64(%rax), %r10d
addl $0x1, %r10d
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm0
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rax,%rdx,8), %xmm1
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movsd (%rax,%rdx,8), %xmm2
movq -0x80(%rbp), %rax
movss 0x44(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x235fe(%rip), %rsi     # 0x822f5
leaq 0x1c04c(%rip), %rdx     # 0x7ad4a
leaq 0x1f87c(%rip), %rax     # 0x7e581
movq %rax, %r9
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x4, %al
callq 0x1150
jmp 0x5ea22
movq -0x78(%rbp), %rdi
leaq 0x23558(%rip), %rsi     # 0x8228a
movb $0x0, %al
callq 0x1150
movq -0x78(%rbp), %rdi
callq 0x10a0
movq -0x60(%rbp), %rdi
callq 0x1040
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)