// File: /workspace/github_c_makefile_star2_O3/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 $0xdc8, %rsp            # imm = 0xDC8
movq %rsi, %rbx
leaq 0x1806(%rdx), %r14
cmpb $0x0, 0x1806(%rdx)
jne 0x15896
movabsq $0x73642f617461642f, %rax # imm = 0x73642F617461642F
movq %rax, (%r14)
movl $0x2f7073, 0x8(%r14)    # imm = 0x2F7073
movq (%rdi), %rax
movq 0x48(%rax), %rdi
leaq 0x9c0(%rsp), %r15
movq %r15, %rsi
callq 0x4d40
leaq 0x5b0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x4db6
movq %r14, %rdi
movq %r12, %rsi
callq 0x2200
movq %r14, %rdi
callq 0x20b0
movl $0x7373642e, (%r14,%rax) # imm = 0x7373642E
movw $0x70, 0x4(%r14,%rax)
leaq 0x5208(%rip), %rsi      # 0x1aaa5
movq %r14, %rdi
callq 0x21b0
testq %rax, %rax
je 0x15b6d
movq %rax, %r15
movq %r14, 0x8(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%rsp)
leaq 0x10(%rsp), %rbp
xorl %r13d, %r13d
xorl %r14d, %r14d
testl %r14d, %r14d
sete %r12b
testl %r13d, %r13d
sete %r14b
movq %rbp, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x2130
testq %rax, %rax
je 0x15b30
testb $0x1, %r12b
je 0x15b30
movb 0x12(%rsp), %al
cmpb $0x23, %al
sete %cl
orb %r14b, %cl
testb $0x1, %cl
jne 0x1591b
movb $0x1, %r12b
xorl %r14d, %r14d
cmpb $0x21, 0x1d(%rsp)
je 0x158d8
jmp 0x15929
xorl %r13d, %r13d
cmpb $0x23, %al
sete %r13b
movb $0x1, %r12b
jmp 0x158d1
movq (%rsp), %rdi
testl %edi, %edi
jle 0x15951
movb 0x1b(%rsp), %al
movl %edi, %ecx
xorl %edx, %edx
movq (%rbx,%rdx,8), %rsi
cmpb %al, 0x401(%rsi)
je 0x15b04
incq %rdx
cmpq %rdx, %rcx
jne 0x15939
movslq %edi, %r12
cmpl $-0x1, %edi
je 0x1596e
movb 0x1b(%rsp), %al
movq (%rbx,%r12,8), %r13
cmpb 0x401(%r13), %al
je 0x15a0f
incl %edi
movq %rdi, (%rsp)
movl $0x428, %edi            # imm = 0x428
callq 0x5880
movq %rax, 0x8(%rbx,%r12,8)
movl $0x4e20, %edi           # imm = 0x4E20
movl $0x6, %esi
callq 0x5fdd
movq 0x8(%rbx,%r12,8), %rcx
movq %rax, 0x408(%rcx)
movl $0x4e20, %edi           # imm = 0x4E20
movl $0x6, %esi
callq 0x5fdd
movq 0x8(%rbx,%r12,8), %rcx
movq %rax, 0x418(%rcx)
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x5880
movq 0x8(%rbx,%r12,8), %rcx
movq %rax, 0x410(%rcx)
movl $0x13880, %edi          # imm = 0x13880
callq 0x5880
movq 0x8(%rbx,%r12,8), %rcx
movq %rax, 0x420(%rcx)
movq 0x8(%rbx,%r12,8), %rdi
movq 0x8(%rsp), %rsi
callq 0x2070
movb 0x1b(%rsp), %al
movq 0x8(%rbx,%r12,8), %r13
movb %al, 0x401(%r13)
movl $0x0, 0x404(%r13)
callq 0x2290
movq (%rax), %rcx
movsbq 0x1d(%rsp), %rax
testb $0x2, 0x1(%rcx,%rax,2)
je 0x15a2b
movb $0x43, 0x1d(%rsp)
movb $0x43, %al
movslq (%rsp), %r12
movq 0x408(%r13), %rcx
movslq 0x404(%r13), %rdx
movq (%rcx,%rdx,8), %r13
movsbl %al, %edi
callq 0x4d18
movq %r13, %rdi
movq %rax, %rsi
callq 0x2070
movl 0x20(%rsp), %eax
cmpb $0x20, %al
movq (%rbx,%r12,8), %rcx
movq 0x410(%rcx), %rdx
movslq 0x404(%rcx), %rcx
movl $0x43, %esi
cmovel %esi, %eax
movb %al, (%rdx,%rcx)
movl $0x1, %r13d
leaq 0x16(%rsp), %rdi
leaq 0x420(%rsp), %rsi
movl $0x1, %edx
callq 0x36c4
movq (%rbx,%r12,8), %rax
movq 0x418(%rax), %rcx
movslq 0x404(%rax), %rax
movq (%rcx,%rax,8), %rdi
movq 0x420(%rsp), %rsi
callq 0x2070
leaq 0x32(%rsp), %rdi
leaq 0x420(%rsp), %rsi
movl $0x1, %edx
callq 0x36c4
movq 0x420(%rsp), %rdi
callq 0x2080
cvtsd2ss %xmm0, %xmm0
movq (%rbx,%r12,8), %rax
movq 0x420(%rax), %rcx
movslq 0x404(%rax), %rdx
movss %xmm0, (%rcx,%rdx,4)
leal 0x1(%rdx), %ecx
movl %ecx, 0x404(%rax)
jmp 0x158ca
movq 0xb4e5(%rip), %rax      # 0x20ff0
movq (%rax), %rdi
leaq 0x5191(%rip), %rsi      # 0x1aca6
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x2160
movq (%rsp), %rdi
movl $0x1, %r14d
jmp 0x15951
movq %r15, %rdi
callq 0x20a0
movq (%rsp), %rax
leal 0x1(%rax), %ebp
testl %eax, %eax
js 0x15b6f
movl %ebp, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rax
movsbl 0x401(%rax), %edi
callq 0x50a2
movq (%rbx,%r15,8), %rcx
movb %al, 0x401(%rcx)
incq %r15
cmpq %r15, %r14
jne 0x15b49
jmp 0x15b6f
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xdc8, %rsp            # imm = 0xDC8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq