// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movl %esi, %eax
movq %rax, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
testl %esi, %esi
jle 0x14733
xorl %r14d, %r14d
xorl %r12d, %r12d
movq (%rbp,%r14,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x14727
movl (%rax), %ecx
testl %ecx, %ecx
jle 0x14727
xorl %ebx, %ebx
movq 0x68(%rax), %rdx
movq (%rdx,%rbx,8), %rdi
cmpl $0x0, (%rdi)
jle 0x1471c
movl $0x10, %r15d
xorl %r13d, %r13d
addq %r15, %rdi
callq 0x4f9a
cmpl $0x1, %eax
adcl $0x0, %r12d
incq %r13
movq (%rbp,%r14,8), %rax
movq 0x68(%rax), %rcx
movq (%rcx,%rbx,8), %rdi
movslq (%rdi), %rcx
addq $0x5, %r15
cmpq %rcx, %r13
jl 0x146ef
movl (%rax), %ecx
incq %rbx
movslq %ecx, %rdx
cmpq %rdx, %rbx
jl 0x146d9
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x146c6
jmp 0x14736
xorl %r12d, %r12d
leal (%r12,%r12,2), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x5880
movq %rax, %r13
movslq %r12d, %rdi
shlq $0x3, %rdi
callq 0x5880
movq %rax, %rsi
cmpl $0x0, 0x2c(%rsp)
movq %rax, 0x48(%rsp)
jle 0x1498f
xorl %r8d, %r8d
movq %r13, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %r13, 0x60(%rsp)
movq %rbp, 0x38(%rsp)
movq %r12, 0x68(%rsp)
movq (%rbp,%r8,8), %rax
cmpl $0x0, 0x58(%rax)
je 0x14876
movl (%rax), %ecx
testl %ecx, %ecx
jle 0x14876
xorl %esi, %esi
movq 0x68(%rax), %rdx
movq (%rdx,%rsi,8), %rdi
cmpl $0x0, (%rdi)
jle 0x14867
movl $0x10, %ebp
movl $0x190, %ebx            # imm = 0x190
xorl %r14d, %r14d
movq %rsi, %r12
movq %r8, %r13
addq %rbp, %rdi
callq 0x4f9a
testl %eax, %eax
je 0x147dc
movq 0x38(%rsp), %r15
movq %r13, %r8
movq %r12, %rsi
jmp 0x14838
movq 0x38(%rsp), %r15
movq (%r15,%r13,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r12,8), %rdi
cvtps2pd -0x8(%rdi,%rbx), %xmm0
movq 0x58(%rsp), %rax
movups %xmm0, (%rax)
xorps %xmm0, %xmm0
cvtss2sd (%rdi,%rbx), %xmm0
movsd %xmm0, 0x10(%rax)
addq $0x18, %rax
movq %rax, 0x58(%rsp)
addq %rbp, %rdi
callq 0x4a68
movq %r12, %rsi
movq %r13, %r8
addsd 0x508a(%rip), %xmm0     # 0x198b0
movq 0x50(%rsp), %rax
movsd %xmm0, (%rax)
addq $0x8, %rax
movq %rax, 0x50(%rsp)
incq %r14
movq (%r15,%r8,8), %rax
movq 0x68(%rax), %rcx
movq (%rcx,%rsi,8), %rdi
movslq (%rdi), %rcx
addq $0x5, %rbp
addq $0xc, %rbx
cmpq %rcx, %r14
jl 0x147bd
movl (%rax), %ecx
movq 0x38(%rsp), %rbp
movq 0x68(%rsp), %r12
incq %rsi
movslq %ecx, %rdx
cmpq %rdx, %rsi
jl 0x1479f
incq %r8
cmpq 0x30(%rsp), %r8
movq 0x60(%rsp), %r13
jne 0x14784
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x70(%rsp), %r9
movq %r13, %rdi
movq 0x48(%rsp), %rsi
movl %r12d, %edx
movl $0x258, %ecx            # imm = 0x258
movl $0x4, %r8d
callq 0x135e3
cmpl $0x0, 0x2c(%rsp)
jle 0x149c6
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rcx
cmpl $0x0, 0x58(%rcx)
je 0x1497f
movl (%rcx), %eax
testl %eax, %eax
jle 0x1497f
xorl %r15d, %r15d
movq 0x68(%rcx), %rdx
movq (%rdx,%r15,8), %rdi
movq 0x768(%rdi), %rdx
movl $0x0, 0x14(%rdx)
cmpl $0x0, (%rdi)
jle 0x14970
movl $0x10, %ebx
xorl %r12d, %r12d
addq %rbx, %rdi
callq 0x4f9a
movq (%rbp,%r14,8), %rcx
testl %eax, %eax
je 0x1492d
movq 0x68(%rcx), %rax
movq (%rax,%r15,8), %rdi
jmp 0x1495f
movq 0x40(%rsp), %rax
leaq 0x8(%rax), %rdx
movq %rdx, 0x40(%rsp)
movq 0x68(%rcx), %rdx
movq (%rdx,%r15,8), %rdi
movq 0x768(%rdi), %rdx
xorps %xmm0, %xmm0
cvtss2sd 0x14(%rdx), %xmm0
addsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rdx)
incq %r12
movslq (%rdi), %rax
addq $0x5, %rbx
cmpq %rax, %r12
jl 0x14912
movl (%rcx), %eax
incq %r15
movslq %eax, %rdx
cmpq %rdx, %r15
jl 0x148ef
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x148d3
jmp 0x149c6
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x70(%rsp), %r9
movq %r13, %rdi
movl %r12d, %edx
movl $0x258, %ecx            # imm = 0x258
movl $0x4, %r8d
callq 0x135e3
movq %r13, %rdi
callq 0x2040
movq 0x48(%rsp), %rdi
callq 0x2040
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop