// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/rdpdb.c
// Function: ReadPDBFile
int ReadPDBFile(CHAIN **Chain, int *Cn, COMMAND *Cmd)
{

  int ChainCnt, InfoCnt, i;
  enum METHOD Method = XRay;
  BOOLEAN First_ATOM, Published=YES, DsspAssigned=NO;
  float Resolution = 0.0;
  FILE *pdb;
  BUFFER Buffer;
  char *Info[MAX_INFO], PdbIdent[5];
  RESIDUE *r;
  CHAIN *c;

  *Cn= 0;
  InfoCnt = 0;
  strcpy(PdbIdent,"~~~~");

  if( !(pdb = fopen(Cmd->InputFile,"r")) )
    return(FAILURE); 
     
  First_ATOM = YES;
  
  while( fgets(Buffer,BUFSZ,pdb) ) {
    
    if(!strncmp(Buffer,"HEADER",6)) {
      Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
      strcpy(Info[InfoCnt],"HDR  ");
      strcat(Info[InfoCnt++],Buffer+10);
      strncpy(PdbIdent,Buffer+62,4);
      PdbIdent[4] = '\0';
    }
    else
    if(!strncmp(Buffer,"AUTHOR",6)) {
      Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
      strcpy(Info[InfoCnt],"AUT  ");
      strcat(Info[InfoCnt++],Buffer+10);
    }
    else
    if(!strncmp(Buffer,"SOURCE",6)) {
      Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
      strcpy(Info[InfoCnt],"SRC  ");
      strcat(Info[InfoCnt++],Buffer+10);
    }
    else
    if(!strncmp(Buffer,"COMPND",6)) {
      if( !Process_COMPND(Buffer,&Method) ) 
	return(FAILURE);
      else {
	Info[InfoCnt] = (char *)ckalloc(BUFSZ*sizeof(char));
	strcpy(Info[InfoCnt],"CMP  ");
	strcat(Info[InfoCnt++],Buffer+10);
      }
    }
    else if(!strncmp(Buffer,"JRNL",4) && !Process_JRNL(Buffer,&Published)) 
	return(FAILURE);
    else if(!strncmp(Buffer,"REMARK",6) && !Process_REMARK(Buffer,&Method,&Resolution,
							   &DsspAssigned)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"EXPDTA",6) && !Process_EXPDTA(Buffer,&Method)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"MODEL",5) && !Process_MODEL(&Method)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"ENDMDL",6)) {
      Process_ENDMDL(Buffer,Chain,Cn);
      break;
    }
    else if(!strncmp(Buffer,"HELIX",5) && !Process_HELIX(Buffer,Chain,Cn,Cmd)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"SHEET",5) && !Process_SHEET(Buffer,Chain,Cn,Cmd)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"TURN",4) && !Process_TURN(Buffer,Chain,Cn,Cmd)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"SSBOND",6) && !Process_SSBOND(Buffer,Chain,Cn,Cmd)) 
      return(FAILURE);
    else if(!strncmp(Buffer,"ATOM",4) && !Process_ATOM(Buffer,Chain,Cn,&First_ATOM,Cmd)) 
      return(FAILURE);
  }
  fclose(pdb);

  for( ChainCnt=0; ChainCnt< *Cn; ChainCnt++ ) {
    c = Chain[ChainCnt];
    if( c->NRes != 0  && !FindAtom(c,c->NRes,"CA",&i) )
      c->NRes--;
    strcpy(c->File,Cmd->InputFile);

    strcpy(c->PdbIdent,PdbIdent);
    if( c->NRes != 0 )  c->NRes++;
    if( c->NSheet != -1 ) c->NSheet++;
    c->Resolution = Resolution;
    c->Method = Method;
    c->Published = Published;
    c->DsspAssigned = DsspAssigned;
    c->NInfo = InfoCnt;
    for(i=0; i<InfoCnt; i++) {
      c->Info[i] = (char *)ckalloc(BUFSZ*sizeof(char));
      strcpy(c->Info[i],Info[i]);
      c->Info[i][71] = '\0';
    }
    for( i=0; i<c->NRes; i++ ) {
      r = c->Rsd[i];
      r->Inv =  (INVOLVED *)ckalloc(sizeof(INVOLVED));
      r->Prop = (PROPERTY *)ckalloc(sizeof(PROPERTY));
      r->Inv->NBondDnr = 0;
      r->Inv->NBondAcc = 0;
      r->Inv->InterchainHBonds = NO;
      r->Prop->Asn     = 'C';
      r->Prop->PdbAsn  = 'C';
      r->Prop->DsspAsn = 'C';
      r->Prop->Solv    = 0.0;
      r->Prop->Phi     = 360.0;
      r->Prop->Psi     = 360.0;
    }
  }
  
  for(i=0; i<InfoCnt; i++)
    free(Info[i]);
  
  return(SUCCESS);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2398, %rsp           # imm = 0x2398
