// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %rdi, %r14
xorl %ebx, %ebx
testl %esi, %esi
cmovlel %ebx, %esi
movq %rsi, 0x28(%rsp)
pushq $0x10
popq %r15
movq $0x0, 0x20(%rsp)
cmpq 0x28(%rsp), %rbx
je 0x142ea
movq (%r14,%rbx,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x142e5
xorl %r12d, %r12d
movslq (%rax), %rcx
cmpq %rcx, %r12
jge 0x142e5
movq %r15, %r13
xorl %ebp, %ebp
movq 0x68(%rax), %rcx
movq (%rcx,%r12,8), %rdi
movslq (%rdi), %rcx
cmpq %rcx, %rbp
jge 0x142e0
addq %r13, %rdi
callq 0x4868
cmpl $0x1, %eax
movq 0x20(%rsp), %rax
adcl $0x0, %eax
movq %rax, 0x20(%rsp)
incq %rbp
movq (%r14,%rbx,8), %rax
addq $0x5, %r13
jmp 0x142ab
incq %r12
jmp 0x1429e
incq %rbx
jmp 0x1428a
movq 0x20(%rsp), %r15
leal (%r15,%r15,2), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x50f4
movq %rax, %rbx
movslq %r15d, %rdi
shlq $0x3, %rdi
callq 0x50f4
xorl %edx, %edx
movq %rax, 0x30(%rsp)
movq %rax, 0x48(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
cmpq 0x28(%rsp), %rdx
je 0x1440b
movq (%r14,%rdx,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x14403
xorl %ebx, %ebx
movslq (%rax), %rcx
cmpq %rcx, %rbx
jge 0x14403
movl $0x190, %r12d           # imm = 0x190
pushq $0x10
popq %r13
xorl %ebp, %ebp
movq %rbx, 0x50(%rsp)
movq 0x68(%rax), %rcx
movq (%rcx,%rbx,8), %rdi
movslq (%rdi), %rcx
cmpq %rcx, %rbp
jge 0x143fb
movq %r14, %r15
movq %rdx, %r14
addq %r13, %rdi
callq 0x4868
testl %eax, %eax
je 0x14387
movq %r14, %rdx
jmp 0x143e4
movq (%r15,%r14,8), %rax
movq 0x68(%rax), %rax
movq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
cvtps2pd -0x8(%rdi,%r12), %xmm0
movq 0x40(%rsp), %rax
movups %xmm0, (%rax)
cvtss2sd (%rdi,%r12), %xmm0
movsd %xmm0, 0x10(%rax)
addq $0x18, %rax
movq %rax, 0x40(%rsp)
addq %r13, %rdi
callq 0x434a
movq %r14, %rdx
movq 0x50(%rsp), %rbx
addsd 0x44de(%rip), %xmm0     # 0x188b0
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax)
addq $0x8, %rax
movq %rax, 0x48(%rsp)
incq %rbp
movq (%r15,%rdx,8), %rax
addq $0x5, %r13
addq $0xc, %r12
movq %r15, %r14
jmp 0x1435c
incq %rbx
jmp 0x1433f
incq %rdx
jmp 0x14324
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x18(%rsp)
pushq $0x4
popq %r8
leaq 0x60(%rsp), %r9
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl $0x258, %ecx            # imm = 0x258
callq 0x1342d
xorl %ebx, %ebx
pushq $0x10
popq %r15
cmpq 0x28(%rsp), %rbx
je 0x144ed
movq (%r14,%rbx,8), %rcx
cmpl $0x0, 0x58(%rcx)
je 0x144e5
xorl %r12d, %r12d
movslq (%rcx), %rax
cmpq %rax, %r12
jge 0x144e5
movq 0x68(%rcx), %rax
movq (%rax,%r12,8), %rdi
movq 0x768(%rdi), %rax
andl $0x0, 0x14(%rax)
movq %r15, %r13
xorl %ebp, %ebp
movslq (%rdi), %rax
cmpq %rax, %rbp
jge 0x144e0
addq %r13, %rdi
callq 0x4868
movq (%r14,%rbx,8), %rcx
testl %eax, %eax
je 0x144a8
movq 0x68(%rcx), %rax
movq (%rax,%r12,8), %rdi
jmp 0x144d7
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq 0x68(%rcx), %rdx
movq (%rdx,%r12,8), %rdi
movq 0x768(%rdi), %rdx
cvtss2sd 0x14(%rdx), %xmm0
addsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rdx)
incq %rbp
addq $0x5, %r13
jmp 0x14486
incq %r12
jmp 0x14466
incq %rbx
jmp 0x1444a
movq 0x38(%rsp), %rdi
callq 0x2040
movq 0x30(%rsp), %rdi
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq