// File: /workspace/github_c_makefile_star2_O1/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 0x15a52
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 0x4e18
leaq 0x5b0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x4e8e
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 0x505c(%rip), %rsi      # 0x1aab5
movq %r14, %rdi
callq 0x21b0
testq %rax, %rax
je 0x15ced
movq %rax, %r15
movq %r14, 0x8(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %r12
xorl %r13d, %r13d
xorl %r14d, %r14d
testl %r13d, %r13d
sete %bpl
movq %r12, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x2130
testq %rax, %rax
je 0x15cdd
testl %r14d, %r14d
jne 0x15cdd
movb 0x12(%rsp), %al
cmpb $0x23, %al
sete %cl
orb %bpl, %cl
testb $0x1, %cl
jne 0x15ca7
xorl %ebp, %ebp
cmpb $0x21, 0x1d(%rsp)
je 0x15a8c
movl 0x4(%rsp), %ebp
testl %ebp, %ebp
jle 0x15af4
movb 0x1b(%rsp), %al
movl %ebp, %ecx
xorl %edx, %edx
movq (%rbx,%rdx,8), %rsi
cmpb %al, 0x401(%rsi)
je 0x15cb5
incq %rdx
cmpq %rdx, %rcx
jne 0x15adc
movslq %ebp, %r13
cmpl $-0x1, %ebp
je 0x15b10
movb 0x1b(%rsp), %al
movq (%rbx,%r13,8), %rcx
cmpb 0x401(%rcx), %al
je 0x15bab
incl %ebp
movl $0x428, %edi            # imm = 0x428
callq 0x595c
movq %rax, 0x8(%rbx,%r13,8)
movl $0x4e20, %edi           # imm = 0x4E20
movl $0x6, %esi
callq 0x60ab
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x408(%rcx)
movl $0x4e20, %edi           # imm = 0x4E20
movl $0x6, %esi
callq 0x60ab
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x418(%rcx)
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x595c
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x410(%rcx)
movl $0x13880, %edi          # imm = 0x13880
callq 0x595c
movq 0x8(%rbx,%r13,8), %rcx
movq %rax, 0x420(%rcx)
movq 0x8(%rbx,%r13,8), %rdi
movq 0x8(%rsp), %rsi
callq 0x2070
movb 0x1b(%rsp), %al
movq 0x8(%rbx,%r13,8), %rcx
movb %al, 0x401(%rcx)
movl $0x0, 0x404(%rcx)
callq 0x2290
movq (%rax), %rax
movsbq 0x1d(%rsp), %rcx
testb $0x2, 0x1(%rax,%rcx,2)
je 0x15bc5
movb $0x43, 0x1d(%rsp)
movl %ebp, 0x4(%rsp)
movslq %ebp, %rbp
movq (%rbx,%rbp,8), %rax
movq 0x408(%rax), %rcx
movslq 0x404(%rax), %rax
movq (%rcx,%rax,8), %r13
movsbl 0x1d(%rsp), %edi
callq 0x4df0
movq %r13, %rdi
movq %rax, %rsi
callq 0x2070
movl 0x20(%rsp), %eax
cmpb $0x20, %al
movq (%rbx,%rbp,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 0x36b8
movq (%rbx,%rbp,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 0x36b8
movq 0x420(%rsp), %rdi
callq 0x2080
cvtsd2ss %xmm0, %xmm0
movq (%rbx,%rbp,8), %rax
movq 0x420(%rax), %rcx
movslq 0x404(%rax), %rdx
movss %xmm0, (%rcx,%rdx,4)
leal 0x1(%rdx), %ecx
movl %ecx, 0x404(%rax)
jmp 0x15a85
xorl %r13d, %r13d
cmpb $0x23, %al
sete %r13b
jmp 0x15a85
movq 0xb334(%rip), %rax      # 0x20ff0
movq (%rax), %rdi
leaq 0x4ff0(%rip), %rsi      # 0x1acb6
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x2160
movl $0x1, %r14d
jmp 0x15af4
movq %r15, %rdi
callq 0x20a0
movl 0x4(%rsp), %ebp
incl %ebp
jmp 0x15cef
xorl %ebp, %ebp
testl %ebp, %ebp
jle 0x15d1b
movl %ebp, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rax
movsbl 0x401(%rax), %edi
callq 0x517a
movq (%rbx,%r15,8), %rcx
movb %al, 0x401(%rcx)
incq %r15
cmpq %r15, %r14
jne 0x15cf9
movl %ebp, %eax
addq $0xdc8, %rsp            # imm = 0xDC8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq