// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/dssp.c
// Function: ReadDSSP
int ReadDSSP(CHAIN **Chain, DSSP **Dssp, COMMAND *Cmd)
{

  FILE *fi;
  int ChainNumber = -1, Start = 0, i;
  BOOLEAN DuplicateChain = NO;
  BUFFER Buffer, Tmp1, Tmp2;
  char *Fields[MAX_FIELD];
  
  if( strlen(Cmd->DsspFile) == 0 ) {
    strcpy(Cmd->DsspFile,DSSPPATH);
    GetFileNameFromPath(Chain[0]->File,Tmp1);
    StripPathFromLastExtention(Tmp1,Tmp2);
    strcat(Cmd->DsspFile,Tmp2);
    strcat(Cmd->DsspFile,".dssp");
  }

  if( (fi = fopen(Cmd->DsspFile,"r")) ) {

    while( fgets(Buffer,BUFSZ,fi) != NULL && !DuplicateChain ) {
      if( Buffer[2] == '#' ) Start = 1;
      else
      if( Start == 1 ) {
	if( Buffer[13] == '!' ) continue;
	if( ChainNumber > 0 ) {
	  for( i=0; i<ChainNumber; i++ ) 
	    if( Dssp[i]->Id == Buffer[11] ) {
	      DuplicateChain = YES;
	      fprintf(stderr,"# Duplicate chain(s) in DSSP file %s\n",Cmd->DsspFile);
	    break;
	  }
	}
	if( ( ChainNumber == -1 || Buffer[11] != Dssp[ChainNumber]->Id ) ) {
	  ChainNumber++;
	  Dssp[ChainNumber]       = (DSSP *)ckalloc(sizeof(DSSP));
	  Dssp[ChainNumber]->ResType = CharMatrix(MAX_RES,RES_FIELD);
	  Dssp[ChainNumber]->PDB_ResNumb = CharMatrix(MAX_RES,RES_FIELD);
	  Dssp[ChainNumber]->SecondStr = (char *)ckalloc(MAX_RES*sizeof(char));
	  Dssp[ChainNumber]->Accessibility = (float *)ckalloc(MAX_RES*sizeof(float));
	  strcpy(Dssp[ChainNumber]->File,Cmd->DsspFile);
	  Dssp[ChainNumber]->Id   = Buffer[11];
	  Dssp[ChainNumber]->NRes = 0;
	}
	
	if( islower(Buffer[13]) ) Buffer[13] = 'C';
	strcpy(Dssp[ChainNumber]->ResType[ Dssp[ChainNumber]->NRes ],OneToThree(Buffer[13]));
	if( Buffer[16] == ' ' )
	  Dssp[ChainNumber]->SecondStr[ Dssp[ChainNumber]->NRes ] = 'C';
	else
	  Dssp[ChainNumber]->SecondStr[ Dssp[ChainNumber]->NRes ] = Buffer[16];
	SplitString(Buffer+6,Fields,1);
	strcpy(Dssp[ChainNumber]->PDB_ResNumb[Dssp[ChainNumber]->NRes],Fields[0]);
	SplitString(Buffer+34,Fields,1);
	Dssp[ChainNumber]->Accessibility[ Dssp[ChainNumber]->NRes ] = atof(Fields[0]);
	Dssp[ChainNumber]->NRes++;
      }
    }
    fclose(fi);
  }

  ChainNumber++;

  for( i=0; i<ChainNumber; i++ ) 
    Dssp[i]->Id = SpaceToDash(Dssp[i]->Id);

  return(ChainNumber);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xdd8, %rsp            # imm = 0xDD8
movq %rsi, %rbx
leaq 0x1806(%rdx), %r13
cmpb $0x0, 0x1806(%rdx)
jne 0x152f0
movabsq $0x73642f617461642f, %rax # imm = 0x73642F617461642F
movq %rax, (%r13)
movl $0x2f7073, 0x8(%r13)    # imm = 0x2F7073
movq (%rdi), %rax
movq 0x48(%rax), %rdi
leaq 0x9d0(%rsp), %r15
movq %r15, %rsi
callq 0x4624
leaq 0x5c0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x469a
movq %r13, %rdi
movq %r12, %rsi
callq 0x2210
movq %r13, %rdi
callq 0x20b0
movl $0x7373642e, (%r13,%rax) # imm = 0x7373642E
movw $0x70, 0x4(%r13,%rax)
leaq 0x475e(%rip), %rsi      # 0x19a55
movq %r13, %rdi
callq 0x21c0
xorl %r14d, %r14d
movl $0x0, %r12d
testq %rax, %rax
je 0x1558f
movq %rax, %r15
movq %r13, 0x10(%rsp)
pushq $-0x1
popq %r12
xorl %eax, %eax
xorl %ebp, %ebp
testl %ebp, %ebp
sete %r13b
testl %eax, %eax
sete %bpl
leaq 0x20(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x2130
testq %rax, %rax
je 0x15584
testb $0x1, %r13b
je 0x15584
movb 0x22(%rsp), %cl
cmpb $0x23, %cl
sete %al
orb %bpl, %al
testb $0x1, %al
jne 0x15371
movb $0x1, %r13b
xorl %ebp, %ebp
cmpb $0x21, 0x2d(%rsp)
je 0x1532d
jmp 0x1537e
xorl %eax, %eax
cmpb $0x23, %cl
sete %al
movb $0x1, %r13b
jmp 0x15327
testl %r12d, %r12d
jle 0x153c0
movb 0x2b(%rsp), %al
movl %r12d, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x153c0
movq (%rbx,%rdx,8), %rsi
incq %rdx
cmpb %al, 0x401(%rsi)
jne 0x1538c
movq 0xac49(%rip), %rax      # 0x1fff0
movq (%rax), %rdi
leaq 0x48a5(%rip), %rsi      # 0x19c56
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2160
pushq $0x1
popq %rbp
movslq %r12d, %r13
movl %r12d, 0xc(%rsp)
cmpl $-0x1, %r12d
je 0x153e4
movb 0x2b(%rsp), %al
movq (%rbx,%r13,8), %r12
cmpb 0x401(%r12), %al
je 0x15482
incl 0xc(%rsp)
movl $0x428, %edi            # imm = 0x428
callq 0x50f4
movq %rax, 0x8(%rbx,%r13,8)
movl $0x4e20, %edi           # imm = 0x4E20
pushq $0x6
popq %r12
movl %r12d, %esi
callq 0x5641
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x408(%rcx)
movl $0x4e20, %edi           # imm = 0x4E20
movl %r12d, %esi
callq 0x5641
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x418(%rcx)
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x50f4
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x410(%rcx)
movl $0x13880, %edi          # imm = 0x13880
callq 0x50f4
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x420(%rcx)
movq 0x8(%rbx,%r13,8), %rdi
movq 0x10(%rsp), %rsi
callq 0x2070
movb 0x2b(%rsp), %al
movq 0x8(%rbx,%r13,8), %r12
movb %al, 0x401(%r12)
andl $0x0, 0x404(%r12)
callq 0x22a0
movq (%rax), %rcx
movsbq 0x2d(%rsp), %rax
testb $0x2, 0x1(%rcx,%rax,2)
je 0x1549e
movb $0x43, 0x2d(%rsp)
movb $0x43, %al
movslq 0xc(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x408(%r12), %rcx
movslq 0x404(%r12), %rdx
movq (%rcx,%rdx,8), %r13
movsbl %al, %edi
callq 0x45fc
movq %r13, %rdi
movq %rax, %rsi
callq 0x2070
movl 0x30(%rsp), %eax
cmpb $0x20, %al
movq 0x18(%rsp), %r12
movq (%rbx,%r12,8), %rcx
movq 0x410(%rcx), %rdx
movslq 0x404(%rcx), %rcx
pushq $0x43
popq %rsi
cmovel %esi, %eax
movb %al, (%rdx,%rcx)
leaq 0x26(%rsp), %rdi
leaq 0x430(%rsp), %rsi
pushq $0x1
popq %r13
movl %r13d, %edx
callq 0x311c
movq (%rbx,%r12,8), %rax
movq 0x418(%rax), %rcx
movslq 0x404(%rax), %rax
movq (%rcx,%rax,8), %rdi
movq 0x430(%rsp), %rsi
callq 0x2070
leaq 0x42(%rsp), %rdi
leaq 0x430(%rsp), %rsi
movl %r13d, %edx
callq 0x311c
movq 0x430(%rsp), %rdi
callq 0x2080
cvtsd2ss %xmm0, %xmm0
movq (%rbx,%r12,8), %rax
movl 0xc(%rsp), %r12d
movq 0x420(%rax), %rcx
movslq 0x404(%rax), %rdx
movss %xmm0, (%rcx,%rdx,4)
leal 0x1(%rdx), %ecx
movl %ecx, 0x404(%rax)
movl %r13d, %eax
jmp 0x15321
movq %r15, %rdi
callq 0x20a0
incl %r12d
testl %r12d, %r12d
movl $0x0, %r15d
cmovgl %r12d, %r15d
cmpq %r14, %r15
je 0x155c0
movq (%rbx,%r14,8), %rax
movsbl 0x401(%rax), %edi
callq 0x4969
movq (%rbx,%r14,8), %rcx
movb %al, 0x401(%rcx)
incq %r14
jmp 0x1559c
movl %r12d, %eax
addq $0xdd8, %rsp            # imm = 0xDD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq