// File: /workspace/github_c_makefile_star2_O1/josch[P]stride/area.c
// Function: Area
void Area(CHAIN **Chain, int NChain, COMMAND *Cmd)
{

  double *Coord, *Radii, OverallArea, *AreaPerAtom, *p1, *p2;
  int At, TotalAt=0, Cn, Res, DotsPerSphere=600;

  for( Cn=0; Cn<NChain; Cn++ ) {

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

    for( Res=0; Res<Chain[Cn]->NRes; Res++ )
      for( At=0; At<Chain[Cn]->Rsd[Res]->NAtom; At++ )
	if( !IsHydrogen(Chain[Cn]->Rsd[Res]->AtomType[At]) )
	  TotalAt ++;
  }

  Coord = (double *)ckalloc(3*TotalAt*sizeof(double));
  Radii = (double *)ckalloc(TotalAt*sizeof(double));

  p1 = Coord;
  p2 = Radii;

  for( Cn=0; Cn<NChain; Cn++ ) {

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

    for( Res=0; Res<Chain[Cn]->NRes; Res++ )
      for( At=0; At<Chain[Cn]->Rsd[Res]->NAtom; At++ ) 
	if( !IsHydrogen(Chain[Cn]->Rsd[Res]->AtomType[At]) ) {
	  (*p1++) = (double)Chain[Cn]->Rsd[Res]->Coord[At][0];
	  (*p1++) = (double)Chain[Cn]->Rsd[Res]->Coord[At][1];
	  (*p1++) = (double)Chain[Cn]->Rsd[Res]->Coord[At][2];
	  (*p2++) = GetAtomRadius(Chain[Cn]->Rsd[Res]->AtomType[At])+1.4;
	}
  
  }  

  p1 = Coord;
  p2 = Radii;

  NSC(Coord,Radii,TotalAt,DotsPerSphere,FLAG_ATOM_AREA,&OverallArea,
      &AreaPerAtom,NULL,NULL,NULL);
    
    for( Cn=0; Cn<NChain; Cn++ ) {

      if( !Chain[Cn]->Valid )
	continue;
      
      for( Res=0; Res<Chain[Cn]->NRes; Res++ ) {
	Chain[Cn]->Rsd[Res]->Prop->Solv = 0.0;
	for( At=0; At<Chain[Cn]->Rsd[Res]->NAtom; At++ )
	  if( !IsHydrogen(Chain[Cn]->Rsd[Res]->AtomType[At]) ) {
	    Chain[Cn]->Rsd[Res]->Prop->Solv += (*AreaPerAtom++);
	  }
      }
    }
  free(Coord);
  free(Radii);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movl %esi, %eax
movq %rax, 0x40(%rsp)
movl %esi, 0x2c(%rsp)
testl %esi, %esi
jle 0x148be
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%rbx,%r14,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x148b2
movq (%rbx,%r14,8), %rax
cmpl $0x0, (%rax)
jle 0x148b2
xorl %r12d, %r12d
movq (%rbx,%r14,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r12,8), %rdi
cmpl $0x0, (%rdi)
jle 0x148a3
movl $0x10, %r13d
xorl %ebp, %ebp
addq %r13, %rdi
callq 0x5072
cmpl $0x1, %eax
adcl $0x0, %r15d
incq %rbp
movq (%rbx,%r14,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r12,8), %rdi
movslq (%rdi), %rax
addq $0x5, %r13
cmpq %rax, %rbp
jl 0x14879
incq %r12
movq (%rbx,%r14,8), %rax
movslq (%rax), %rax
cmpq %rax, %r12
jl 0x14860
incq %r14
cmpq 0x40(%rsp), %r14
jne 0x1484a
jmp 0x148c1
xorl %r15d, %r15d
leal (%r15,%r15,2), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x595c
movq %rax, 0x38(%rsp)
movslq %r15d, %rdi
shlq $0x3, %rdi
callq 0x595c
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x2c(%rsp)
jle 0x14a14
xorl %ecx, %ecx
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r15, 0x60(%rsp)
movq (%rbx,%rcx,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x14a01
movq (%rbx,%rcx,8), %rax
cmpl $0x0, (%rax)
jle 0x14a01
xorl %r13d, %r13d
movq %rcx, 0x68(%rsp)
movq (%rbx,%rcx,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r13,8), %rdi
cmpl $0x0, (%rdi)
jle 0x149ee
movl $0x10, %ebp
movl $0x190, %r14d           # imm = 0x190
xorl %r12d, %r12d
movq %rbx, %r15
movq %rcx, %rbx
addq %rbp, %rdi
callq 0x5072
testl %eax, %eax
je 0x1496d
movq %rbx, %rcx
movq %r15, %rbx
jmp 0x149cb
movq %rbx, %rax
movq %r15, %rbx
movq (%r15,%rax,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r13,8), %rdi
cvtps2pd -0x8(%rdi,%r14), %xmm0
movq 0x50(%rsp), %rax
movups %xmm0, (%rax)
xorps %xmm0, %xmm0
cvtss2sd (%rdi,%r14), %xmm0
movsd %xmm0, 0x10(%rax)
addq $0x18, %rax
movq %rax, 0x50(%rsp)
addq %rbp, %rdi
callq 0x4b26
movq 0x68(%rsp), %rcx
movq 0x48(%rsp), %rax
addsd 0x4eda(%rip), %xmm0     # 0x19898
movsd %xmm0, (%rax)
addq $0x8, %rax
movq %rax, 0x48(%rsp)
incq %r12
movq (%rbx,%rcx,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r13,8), %rdi
movslq (%rdi), %rax
addq $0x5, %rbp
addq $0xc, %r14
cmpq %rax, %r12
jl 0x14953
incq %r13
movq (%rbx,%rcx,8), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jl 0x14930
incq %rcx
cmpq 0x40(%rsp), %rcx
movq 0x60(%rsp), %r15
jne 0x1490d
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x70(%rsp), %r9
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl %r15d, %edx
movl $0x258, %ecx            # imm = 0x258
movl $0x4, %r8d
callq 0x136e9
cmpl $0x0, 0x2c(%rsp)
jle 0x14b2c
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x14b1e
movq (%rbx,%r14,8), %rax
cmpl $0x0, (%rax)
jle 0x14b1e
xorl %r15d, %r15d
movq 0x68(%rax), %rax
movq (%rax,%r15,8), %rax
movq 0x768(%rax), %rax
movl $0x0, 0x14(%rax)
movq (%rbx,%r14,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r15,8), %rdi
cmpl $0x0, (%rdi)
jle 0x14b0b
movl $0x10, %r12d
xorl %r13d, %r13d
addq %r12, %rdi
callq 0x5072
testl %eax, %eax
jne 0x14af0
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq (%rbx,%r14,8), %rcx
movq 0x68(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movq 0x768(%rcx), %rcx
xorps %xmm0, %xmm0
cvtss2sd 0x14(%rcx), %xmm0
addsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rcx)
incq %r13
movq (%rbx,%r14,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r15,8), %rdi
movslq (%rdi), %rax
addq $0x5, %r12
cmpq %rax, %r13
jl 0x14aae
incq %r15
movq (%rbx,%r14,8), %rax
movslq (%rax), %rcx
cmpq %rcx, %r15
jl 0x14a7e
incq %r14
cmpq 0x40(%rsp), %r14
jne 0x14a60
movq 0x38(%rsp), %rdi
callq 0x2040
movq 0x30(%rsp), %rdi
callq 0x2040
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop