// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/seqres.c
// Function: Read_seqres
int Read_seqres(char **seqres, int *N_seqres, int NCHAIN,
		char *file_pdb, char *chain_to_read)
{
  /* Open file */
  int Compression;
  FILE *file_in=Open_compressed_file(file_pdb, &Compression);
  if(file_in==NULL)return(0);

  int nchain=0, read=0, L=0, n=0;
  char string[200], chain_old='-', *seq=NULL;
  while(fgets(string, sizeof(string), file_in)!=NULL){
    if(strncmp(string,"ATOM", 4)==0)break;
    if(strncmp(string,"SEQRES", 6)==0){
      char chain=string[11];
      if(chain!=chain_old){
	if(n){
	  printf("%d residues read %d expected for chain %d\n",
		 n, L, nchain); n=0;
	}
	chain_old=chain; int ic=0;
	while((chain_to_read[ic]!='\0')&&(chain!=chain_to_read[ic]))ic++;
	if(chain_to_read[ic]!=chain){read=0; continue;}
	read=1; sscanf(string+12, "%d", &L);
	printf("Reading chain %d %c %d residues\n", nchain, chain, L);
	seqres[nchain]=malloc(L*sizeof(char)); seq=seqres[nchain];
	N_seqres[nchain]=L;
	nchain++;
      }
      if(read==0)continue;
      char amm[3], aa3[4], *str=string+19;
      for(int k=0; k<13; k++){
	sscanf(str, "%s", aa3); str+=4;
	int exo=0; Get_amm(amm, &exo, aa3, 0, 0);
	*seq=amm[1]; seq++; n++; if(n==L)break;
      }
    }
  }
  if(n){
    printf("%d residues read %d expected for chain %d\n",
	   n, L, nchain); n=0;
  }
  if(nchain!=NCHAIN){
    printf("WARNING in SEQRES, %d chains expected (%s), %d found\n",
	   NCHAIN, chain_to_read, nchain);
    if(nchain==0){printf("Getting residues from atoms\n"); return(-1);}
    else{printf("Exiting\n"); exit(8);}
  }
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r8, 0x10(%rsp)
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x38(%rsp), %rsi
movq %rcx, %rdi
callq 0xe1e3
testq %rax, %rax
je 0x102ac
movq %rax, %r13
movl $0x0, 0x4(%rsp)
leaq 0x40(%rsp), %rdi
movl $0xc8, %esi
movq %rax, %rdx
callq 0x2170
testq %rax, %rax
je 0x1027e
cmpl $0x4d4f5441, 0x40(%rsp) # imm = 0x4D4F5441
je 0x1027e
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movl %ebx, 0x18(%rsp)
movb $0x2d, %r14b
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, 0x8(%rsp)
movq %r13, 0x30(%rsp)
movl %r14d, %ebp
movl 0x40(%rsp), %eax
movl $0x52514553, %ecx       # imm = 0x52514553
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x5345, %ecx           # imm = 0x5345
orl %eax, %ecx
jne 0x10122
movb 0x4b(%rsp), %r14b
cmpb %bpl, %r14b
jne 0x100b2
testl %ebx, %ebx
je 0x100f2
jmp 0x1018b
testl %r15d, %r15d
je 0x100d0
movl 0x4(%rsp), %edx
leaq 0x45f87(%rip), %rdi     # 0x56049
movl %r15d, %esi
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0x20f0
movsbl %r14b, %ebx
movq 0x10(%rsp), %rax
movb (%rax), %cl
testb %cl, %cl
je 0x100e7
incq %rax
cmpb %cl, %r14b
jne 0x100d9
xorl %r15d, %r15d
cmpb %cl, %r14b
je 0x1012a
movl %r14d, %ebp
leaq 0x40(%rsp), %rdi
movl $0xc8, %esi
movq %r13, %rdx
callq 0x2170
testq %rax, %rax
je 0x10227
xorl %ebx, %ebx
cmpl $0x4d4f5441, 0x40(%rsp) # imm = 0x4D4F5441
jne 0x10081
jmp 0x10227
movl %ebp, %r14d
jmp 0x10202
xorl %r15d, %r15d
leaq 0x4c(%rsp), %rdi
leaq 0x4d182(%rip), %rsi     # 0x5d2bb
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x2200
movl 0x4(%rsp), %ecx
leaq 0x45f24(%rip), %rdi     # 0x56074
movl 0x8(%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
movslq 0x4(%rsp), %rbx
movq %rbx, %rdi
callq 0x21e0
movq %rax, %r12
movslq %ebp, %rax
movq 0x20(%rsp), %rcx
movq %r12, (%rcx,%rax,8)
movq 0x28(%rsp), %rcx
movl %ebx, (%rcx,%rax,4)
incl %ebp
movl %ebp, 0x8(%rsp)
jmp 0x1018e
movl %ebp, %r14d
movl %r15d, %r15d
xorl %ebp, %ebp
leaq 0x53(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4708a(%rip), %rsi     # 0x5722c
leaq 0x3c(%rsp), %r13
movq %r13, %rdx
xorl %eax, %eax
callq 0x2200
movl $0x0, 0x1c(%rsp)
leaq 0xd(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xef00
movb 0xe(%rsp), %al
movb %al, (%r12,%rbp)
movl %ebp, %eax
leal (%r15,%rax), %ecx
incl %ecx
incq %rbp
cmpl 0x4(%rsp), %ecx
je 0x101f2
addq $0x4, %rbx
cmpl $0xc, %eax
jb 0x10198
addq %rbp, %r12
addl %ebp, %r15d
movl $0x1, %ebx
movq 0x30(%rsp), %r13
leaq 0x40(%rsp), %rdi
movl $0xc8, %esi
movq %r13, %rdx
callq 0x2170
testq %rax, %rax
je 0x10227
cmpl $0x4d4f5441, 0x40(%rsp) # imm = 0x4D4F5441
jne 0x1007e
testl %r15d, %r15d
movl 0x8(%rsp), %ebx
je 0x10247
movl 0x4(%rsp), %edx
leaq 0x45e0e(%rip), %rdi     # 0x56049
movl %r15d, %esi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
movl 0x18(%rsp), %esi
cmpl %esi, %ebx
je 0x102ac
leaq 0x45e3f(%rip), %rdi     # 0x56095
movq 0x10(%rsp), %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
je 0x10299
leaq 0x45e5c(%rip), %rdi     # 0x560cb
callq 0x2090
movl $0x8, %edi
callq 0x2280
testl %ebx, %ebx
je 0x102ac
leaq 0x45e0c(%rip), %rdi     # 0x56095
movl %ebx, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x20f0
leaq 0x45e33(%rip), %rdi     # 0x560d3
callq 0x2090
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x102ae
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq