// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, 0x18(%rsp)
xorl %ebp, %ebp
movl %ebp, 0xc(%rsp)
movl $0x1, 0x38(%rsp)
movl %ebp, 0x34(%rsp)
movl %ebp, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movl %ebp, (%rsi)
movb $0x0, 0x24(%rsp)
movl $0x7e7e7e7e, 0x20(%rsp) # imm = 0x7E7E7E7E
leaq 0x17286(%rip), %rsi     # 0x1aaa5
movq %rdx, 0x28(%rsp)
movq %rdx, %rdi
callq 0x21b0
testq %rax, %rax
je 0x3d6d
movq %rax, %r12
movl $0x1, 0x3c(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rax, %rdx
callq 0x2130
testq %rax, %rax
je 0x3b9b
leaq 0x4a(%rsp), %rbx
xorl %r15d, %r15d
leaq 0x7e(%rsp), %r14
movl $0x44414548, %r13d      # imm = 0x44414548
leaq 0x40(%rsp), %rbp
movl 0x40(%rsp), %eax
xorl %r13d, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x5245, %ecx           # imm = 0x5245
orl %eax, %ecx
je 0x3aba
movl 0x40(%rsp), %eax
movl $0x48545541, %ecx       # imm = 0x48545541
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x524f, %ecx           # imm = 0x524F
orl %eax, %ecx
je 0x3b02
movl 0x40(%rsp), %eax
movl $0x52554f53, %ecx       # imm = 0x52554F53
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x4543, %ecx           # imm = 0x4543
orl %eax, %ecx
je 0x3b1f
movl 0x40(%rsp), %eax
movl $0x504d4f43, %ecx       # imm = 0x504D4F43
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x444e, %ecx           # imm = 0x444E
orl %eax, %ecx
je 0x3b3c
cmpl $0x4c4e524a, 0x40(%rsp) # imm = 0x4C4E524A
jne 0x3906
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
callq 0xeda4
testl %eax, %eax
je 0x3d6b
movl 0x40(%rsp), %eax
movl $0x414d4552, %ecx       # imm = 0x414D4552
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x4b52, %ecx           # imm = 0x4B52
orl %eax, %ecx
jne 0x393f
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x34(%rsp), %rcx
callq 0xee28
testl %eax, %eax
je 0x3d6b
movl 0x40(%rsp), %eax
movl $0x44505845, %ecx       # imm = 0x44505845
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x4154, %ecx           # imm = 0x4154
orl %eax, %ecx
jne 0x396e
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
callq 0xff2c
testl %eax, %eax
je 0x3d6b
movl 0x40(%rsp), %eax
movl $0x45444f4d, %ecx       # imm = 0x45444F4D
xorl %ecx, %eax
movzbl 0x44(%rsp), %ecx
xorl $0x4c, %ecx
orl %eax, %ecx
jne 0x3997
leaq 0xc(%rsp), %rdi
callq 0xffc8
testl %eax, %eax
je 0x3d6b
movl 0x40(%rsp), %eax
movl $0x4d444e45, %ecx       # imm = 0x4D444E45
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x4c44, %ecx           # imm = 0x4C44
orl %eax, %ecx
je 0x3d81
movl 0x40(%rsp), %eax
movl $0x494c4548, %ecx       # imm = 0x494C4548
xorl %ecx, %eax
movzbl 0x44(%rsp), %ecx
xorl $0x58, %ecx
orl %eax, %ecx
jne 0x39eb
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0xf52c
testl %eax, %eax
je 0x3d6b
movl 0x40(%rsp), %eax
movl $0x45454853, %ecx       # imm = 0x45454853
xorl %ecx, %eax
movzbl 0x44(%rsp), %ecx
xorl $0x54, %ecx
orl %eax, %ecx
jne 0x3a21
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0xf71c
testl %eax, %eax
je 0x3d6b
cmpl $0x4e525554, 0x40(%rsp) # imm = 0x4E525554
jne 0x3a4a
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0xfc3c
testl %eax, %eax
je 0x3d6b
movl 0x40(%rsp), %eax
movl $0x4f425353, %ecx       # imm = 0x4F425353
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x444e, %ecx           # imm = 0x444E
orl %eax, %ecx
jne 0x3a83
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0xfdf0
testl %eax, %eax
je 0x3d6b
cmpl $0x4d4f5441, 0x40(%rsp) # imm = 0x4D4F5441
jne 0x3b80
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x3c(%rsp), %rcx
movq 0x28(%rsp), %r8
callq 0xf03c
testl %eax, %eax
jne 0x3b80
jmp 0x3d6b
movl $0x400, %edi            # imm = 0x400
callq 0x5880
movslq %r15d, %rcx
movq %rax, 0x450(%rsp,%rcx,8)
movl $0x20524448, (%rax)     # imm = 0x20524448
movw $0x20, 0x4(%rax)
incl %r15d
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2200
movl $0x4, %edx
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2050
movb $0x0, 0x24(%rsp)
jmp 0x3b80
movl $0x400, %edi            # imm = 0x400
callq 0x5880
movslq %r15d, %rcx
movq %rax, 0x450(%rsp,%rcx,8)
movl $0x20545541, (%rax)     # imm = 0x20545541
jmp 0x3b6c
movl $0x400, %edi            # imm = 0x400
callq 0x5880
movslq %r15d, %rcx
movq %rax, 0x450(%rsp,%rcx,8)
movl $0x20435253, (%rax)     # imm = 0x20435253
jmp 0x3b6c
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
callq 0xffdc
testl %eax, %eax
je 0x3d6b
movl $0x400, %edi            # imm = 0x400
callq 0x5880
movslq %r15d, %r15
movq %rax, 0x450(%rsp,%r15,8)
movl $0x20504d43, (%rax)     # imm = 0x20504D43
movw $0x20, 0x4(%rax)
incl %r15d
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2200
movq %rbp, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x2130
testq %rax, %rax
jne 0x3873
jmp 0x3b9e
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x20a0
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x3d37
xorl %ebp, %ebp
leaq 0x20(%rsp), %r12
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %r13
movl (%r13), %esi
testl %esi, %esi
je 0x3bea
movq %r13, %rdi
leaq 0x17260(%rip), %rdx     # 0x1ae38
leaq 0x8(%rsp), %rcx
callq 0x4ea0
testl %eax, %eax
jne 0x3bea
decl (%r13)
movq 0x48(%r13), %rdi
movq 0x28(%rsp), %rsi
callq 0x2070
leaq 0xb0(%r13), %rdi
movq %r12, %rsi
callq 0x2070
movl (%r13), %eax
testl %eax, %eax
je 0x3c15
incl %eax
movl %eax, (%r13)
movl 0x20(%r13), %eax
cmpl $-0x1, %eax
je 0x3c24
incl %eax
movl %eax, 0x20(%r13)
movss 0x30(%rsp), %xmm0
movss %xmm0, 0x50(%r13)
movl 0xc(%rsp), %eax
movl %eax, 0x54(%r13)
movl 0x38(%rsp), %eax
movl %eax, 0x5c(%r13)
movl 0x34(%rsp), %eax
movl %eax, 0x60(%r13)
movl %r15d, 0x3c(%r13)
movl $0x0, 0x8(%rsp)
testl %r15d, %r15d
jle 0x3cab
movl $0x400, %edi            # imm = 0x400
callq 0x5880
movq 0xa8(%r13), %rcx
movslq 0x8(%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
movq 0xa8(%r13), %rax
movq (%rax,%rdx,8), %rdi
movq 0x450(%rsp,%rdx,8), %rsi
callq 0x2070
movq 0xa8(%r13), %rax
movslq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, 0x47(%rax)
leal 0x1(%rcx), %eax
movl %eax, 0x8(%rsp)
cmpl %r15d, %eax
jl 0x3c59
movl $0x0, 0x8(%rsp)
cmpl $0x0, (%r13)
jle 0x3d23
xorl %eax, %eax
movq 0x68(%r13), %rcx
cltq
movq (%rcx,%rax,8), %r14
movl $0x3c, %edi
callq 0x5880
movq %rax, 0x770(%r14)
movl $0x20, %edi
callq 0x5880
movsd 0x15af7(%rip), %xmm0    # 0x197e0
movq %rax, 0x768(%r14)
movq 0x770(%r14), %rcx
movq $0x0, 0x30(%rcx)
movl %ebp, 0x38(%rcx)
movw $0x4343, 0x1c(%rax)     # imm = 0x4343
movb $0x43, 0x1e(%rax)
movl %ebp, 0x14(%rax)
movsd %xmm0, (%rax)
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl (%r13), %eax
jl 0x3cbc
incq %rbx
movq 0x10(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbx
jl 0x3bbd
movl $0x0, 0x8(%rsp)
movl $0x1, %ebp
testl %r15d, %r15d
jle 0x3d6d
xorl %eax, %eax
cltq
movq 0x450(%rsp,%rax,8), %rdi
callq 0x2040
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl %r15d, %eax
jl 0x3d4b
jmp 0x3d6d
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x2398, %rsp           # imm = 0x2398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x17f38
jmp 0x3b9e
nop