// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/read.c
// Function: Write_residue
static short Write_residue(char *res_type_old, atom *first_atom, short i_atom,
			   struct residue *ptr_tmp, int n_exo, int res_num,
			   char icode, char xchain, int hetatm)
{
  /* Returns type =1 (a.a.), -1 (a.a. as ligand), 2/-2: DNA 3/-3: RNA */
  char amm[5]; //modyves: this was the cause of the overwriting problems I had (that were not visible for you, though something else might have gotten overwritten)
  int exo=0, type;
  type = Get_amm(amm, &exo, res_type_old, hetatm, n_exo);

  	
  /* Check backbone */
  if((type==0) && (i_atom >=3))
  	{// If backbone atoms exist: Modified residue
     int i_N=0, i_CA=0, i_C=0;
     atom *atom_ptr=first_atom;
    
     for(int i=0; i<i_atom; i++)
     	{if(strncmp(atom_ptr->name, "N ", 2)==0){i_N=1;}
      	 else if(strncmp(atom_ptr->name, "CA", 2)==0){i_CA=1;}
      	 else if(strncmp(atom_ptr->name, "C ", 2)==0){i_C=1;}
      	 if(i_N && i_CA && i_C){type=1; exo=1; break;}
      	 atom_ptr++;
    	}
  	}

  ptr_tmp->type=type;
  ptr_tmp->chain=xchain;

  strcpy(ptr_tmp->pdbres,"     "); //modyves: this was sometimes uninitialized
  sprintf(ptr_tmp->pdbres, "%d", res_num);
  char tmp[40];
  if(icode!=' '){sprintf(tmp, "%c", icode); strcat(ptr_tmp->pdbres, tmp);}
  ptr_tmp->amm=amm[1]; ptr_tmp->exo=exo;
  if((type==1)||(type==-1)){
    ptr_tmp->i_aa=Code_AA(amm[1]);
    if(ptr_tmp->i_aa<0){
      printf("Unknown residue %s %d%c\n", res_type_old, res_num, icode);
      ptr_tmp->i_aa=0;
    }
  }
  ptr_tmp->atom_ptr=first_atom; 
  ptr_tmp->n_atom=i_atom;

  if(type==0)
    printf("Group %s %d%c  %s (%d atoms) not a residue\n",
	   res_type_old, res_num, icode, amm, i_atom);

  return(type);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movw %dx, %ax
movl 0x20(%rbp), %edx
movb 0x18(%rbp), %dl
movb 0x10(%rbp), %dl
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
leaq -0x2d(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl 0x20(%rbp), %ecx
movl -0x24(%rbp), %r8d
leaq -0x34(%rbp), %rsi
callq 0x12810
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x14120
movswl -0x12(%rbp), %eax
cmpl $0x3, %eax
jl 0x14120
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movswl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1411e
movq -0x50(%rbp), %rdi
addq $0x18, %rdi
leaq 0x66fb3(%rip), %rsi     # 0x7b02d
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x14092
movl $0x1, -0x3c(%rbp)
jmp 0x140e2
movq -0x50(%rbp), %rdi
addq $0x18, %rdi
leaq 0x62267(%rip), %rsi     # 0x76308
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x140b9
movl $0x1, -0x40(%rbp)
jmp 0x140e0
movq -0x50(%rbp), %rdi
addq $0x18, %rdi
leaq 0x66f68(%rip), %rsi     # 0x7b030
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x140de
movl $0x1, -0x44(%rbp)
jmp 0x140e0
jmp 0x140e2
cmpl $0x0, -0x3c(%rbp)
je 0x14104
cmpl $0x0, -0x40(%rbp)
je 0x14104
cmpl $0x0, -0x44(%rbp)
je 0x14104
movl $0x1, -0x38(%rbp)
movl $0x1, -0x34(%rbp)
jmp 0x1411e
movq -0x50(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x50(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1405c
jmp 0x14120
movl -0x38(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x18(%rax)
movb 0x18(%rbp), %cl
movq -0x20(%rbp), %rax
movb %cl, 0xc(%rax)
movq -0x20(%rbp), %rdi
addq $0xd, %rdi
leaq 0x6a436(%rip), %rsi     # 0x7e57d
callq 0x1060
movq -0x20(%rbp), %rdi
addq $0xd, %rdi
movl -0x28(%rbp), %edx
leaq 0x6e550(%rip), %rsi     # 0x826ae
movb $0x0, %al
callq 0x1200
movsbl 0x10(%rbp), %eax
cmpl $0x20, %eax
je 0x14195
leaq -0x80(%rbp), %rdi
movsbl 0x10(%rbp), %edx
leaq 0x6eab9(%rip), %rsi     # 0x82c36
movb $0x0, %al
callq 0x1200
movq -0x20(%rbp), %rdi
addq $0xd, %rdi
leaq -0x80(%rbp), %rsi
callq 0x11e0
movb -0x2c(%rbp), %cl
movq -0x20(%rbp), %rax
movb %cl, 0x13(%rax)
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x16(%rax)
cmpl $0x1, -0x38(%rbp)
je 0x141b9
cmpl $-0x1, -0x38(%rbp)
jne 0x141ff
movsbl -0x2c(%rbp), %edi
callq 0x2bec0
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x20(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $0x0, %eax
jge 0x141fd
movq -0x8(%rbp), %rsi
movl -0x28(%rbp), %edx
movsbl 0x10(%rbp), %ecx
leaq 0x66eb0(%rip), %rdi     # 0x7b09c
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rax
movw $0x0, 0x14(%rax)
jmp 0x141ff
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movswl -0x12(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpl $0x0, -0x38(%rbp)
jne 0x1423d
movq -0x8(%rbp), %rsi
movl -0x28(%rbp), %edx
movsbl 0x10(%rbp), %ecx
leaq -0x2d(%rbp), %r8
movswl -0x12(%rbp), %r9d
leaq 0x66e7f(%rip), %rdi     # 0x7b0b5
movb $0x0, %al
callq 0x10d0
movl -0x38(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)