// File: /workspace/github_c_makefile_star2_O0/josch[P]stride/molscr.c
// Function: MolScript
int MolScript(CHAIN **Chain, int NChain, COMMAND *Cmd)
{

  int HelixBound[MAX_ASSIGN][2], SheetBound[MAX_ASSIGN][2], CoilBound[MAX_ASSIGN][2];
  int NHelix, NSheet, NCoil, i, Cn;
  char *Asn;
  FILE *fi;

  if( !(fi = fopen(Cmd->MolScriptFile,"w")) )
    return(escape(FAILURE,"\nCan not open molscript file %s\n\n",Cmd->MolScriptFile));

  fprintf(fi,"plot\n");
  fprintf(fi,"read mol \"%s\";\n",Chain[0]->File);
  fprintf(fi,"transform atom * by centre position in amino-acids\n");
  fprintf(fi,"by rotation z  0.0	\n");
  fprintf(fi,"by rotation y -260.0	\n");
  fprintf(fi,"by rotation x -40.0;\n");
      
  for( Cn=0; Cn<NChain; Cn++ ) {

    if( !Chain[Cn]->Valid )
       continue;

    Asn = (char *)ckalloc(Chain[Cn]->NRes*sizeof(char));

    ExtractAsn(Chain,Cn,Asn);
    for( i=0; i<Chain[Cn]->NRes; i++ )
      if( Asn[i] != 'H' && Asn[i] != 'E' )
	Asn[i] = 'C';

    NHelix = Boundaries(Asn,Chain[Cn]->NRes,'H',HelixBound);
    NSheet = Boundaries(Asn,Chain[Cn]->NRes,'E',SheetBound);
    NCoil  = Boundaries(Asn,Chain[Cn]->NRes,'C',CoilBound);

    free(Asn);
    
    for( i=0; i<NSheet; i++ )  
      if( SheetBound[i][1] != Chain[Cn]->NRes-1 ) 
	SheetBound[i][1]++;
    for( i=0; i<NHelix;  i++ ) 
      if( HelixBound[i][1] != Chain[Cn]->NRes-1 ) 
	HelixBound[i][1]++;
    for( i=0; i<NCoil;   i++ ) 
      if( CoilBound[i][1]  != Chain[Cn]->NRes-1 )
	CoilBound[i][1]++;
    
    for( i=0; i<NHelix; i++ )
      fprintf(fi,"helix from %c%s to %c%s;\n",
	      Chain[Cn]->Id,Chain[Cn]->Rsd[HelixBound[i][0]]->PDB_ResNumb,
	      Chain[Cn]->Id,Chain[Cn]->Rsd[HelixBound[i][1]]->PDB_ResNumb);
  
    for( i=0; i<NSheet; i++ )
      fprintf(fi,"strand from %c%s to %c%s;\n",
	      Chain[Cn]->Id,Chain[Cn]->Rsd[SheetBound[i][0]]->PDB_ResNumb,
	      Chain[Cn]->Id,Chain[Cn]->Rsd[SheetBound[i][1]]->PDB_ResNumb);
    
    for( i=0; i<NCoil; i++ )
      fprintf(fi,"coil from %c%s to %c%s;\n",
	      Chain[Cn]->Id,Chain[Cn]->Rsd[CoilBound[i][0]]->PDB_ResNumb,
	      Chain[Cn]->Id,Chain[Cn]->Rsd[CoilBound[i][1]]->PDB_ResNumb);
  }

  fprintf(fi,"end_plot\n");
  fclose(fi);
  
  return(SUCCESS);
}