andl $0x0, 0x4(%rsp)
andl $0x0, 0x28(%rsp)
movq %rsi, %rbx
andl $0x0, 0x24(%rsp)
movl $0x1, 0x2c(%rsp)
andl $0x0, (%rsi)
movq %rdi, 0x8(%rsp)
movb $0x0, 0x14(%rsp)
movl $0x7e7e7e7e, 0x10(%rsp) # imm = 0x7E7E7E7E
leaq 0x167c6(%rip), %rsi     # 0x19a55
movq %rdx, 0x18(%rsp)
movq %rdx, %rdi
callq 0x21c0
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x35bd
leaq 0x3c(%rsp), %rax
movl $0x1, (%rax)
xorl %r15d, %r15d
leaq 0x40(%rsp), %rbp
pushq $0x6
popq %r13
pushq $0x5
popq %r12
movq %rbp, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x30(%rsp), %rdx
callq 0x2130
testq %rax, %rax
je 0x35e5
movq %rbp, %rdi
leaq 0x1550b(%rip), %rsi     # 0x187f5
movq %r13, %rdx
callq 0x21a0
movslq %r15d, %r14
testl %eax, %eax
je 0x3501
movq %rbp, %rdi
leaq 0x154fb(%rip), %rsi     # 0x18802
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
je 0x3545
movq %rbp, %rdi
leaq 0x154ee(%rip), %rsi     # 0x1880f
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
je 0x355f
movq %rbp, %rdi
leaq 0x154e1(%rip), %rsi     # 0x1881c
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
je 0x3579
cmpl $0x4c4e524a, 0x40(%rsp) # imm = 0x4C4E524A
jne 0x336a
movq %rbp, %rdi
leaq 0x2c(%rsp), %rsi
callq 0xed78
testl %eax, %eax
je 0x35bd
movq %rbp, %rdi
leaq 0x154b5(%rip), %rsi     # 0x18829
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
jne 0x339f
movq %rbp, %rdi
leaq 0x4(%rsp), %rsi
leaq 0x24(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0xedf4
testl %eax, %eax
je 0x35bd
movq %rbp, %rdi
leaq 0x15487(%rip), %rsi     # 0x18830
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
jne 0x33ca
movq %rbp, %rdi
leaq 0x4(%rsp), %rsi
callq 0xfe8c
testl %eax, %eax
je 0x35bd
movq %rbp, %rdi
leaq 0x15463(%rip), %rsi     # 0x18837
movq %r12, %rdx
callq 0x21a0
testl %eax, %eax
jne 0x33f2
leaq 0x4(%rsp), %rdi
callq 0xff28
testl %eax, %eax
je 0x35bd
movq %rbp, %rdi
leaq 0x15441(%rip), %rsi     # 0x1883d
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
je 0x35d3
movq %rbp, %rdi
leaq 0x1542e(%rip), %rsi     # 0x18844
movq %r12, %rdx
callq 0x21a0
testl %eax, %eax
jne 0x343f
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
callq 0xf4c0
testl %eax, %eax
je 0x35bd
movq %rbp, %rdi
leaq 0x15401(%rip), %rsi     # 0x1884a
movq %r12, %rdx
callq 0x21a0
testl %eax, %eax
jne 0x3472
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
callq 0xf6b0
testl %eax, %eax
je 0x35bd
cmpl $0x4e525554, 0x40(%rsp) # imm = 0x4E525554
jne 0x3499
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
callq 0xfba0
testl %eax, %eax
je 0x35bd
movq %rbp, %rdi
leaq 0x153ad(%rip), %rsi     # 0x18850
movq %r13, %rdx
callq 0x21a0
testl %eax, %eax
jne 0x34cc
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
callq 0xfd58
testl %eax, %eax
je 0x35bd
cmpl $0x4d4f5441, 0x40(%rsp) # imm = 0x4D4F5441
jne 0x32c5
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
leaq 0x3c(%rsp), %rcx
movq 0x18(%rsp), %r8
callq 0xf000
testl %eax, %eax
jne 0x32c5
jmp 0x35bd
movl $0x400, %edi            # imm = 0x400
callq 0x50f4
movq %rax, 0x450(%rsp,%r14,8)
movl $0x20524448, (%rax)     # imm = 0x20524448
movw $0x20, 0x4(%rax)
movq %rax, %rdi
leaq 0x4a(%rsp), %rsi
callq 0x2210
leaq 0x10(%rsp), %rdi
leaq 0x7e(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2050
movb $0x0, 0x14(%rsp)
jmp 0x35b5
movl $0x400, %edi            # imm = 0x400
callq 0x50f4
movq %rax, 0x450(%rsp,%r14,8)
movl $0x20545541, (%rax)     # imm = 0x20545541
jmp 0x35a2
movl $0x400, %edi            # imm = 0x400
callq 0x50f4
movq %rax, 0x450(%rsp,%r14,8)
movl $0x20435253, (%rax)     # imm = 0x20435253
jmp 0x35a2
movq %rbp, %rdi
leaq 0x4(%rsp), %rsi
callq 0xff38
testl %eax, %eax
je 0x35bd
movl $0x400, %edi            # imm = 0x400
callq 0x50f4
movq %rax, 0x450(%rsp,%r14,8)
movl $0x20504d43, (%rax)     # imm = 0x20504D43
movw $0x20, 0x4(%rax)
movq %rax, %rdi
leaq 0x4a(%rsp), %rsi
callq 0x2210
incl %r15d
jmp 0x32c5
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x2398, %rsp           # imm = 0x2398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x17724
movq 0x30(%rsp), %rdi
callq 0x20a0
xorl %ecx, %ecx
pushq $0x3c
popq %r13
pushq $0x20
popq %rbp
movslq (%rbx), %rax
cmpq %rax, %rcx
jge 0x376f
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rsp)
movq (%rax,%rcx,8), %r12
movl (%r12), %esi
testl %esi, %esi
je 0x3634
movq %r12, %rdi
leaq 0x167c4(%rip), %rdx     # 0x19de8
movq %rsp, %rcx
callq 0x4777
testl %eax, %eax
jne 0x3634
decl (%r12)
movq 0x48(%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x2070
leaq 0xb0(%r12), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2070
movl (%r12), %eax
testl %eax, %eax
je 0x3663
incl %eax
movl %eax, (%r12)
movl 0x20(%r12), %eax
cmpl $-0x1, %eax
je 0x3674
incl %eax
movl %eax, 0x20(%r12)
movss 0x24(%rsp), %xmm0
movss %xmm0, 0x50(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0x54(%r12)
movl 0x2c(%rsp), %eax
movl %eax, 0x5c(%r12)
movl 0x28(%rsp), %eax
movl %eax, 0x60(%r12)
movl %r15d, 0x3c(%r12)
xorl %eax, %eax
movl %eax, (%rsp)
cmpl %r15d, %eax
jge 0x36f7
movl $0x400, %edi            # imm = 0x400
callq 0x50f4
movq 0xa8(%r12), %rcx
movslq (%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
movq 0xa8(%r12), %rax
movq (%rax,%rdx,8), %rdi
movq 0x450(%rsp,%rdx,8), %rsi
callq 0x2070
movq 0xa8(%r12), %rax
movslq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, 0x47(%rax)
leal 0x1(%rcx), %eax
jmp 0x36a3
movq %rbx, %r14
xorl %eax, %eax
movl %eax, (%rsp)
cmpl (%r12), %eax
jge 0x375f
movq 0x68(%r12), %rcx
cltq
movq (%rcx,%rax,8), %rbx
movq %r13, %rdi
callq 0x50f4
movq %rax, 0x770(%rbx)
movq %rbp, %rdi
callq 0x50f4
movq %rax, 0x768(%rbx)
movq 0x770(%rbx), %rcx
andq $0x0, 0x30(%rcx)
andl $0x0, 0x38(%rcx)
movw $0x4343, 0x1c(%rax)     # imm = 0x4343
movb $0x43, 0x1e(%rax)
andl $0x0, 0x14(%rax)
movsd 0x1508c(%rip), %xmm0    # 0x187e0
movsd %xmm0, (%rax)
movl (%rsp), %eax
incl %eax
jmp 0x36fc
movq 0x30(%rsp), %rcx
incq %rcx
movq %r14, %rbx
jmp 0x35f8
xorl %eax, %eax
pushq $0x1
popq %rbx
movl %eax, (%rsp)
cmpl %r15d, %eax
jge 0x35bf
cltq
movq 0x450(%rsp,%rax,8), %rdi
callq 0x2040
movl (%rsp), %eax
incl %eax
jmp 0x3774
nop