// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f18, %rsp           # imm = 0x2F18
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r14
addq $0x1405, %r15           # imm = 0x1405
leaq 0x1181d(%rip), %rsi     # 0x19da8
movq %r15, %rdi
callq 0x21b0
testq %rax, %rax
je 0x88d9
movq %rax, %r12
leaq 0x118fe(%rip), %rdi     # 0x19ea4
movl $0x5, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2240
movq (%r14), %rax
movq 0x48(%rax), %rdx
leaq 0x11806(%rip), %rsi     # 0x19dcc
movq %r12, %rdi
xorl %eax, %eax
callq 0x2160
leaq 0x11805(%rip), %rdi     # 0x19ddc
movl $0x33, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x2240
leaq 0x11820(%rip), %rdi     # 0x19e10
movl $0x14, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x2240
leaq 0x1181c(%rip), %rdi     # 0x19e25
movl $0x16, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x2240
leaq 0x1181a(%rip), %rdi     # 0x19e3c
movl $0x15, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x2240
testl %ebp, %ebp
jle 0x88a1
movl %ebp, %eax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq (%r14,%r13,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x8893
movslq (%rax), %rdi
callq 0x595c
movq %rax, %rbp
movq %r14, %rdi
movl %r13d, %esi
movq %rax, %rdx
callq 0x51f0
movq (%r14,%r13,8), %rax
movl (%rax), %esi
testl %esi, %esi
jle 0x869c
xorl %eax, %eax
movzbl (%rbp,%rax), %ecx
cmpl $0x45, %ecx
je 0x868d
cmpl $0x48, %ecx
je 0x868d
movb $0x43, (%rbp,%rax)
incq %rax
movq (%r14,%r13,8), %rcx
movslq (%rcx), %rsi
cmpq %rsi, %rax
jl 0x8679
movq %rbp, %rdi
movl $0x48, %edx
leaq 0x1f70(%rsp), %rcx
callq 0x4fe2
movl %eax, 0xc(%rsp)
movq (%r14,%r13,8), %rax
movl (%rax), %esi
movq %rbp, %rdi
movl $0x45, %edx
leaq 0xfd0(%rsp), %rcx
callq 0x4fe2
movl %eax, %r15d
movq (%r14,%r13,8), %rax
movl (%rax), %esi
movq %rbp, %rdi
movl $0x43, %edx
leaq 0x30(%rsp), %rcx
callq 0x4fe2
movl %eax, %ebx
movq %rbp, %rdi
callq 0x2040
movl %r15d, %edi
movl %r15d, 0x10(%rsp)
testl %r15d, %r15d
jle 0x8728
movq (%r14,%r13,8), %rax
xorl %ecx, %ecx
movl 0xfd4(%rsp,%rcx,8), %edx
movl (%rax), %esi
decl %esi
cmpl %esi, %edx
je 0x8720
incl %edx
movl %edx, 0xfd4(%rsp,%rcx,8)
incq %rcx
cmpq %rcx, %rdi
jne 0x8708
movq %rdi, 0x28(%rsp)
movl 0xc(%rsp), %r8d
movl %r8d, %ebp
testl %r8d, %r8d
jle 0x8760
movq (%r14,%r13,8), %rax
xorl %ecx, %ecx
movl 0x1f74(%rsp,%rcx,8), %edx
movl (%rax), %esi
decl %esi
cmpl %esi, %edx
je 0x8758
incl %edx
movl %edx, 0x1f74(%rsp,%rcx,8)
incq %rcx
cmpq %rcx, %rbp
jne 0x8740
movl %ebx, %edi
testl %ebx, %ebx
jle 0x8786
movq (%r14,%r13,8), %rax
xorl %ecx, %ecx
movl 0x34(%rsp,%rcx,8), %edx
movl (%rax), %esi
decl %esi
cmpl %esi, %edx
je 0x877e
incl %edx
movl %edx, 0x34(%rsp,%rcx,8)
incq %rcx
cmpq %rcx, %rdi
jne 0x876c
movq %rdi, 0x20(%rsp)
movl %ebx, 0x14(%rsp)
testl %r8d, %r8d
movq %r14, %r15
leaq 0x116b6(%rip), %r14     # 0x19e52
jle 0x87e4
xorl %ebx, %ebx
movq (%r15,%r13,8), %rax
movsbl 0x40(%rax), %edx
movq 0x68(%rax), %rax
movslq 0x1f70(%rsp,%rbx,8), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
movslq 0x1f74(%rsp,%rbx,8), %rsi
movq (%rax,%rsi,8), %r9
addq $0x4, %r9
movq %r12, %rdi
movq %r14, %rsi
movl %edx, %r8d
xorl %eax, %eax
callq 0x2160
incq %rbx
cmpq %rbx, %rbp
jne 0x87a0
cmpl $0x0, 0x10(%rsp)
movq %r15, %r14
leaq 0x11679(%rip), %r15     # 0x19e6c
movq 0x28(%rsp), %rbp
jle 0x8840
xorl %ebx, %ebx
movq (%r14,%r13,8), %rax
movsbl 0x40(%rax), %edx
movq 0x68(%rax), %rax
movslq 0xfd0(%rsp,%rbx,8), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
movslq 0xfd4(%rsp,%rbx,8), %rsi
movq (%rax,%rsi,8), %r9
addq $0x4, %r9
movq %r12, %rdi
movq %r15, %rsi
movl %edx, %r8d
xorl %eax, %eax
callq 0x2160
incq %rbx
cmpq %rbx, %rbp
jne 0x87fc
cmpl $0x0, 0x14(%rsp)
leaq 0x1163b(%rip), %r15     # 0x19e87
movq 0x20(%rsp), %rbp
jle 0x8893
xorl %ebx, %ebx
movq (%r14,%r13,8), %rax
movsbl 0x40(%rax), %edx
movq 0x68(%rax), %rax
movslq 0x30(%rsp,%rbx,8), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
movslq 0x34(%rsp,%rbx,8), %rsi
movq (%rax,%rsi,8), %r9
addq $0x4, %r9
movq %r12, %rdi
movq %r15, %rsi
movl %edx, %r8d
xorl %eax, %eax
callq 0x2160
incq %rbx
cmpq %rbx, %rbp
jne 0x8855
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x8646
leaq 0x115f8(%rip), %rdi     # 0x19ea0
movl $0x9, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x2240
movq %r12, %rdi
callq 0x20a0
movl $0x1, %eax
addq $0x2f18, %rsp           # imm = 0x2F18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x114ca(%rip), %rsi     # 0x19daa
xorl %edi, %edi
movq %r15, %rdx
xorl %eax, %eax
addq $0x2f18, %rsp           # imm = 0x2F18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2424
nopl (%rax)