// Assembly:
subq $0x2f38, %rsp           # imm = 0x2F38
movq %rdi, 0x2f28(%rsp)
movl %esi, 0x2f24(%rsp)
movq %rdx, 0x2f18(%rsp)
movq 0x2f18(%rsp), %rdi
addq $0x1405, %rdi           # imm = 0x1405
leaq 0x1f914(%rip), %rsi     # 0x2bce8
callq 0x2190
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
jne 0xc40f
movq 0x2f18(%rsp), %rdx
addq $0x1405, %rdx           # imm = 0x1405
xorl %edi, %edi
leaq 0x1f8ee(%rip), %rsi     # 0x2bcea
movb $0x0, %al
callq 0x19470
movl %eax, 0x2f34(%rsp)
jmp 0xc95c
movq 0x8(%rsp), %rdi
leaq 0x1f9c9(%rip), %rsi     # 0x2bde4
movb $0x0, %al
callq 0x2140
movq 0x8(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movq (%rax), %rax
movq 0x48(%rax), %rdx
leaq 0x1f8cf(%rip), %rsi     # 0x2bd0c
movb $0x0, %al
callq 0x2140
movq 0x8(%rsp), %rdi
leaq 0x1f8cc(%rip), %rsi     # 0x2bd1c
movb $0x0, %al
callq 0x2140
movq 0x8(%rsp), %rdi
leaq 0x1f8ed(%rip), %rsi     # 0x2bd50
movb $0x0, %al
callq 0x2140
movq 0x8(%rsp), %rdi
leaq 0x1f8ef(%rip), %rsi     # 0x2bd65
movb $0x0, %al
callq 0x2140
movq 0x8(%rsp), %rdi
leaq 0x1f8f3(%rip), %rsi     # 0x2bd7c
movb $0x0, %al
callq 0x2140
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x2f24(%rsp), %eax
jge 0xc934
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, 0x58(%rax)
jne 0xc4c5
jmp 0xc924
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq (%rax), %rdi
shlq $0x0, %rdi
callq 0x7360
movq %rax, 0x10(%rsp)
movq 0x2f28(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq 0x10(%rsp), %rdx
callq 0x6610
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movq 0x2f28(%rsp), %rcx
movslq 0x1c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl (%rcx), %eax
jge 0xc561
movq 0x10(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x48, %eax
je 0xc552
movq 0x10(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x45, %eax
je 0xc552
movq 0x10(%rsp), %rax
movslq 0x20(%rsp), %rcx
movb $0x43, (%rax,%rcx)
jmp 0xc554
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc505
movq 0x10(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
leaq 0x1f70(%rsp), %rcx
movl $0x48, %edx
callq 0x61f0
movl %eax, 0x2c(%rsp)
movq 0x10(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
leaq 0xfd0(%rsp), %rcx
movl $0x45, %edx
callq 0x61f0
movl %eax, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
leaq 0x30(%rsp), %rcx
movl $0x43, %edx
callq 0x61f0
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
callq 0x2030
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x28(%rsp), %eax
jge 0xc64f
movslq 0x20(%rsp), %rax
movl 0xfd4(%rsp,%rax,8), %eax
movq 0x2f28(%rsp), %rcx
movslq 0x1c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xc640
movslq 0x20(%rsp), %rax
movl 0xfd4(%rsp,%rax,8), %ecx
addl $0x1, %ecx
movl %ecx, 0xfd4(%rsp,%rax,8)
jmp 0xc642
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc5fa
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0xc6ac
movslq 0x20(%rsp), %rax
movl 0x1f74(%rsp,%rax,8), %eax
movq 0x2f28(%rsp), %rcx
movslq 0x1c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xc69d
movslq 0x20(%rsp), %rax
movl 0x1f74(%rsp,%rax,8), %ecx
addl $0x1, %ecx
movl %ecx, 0x1f74(%rsp,%rax,8)
jmp 0xc69f
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc657
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0xc700
movslq 0x20(%rsp), %rax
movl 0x34(%rsp,%rax,8), %eax
movq 0x2f28(%rsp), %rcx
movslq 0x1c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xc6f1
movslq 0x20(%rsp), %rax
movl 0x34(%rsp,%rax,8), %ecx
addl $0x1, %ecx
movl %ecx, 0x34(%rsp,%rax,8)
jmp 0xc6f3
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc6b4
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0xc7b8
movq 0x8(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x40(%rax), %edx
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x20(%rsp), %rcx
movslq 0x1f70(%rsp,%rcx,8), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movsbl 0x40(%rax), %r8d
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movq 0x68(%rax), %rax
movslq 0x20(%rsp), %rsi
movslq 0x1f74(%rsp,%rsi,8), %rsi
movq (%rax,%rsi,8), %r9
addq $0x4, %r9
leaq 0x1f5f1(%rip), %rsi     # 0x2bd92
movb $0x0, %al
callq 0x2140
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc708
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x28(%rsp), %eax
jge 0xc870
movq 0x8(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x40(%rax), %edx
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x20(%rsp), %rcx
movslq 0xfd0(%rsp,%rcx,8), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movsbl 0x40(%rax), %r8d
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movq 0x68(%rax), %rax
movslq 0x20(%rsp), %rsi
movslq 0xfd4(%rsp,%rsi,8), %rsi
movq (%rax,%rsi,8), %r9
addq $0x4, %r9
leaq 0x1f553(%rip), %rsi     # 0x2bdac
movb $0x0, %al
callq 0x2140
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc7c0
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0xc922
movq 0x8(%rsp), %rdi
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x40(%rax), %edx
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x20(%rsp), %rcx
movslq 0x30(%rsp,%rcx,8), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movsbl 0x40(%rax), %r8d
movq 0x2f28(%rsp), %rax
movslq 0x1c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movq 0x68(%rax), %rax
movslq 0x20(%rsp), %rsi
movslq 0x34(%rsp,%rsi,8), %rsi
movq (%rax,%rsi,8), %r9
addq $0x4, %r9
leaq 0x1f4bc(%rip), %rsi     # 0x2bdc7
movb $0x0, %al
callq 0x2140
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc878
jmp 0xc924
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xc498
movq 0x8(%rsp), %rdi
leaq 0x1f4a0(%rip), %rsi     # 0x2bde0
movb $0x0, %al
callq 0x2140
movq 0x8(%rsp), %rdi
callq 0x20a0
movl $0x1, 0x2f34(%rsp)
movl 0x2f34(%rsp), %eax
addq $0x2f38, %rsp           # imm = 0x2F38
retq
nopl (%rax,%rax)