user: 请将以下的汇编代码转换成C语言代码：

```asm
<conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm>:
  endbr64
  movapd %xmm0,%xmm6
  push   %r15
  mov    %r8d,%eax
  movapd %xmm0,%xmm3
  mulsd  %xmm0,%xmm6
  push   %r14
  imul   %r8d,%eax
  push   %r13
  push   %r12
  push   %rbp
  mov    %esi,%ebp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x108,%rsp
  mov    %edi,0x64(%rsp)
  mov    0x158(%rsp),%rdx
  mov    %ecx,0xd0(%rsp)
  mov    0x1e8(%rsp),%r15
  mov    %r8d,0xfc(%rsp)
  mov    0x1f0(%rsp),%r14
  mov    %r9d,0x68(%rsp)
  mov    %eax,0x6c(%rsp)
  movsd  %xmm1,(%rsp)
  movsd  %xmm6,0xf0(%rsp)
  test   %edi,%edi
  jle    L260
  mov    %esi,%edi
  xor    %eax,%eax
  movsd  %xmm0,0x8(%rsp)
  call   <assert@plt>
  mov    0x158(%rsp),%rdx
  movsd  0x8(%rsp),%xmm3
L260:
  test   %ebx,%ebx
  jle    L115
  mov    0x150(%rsp),%rax
  mov    0x6c(%rsp),%edi
  movl   $0x0,0xf8(%rsp)
  mov    0xd0(%rsp),%r12d
  mov    %rdx,0x158(%rsp)
  mov    %rax,0xb0(%rsp)
  mov    %edi,%eax
  imul   %r12d,%eax
  mov    %r15,0x1e8(%rsp)
  movl   $0x0,0xe4(%rsp)
  movl   $0x0,0xd4(%rsp)
  mov    %eax,0xe0(%rsp)
  lea    -0x1(%rbx),%eax
  mov    0x150(%rsp),%rbx
  mov    %r14,0x1f0(%rsp)
  lea    0x4(%rbx,%rax,4),%rax
  movsd  %xmm3,0x50(%rsp)
  mov    %rax,0xd8(%rsp)
  movslq %edi,%rax
  lea    0x0(,%rax,8),%rbx
  mov    0x150(%rsp),%rax
  mov    %rbx,0x58(%rsp)
  mov    %rax,0xa8(%rsp)
  nopw   0x0(%rax,%rax,1)
L234:
  mov    0xa8(%rsp),%rax
  mov    (%rax),%ecx
  test   %r12d,%r12d
  jle    L26
  movslq 0xe4(%rsp),%rsi
  lea    -0x1(%r12),%edx
  pxor   %xmm0,%xmm0
  mov    0x1a0(%rsp),%rax
  mov    0x1a0(%rsp),%rdi
  add    %rsi,%rdx
  lea    (%rax,%rsi,8),%rax
  lea    0x8(%rdi,%rdx,8),%rdx
L122:
  addsd  (%rax),%xmm0
  add    $0x8,%rax
  cmp    %rax,%rdx
  jne    L122
  movslq 0xd4(%rsp),%rax
  movsd  %xmm0,0xe8(%rsp)
  mov    %rax,0xc8(%rsp)
  test   %ebp,%ebp
  je     L225
  mov    0x1c8(%rsp),%rdx
  movq   $0x0,(%rdx,%rax,8)
  mov    0x1d0(%rsp),%rdx
  movq   $0x0,(%rdx,%rax,8)
L225:
  mov    0x168(%rsp),%rdi
  movslq %ecx,%rax
  xor    %r13d,%r13d
  movslq 0xf8(%rsp),%rdx
  shl    $0x3,%rax
  mov    0x1e8(%rsp),%r15
  add    %rax,%rdi
  shl    $0x3,%rdx
  mov    %rdi,0xb8(%rsp)
  mov    0x170(%rsp),%rdi
  add    %rdx,%r15
  add    0x1f0(%rsp),%rdx
  add    %rax,%rdi
  mov    %rdx,%r14
  mov    %ebp,%edx
  mov    %rbx,%rbp
  mov    %rdi,0x28(%rsp)
  mov    0x178(%rsp),%rdi
  mov    %r14,%rbx
  mov    %edx,%r14d
  add    %rax,%rdi
  add    0x160(%rsp),%rax
  mov    %rax,0xc0(%rsp)
  mov    0xc8(%rsp),%rax
  mov    %rdi,0x30(%rsp)
  mov    0x1c8(%rsp),%rdi
  shl    $0x3,%rax
  add    %rax,%rdi
  add    0x1d0(%rsp),%rax
  mov    %rax,0x78(%rsp)
  lea    0x0(,%rsi,8),%rax
  mov    0x188(%rsp),%rsi
  mov    %rdi,0x70(%rsp)
  add    %rax,%rsi
  mov    %rsi,0x48(%rsp)
  mov    0x1a8(%rsp),%rsi
  add    %rax,%rsi
  mov    %rsi,0x40(%rsp)
  mov    0x1b0(%rsp),%rsi
  add    %rax,%rsi
  add    0x1a0(%rsp),%rax
  mov    %rax,0x80(%rsp)
  mov    %r12d,%eax
  mov    %r15,%r12
  mov    %rsi,0x38(%rsp)
  mov    %eax,%r15d
  jmp    L73
  nopl   0x0(%rax,%rax,1)
L287:
  mov    D70(%rip),%rax
  addsd  %xmm9,%xmm4
  movq   $0x0,0x20(%rsp)
  movq   %rax,%xmm1
  mov    D145(%rip),%rax
  movq   %rax,%xmm3
L102:
  mulsd  (%rsp),%xmm2
  movsd  %xmm1,0x18(%rsp)
  movsd  %xmm3,0x10(%rsp)
  movsd  %xmm4,0x8(%rsp)
  movapd %xmm2,%xmm0
  call   <exp@plt>
  mulsd  0x50(%rsp),%xmm0
  mov    0x40(%rsp),%rax
  movsd  0x8(%rsp),%xmm4
  movsd  0x10(%rsp),%xmm3
  movsd  0x18(%rsp),%xmm1
  movapd %xmm4,%xmm2
  mulsd  %xmm0,%xmm2
  movsd  %xmm2,(%rax,%r13,8)
  movsd  0x20(%rsp),%xmm2
  mov    0x38(%rsp),%rax
  mulsd  %xmm0,%xmm2
  mulsd  (%rsp),%xmm0
  mulsd  %xmm4,%xmm0
  subsd  %xmm2,%xmm0
  movsd  %xmm0,(%rax,%r13,8)
  movsd  %xmm3,(%r12)
  movsd  %xmm1,(%rbx)
  test   %r14d,%r14d
  je     L196
  mov    0x80(%rsp),%rax
  mov    0x70(%rsp),%rsi
  mulsd  (%rax,%r13,8),%xmm3
  addsd  (%rsi),%xmm3
  movsd  %xmm3,(%rsi)
  mulsd  (%rax,%r13,8),%xmm1
  mov    0x78(%rsp),%rax
  addsd  (%rax),%xmm1
  movsd  %xmm1,(%rax)
L196:
  add    $0x1,%r13
  add    %rbp,%r12
  add    %rbp,%rbx
  cmp    %r13d,%r15d
  jle    L142
L73:
  mov    0x48(%rsp),%rax
  pxor   %xmm5,%xmm5
  movsd  (%rax,%r13,8),%xmm2
  mov    0x28(%rsp),%rax
  comisd %xmm2,%xmm5
  movsd  (%rax),%xmm4
  mov    0x30(%rsp),%rax
  movsd  (%rax),%xmm9
  jbe    L287
  mov    0xb8(%rsp),%rax
  movapd %xmm2,%xmm5
  xorpd  D70(%rip),%xmm5
  movsd  %xmm9,0xa0(%rsp)
  movsd  %xmm4,0x98(%rsp)
  movsd  %xmm2,0x90(%rsp)
  movsd  (%rax),%xmm12
  mov    0xc0(%rsp),%rax
  movsd  (%rax),%xmm3
  movapd %xmm12,%xmm1
  movsd  %xmm12,0x10(%rsp)
  subsd  D125(%rip),%xmm1
  movsd  %xmm3,0x88(%rsp)
  mulsd  %xmm3,%xmm5
  movapd %xmm5,%xmm0
  movsd  %xmm5,0x8(%rsp)
  call   <pow@plt>
  movsd  0x8(%rsp),%xmm5
  movsd  0x10(%rsp),%xmm12
  movsd  %xmm0,0x20(%rsp)
  movsd  D145(%rip),%xmm1
  movapd %xmm5,%xmm10
  mulsd  %xmm0,%xmm10
  movsd  D145(%rip),%xmm0
  divsd  %xmm12,%xmm0
  mulsd  %xmm10,%xmm5
  movsd  %xmm10,0x18(%rsp)
  addsd  D145(%rip),%xmm5
  movsd  %xmm5,0x8(%rsp)
  subsd  %xmm0,%xmm1
  xorpd  D70(%rip),%xmm1
  movapd %xmm5,%xmm0
  call   <pow@plt>
  movsd  0x8(%rsp),%xmm5
  movsd  0x10(%rsp),%xmm12
  movapd %xmm0,%xmm1
  movsd  0x18(%rsp),%xmm10
  movsd  D145(%rip),%xmm8
  divsd  %xmm5,%xmm1
  movsd  0x88(%rsp),%xmm3
  movsd  0x20(%rsp),%xmm11
  subsd  %xmm12,%xmm8
  subsd  D145(%rip),%xmm12
  movsd  0xa0(%rsp),%xmm9
  movsd  D145(%rip),%xmm6
  movsd  0x98(%rsp),%xmm4
  movsd  0x90(%rsp),%xmm2
  mulsd  %xmm3,%xmm8
  xorpd  D70(%rip),%xmm3
  mulsd  %xmm12,%xmm3
  movapd %xmm3,%xmm5
  pxor   %xmm3,%xmm3
  mulsd  %xmm11,%xmm5
  ucomisd %xmm0,%xmm3
  mulsd  %xmm0,%xmm5
  mulsd  %xmm1,%xmm8
  movapd %xmm10,%xmm1
  mulsd  %xmm0,%xmm1
  mulsd  %xmm10,%xmm8
  subsd  %xmm1,%xmm6
  movapd %xmm9,%xmm1
  mulsd  %xmm0,%xmm1
  movapd %xmm6,%xmm7
  mulsd  %xmm8,%xmm10
  mulsd  %xmm8,%xmm9
  mulsd  %xmm6,%xmm7
  addsd  %xmm1,%xmm4
  subsd  %xmm10,%xmm5
  movsd  %xmm9,0x20(%rsp)
  ja     L162
  sqrtsd %xmm0,%xmm0
L262:
  movsd  D50(%rip),%xmm1
  movapd %xmm7,%xmm3
  mulsd  %xmm0,%xmm3
  divsd  %xmm0,%xmm1
  addsd  %xmm0,%xmm0
  mulsd  %xmm6,%xmm0
  mulsd  %xmm5,%xmm0
  mulsd  %xmm8,%xmm1
  mulsd  %xmm7,%xmm1
  addsd  %xmm0,%xmm1
  xorpd  D70(%rip),%xmm1
  jmp    L102
  nopl   (%rax)
L142:
  mov    %rbp,%rbx
  mov    %r15d,%r12d
  mov    %r14d,%ebp
  test   %r14d,%r14d
  je     L46
L217:
  mov    0xc8(%rsp),%rax
  mov    0x1c8(%rsp),%rdx
  movsd  0xe8(%rsp),%xmm6
  shl    $0x3,%rax
  add    %rax,%rdx
  add    0x1d0(%rsp),%rax
  movsd  (%rdx),%xmm0
  divsd  %xmm6,%xmm0
  movsd  %xmm0,(%rdx)
  movsd  (%rax),%xmm0
  divsd  %xmm6,%xmm0
  movsd  %xmm0,(%rax)
L46:
  addq   $0x4,0xa8(%rsp)
  mov    0x6c(%rsp),%esi
  mov    0xe0(%rsp),%edi
  add    %esi,0xd4(%rsp)
  add    %r12d,0xe4(%rsp)
  mov    0xa8(%rsp),%rax
  add    %edi,0xf8(%rsp)
  cmp    0xd8(%rsp),%rax
  jne    L234
  mov    0xfc(%rsp),%eax
  mov    0xd0(%rsp),%esi
  movl   $0x0,0x20(%rsp)
  pxor   %xmm4,%xmm4
  movl   $0x0,0x28(%rsp)
  movsd  0x50(%rsp),%xmm3
  mov    %eax,%ebx
  cltq
  movl   $0x0,0x30(%rsp)
  mov    0x158(%rsp),%rdx
  imul   %esi,%ebx
  lea    0x8(,%rax,8),%r10
  mov    0x1e8(%rsp),%r15
  mov    0x1f0(%rsp),%r14
  movsd  D3(%rip),%xmm5
  movsd  0xf0(%rsp),%xmm6
  mov    %ebx,0x38(%rsp)
  mov    %rax,%rbx
  lea    -0x1(%rsi),%eax
  mov    %rax,0x40(%rsp)
  mov    0x148(%rsp),%rax
  lea    -0x1(%rbx),%r9d
  mov    %ebx,%r13d
  mov    %r9d,0x18(%rsp)
  add    $0x4,%rax
  mov    %rax,0x48(%rsp)
  nopw   0x0(%rax,%rax,1)
L213:
  mov    0xb0(%rsp),%rax
  mov    0xd0(%rsp),%esi
  movslq (%rax),%rax
  test   %esi,%esi
  jle    L189
  mov    0x180(%rsp),%rbx
  mov    0x48(%rsp),%rsi
  lea    (%rbx,%rax,8),%rax
  mov    0x148(%rsp),%rbx
  mov    %rax,0x8(%rsp)
  movslq 0x20(%rsp),%rax
  lea    (%rbx,%rax,4),%r12
  add    0x40(%rsp),%rax
  movslq 0x28(%rsp),%rbx
  lea    (%rsi,%rax,4),%rax
  mov    %rax,0x10(%rsp)
  mov    0x30(%rsp),%eax
  shl    $0x3,%rbx
  mov    %eax,(%rsp)
  nopw   0x0(%rax,%rax,1)
L13:
  mov    0x8(%rsp),%rsi
  mov    (%r12),%eax
  movsd  (%rsi),%xmm1
  lea    (%rax,%rax,1),%ebp
  mov    0x140(%rsp),%rsi
  movslq %ebp,%rbp
  mov    0x4(%rsi,%rbp,4),%r11d
  movapd %xmm1,%xmm0
  test   %r11d,%r11d
  js     L202
  mov    0x150(%rsp),%rsi
  movslq %r11d,%rcx
  movslq (%rsi,%rcx,4),%rcx
  mov    0x180(%rsp),%rsi
  movsd  (%rsi,%rcx,8),%xmm0
L202:
  movapd %xmm1,%xmm8
  addsd  %xmm1,%xmm8
  mulsd  %xmm0,%xmm8
  addsd  %xmm1,%xmm0
  addsd  %xmm5,%xmm0
  divsd  %xmm0,%xmm8
  test   %r13d,%r13d
  jle    L257
  imul   0x68(%rsp),%eax
  movapd %xmm3,%xmm7
  movslq (%rsp),%rsi
  movapd %xmm6,%xmm9
  mov    0x190(%rsp),%rdi
  mulsd  %xmm8,%xmm9
  movapd %xmm4,%xmm1
  mulsd  %xmm8,%xmm7
  imul   %r13d,%eax
  lea    (%rdi,%rsi,8),%r8
  mov    0x198(%rsp),%rdi
  cltq
  lea    (%rdi,%rax,8),%rdi
  xor    %eax,%eax
  nopw   0x0(%rax,%rax,1)
L81:
  movsd  (%rdx,%rax,8),%xmm0
  movsd  (%r8,%rax,8),%xmm2
  mov    %rax,%rcx
  mulsd  %xmm9,%xmm0
  mulsd  %xmm7,%xmm2
  subsd  %xmm2,%xmm0
  mulsd  (%rdi,%rax,8),%xmm0
  add    $0x1,%rax
  addsd  %xmm0,%xmm1
  cmp    %rcx,%r9
  jne    L81
  comisd %xmm4,%xmm1
  jb     L123
L257:
  mov    0x140(%rsp),%rax
  mov    0x64(%rsp),%ecx
  movsd  (%r15,%rbx,1),%xmm1
  movsd  (%r14,%rbx,1),%xmm2
  mov    (%rax,%rbp,4),%r11d
  test   %ecx,%ecx
  jle    L242
L98:
  imul   0x6c(%rsp),%r11d
  mov    0x1c8(%rsp),%rax
  movslq %r11d,%r11
  movsd  (%rax,%r11,8),%xmm1
L242:
  movslq (%rsp),%rsi
  test   %r13d,%r13d
  jle    L8
L276:
  movapd %xmm6,%xmm9
  movapd %xmm6,%xmm7
  shl    $0x3,%rsi
  mov    %rbx,%rcx
  mulsd  %xmm1,%xmm9
  mov    0x1d8(%rsp),%r11
  mov    0x18(%rsp),%r8d
  xor    %eax,%eax
  mulsd  %xmm2,%xmm7
  mulsd  %xmm3,%xmm1
  add    %rsi,%r11
  add    0x1e0(%rsp),%rsi
  mulsd  %xmm3,%xmm2
  mulsd  %xmm8,%xmm9
  mulsd  %xmm8,%xmm7
  mulsd  %xmm8,%xmm1
  mulsd  %xmm8,%xmm2
  nopw   0x0(%rax,%rax,1)
L153:
  movsd  (%rdx,%rax,8),%xmm0
  mov    %rax,%rdi
  mulsd  %xmm9,%xmm0
  movsd  %xmm0,(%r11,%rax,8)
  movsd  (%rdx,%rax,8),%xmm0
  mulsd  %xmm7,%xmm0
  movsd  %xmm0,(%rsi,%rax,8)
  add    $0x1,%rax
  movsd  %xmm1,(%r15,%rcx,1)
  movsd  %xmm2,(%r14,%rcx,1)
  add    %r10,%rcx
  cmp    %rdi,%r8
  jne    L153
L8:
  add    %r13d,(%rsp)
  add    $0x4,%r12
  add    0x58(%rsp),%rbx
  cmp    %r12,0x10(%rsp)
  jne    L13
L189:
  mov    0x38(%rsp),%esi
  mov    0xe0(%rsp),%edi
  addq   $0x4,0xb0(%rsp)
  mov    0xb0(%rsp),%rax
  add    %esi,0x30(%rsp)
  mov    0xd0(%rsp),%esi
  add    %edi,0x28(%rsp)
  add    %esi,0x20(%rsp)
  cmp    0xd8(%rsp),%rax
  jne    L213
L115:
  add    $0x108,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L123:
  test   %r11d,%r11d
  js     L257
  mov    0x64(%rsp),%eax
  movsd  (%r15,%rbx,1),%xmm1
  movsd  (%r14,%rbx,1),%xmm2
  test   %eax,%eax
  jg     L98
  jmp    L276
L26:
  test   %ebp,%ebp
  je     L46
  movslq 0xd4(%rsp),%rax
  mov    0x1c8(%rsp),%rdx
  pxor   %xmm6,%xmm6
  movsd  %xmm6,0xe8(%rsp)
  movq   $0x0,(%rdx,%rax,8)
  mov    0x1d0(%rsp),%rdx
  mov    %rax,0xc8(%rsp)
  movq   $0x0,(%rdx,%rax,8)
  jmp    L217
L162:
  movsd  %xmm5,0x98(%rsp)
  movsd  %xmm7,0x90(%rsp)
  movsd  %xmm6,0x88(%rsp)
  movsd  %xmm8,0x18(%rsp)
  movsd  %xmm4,0x10(%rsp)
  movsd  %xmm2,0x8(%rsp)
  call   <sqrt@plt>
  movsd  0x18(%rsp),%xmm8
  movsd  0x98(%rsp),%xmm5
  movsd  0x90(%rsp),%xmm7
  movsd  0x10(%rsp),%xmm4
  movsd  0x88(%rsp),%xmm6
  movsd  0x8(%rsp),%xmm2
  jmp    L262
```

tool_calls: name: read_data
arguments: tag: D70
data_type: f32[4]
name: read_data
arguments: tag: D145
data_type: f64
name: read_data
arguments: tag: D125
data_type: f64
name: read_data
arguments: tag: D50
data_type: f64
name: read_data
arguments: tag: D3
data_type: byte[8]

tool: {"D70": [0.0,-0.0,0.0,0.0]}

tool: D145: 1

tool: D125: 2

tool: D50: 0.5

tool: {"D3": [0xa7,0x8e,0xa8,0x99,0xc2,0x57,0xf3,0x3a]}

assistant: ```c
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm(const int upwindFlag, const int computeAverages, const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int nQuadraturePoints_elementBoundary, const int *elementBoundaryElementsArray, const int *quadraturePointToElementBoundary, const int *materialTypes, const double rho, const double beta, const double *gravity, const double *alpha, const double *n_vg, const double *thetaR, const double *thetaSR, const double *KWs, const double *u, const double *gradu, const double *n_global, const double *dV, double *mass, double *dmass, double *f_avg, double *df_avg, double *a_avg, double *da_avg, double *f, double *df, double *a, double *da) {
  int i, j, k, I, matID;
  const int nSpace2 = nSpace * nSpace;
  register double psiC, pcBar, pcBar_n, pcBar_nM1, pcBar_nM2, onePlus_pcBar_n, sBar, sqrt_sBar, DsBar_DpsiC, thetaW, DthetaW_DpsiC, vBar, vBar2, DvBar_DpsiC, KWr, DKWr_DpsiC, rho2 = rho * rho, thetaS, rhom, drhom, m;
  int eN_upwind, ebN_global;
  register double drive, KWs_harm, KWs_left, KWs_right, krw_val, dkrw_val, vol;
  if (upwindFlag > 0)
    assert(computeAverages);
  for (i = 0; i < nSimplex; i++) {
    matID = materialTypes[i];
    vol = 0.0;
    for (j = 0; j < nPointsPerSimplex; j++)
      vol += dV[i * nPointsPerSimplex + j];
    if (computeAverages) {
      a_avg[i * nSpace2 + 0 * nSpace + 0] = 0.0;
      da_avg[i * nSpace2 + 0 * nSpace + 0] = 0.0;
    }
    for (j = 0; j < nPointsPerSimplex; j++) {
      k = i * nPointsPerSimplex + j;
      psiC = -u[k];
      m = 1.0 - 1.0 / n_vg[matID];
      thetaS = thetaR[matID] + thetaSR[matID];
      if (psiC > 0.0) {
        pcBar = alpha[matID] * psiC;
        pcBar_nM2 = pow(pcBar, n_vg[matID] - 2);
        pcBar_nM1 = pcBar_nM2 * pcBar;
        pcBar_n = pcBar_nM1 * pcBar;
        onePlus_pcBar_n = 1.0 + pcBar_n;
        sBar = pow(onePlus_pcBar_n, -m);
        DsBar_DpsiC = alpha[matID] * (1.0 - n_vg[matID]) * (sBar / onePlus_pcBar_n) * pcBar_nM1;
        vBar = 1.0 - pcBar_nM1 * sBar;
        vBar2 = vBar * vBar;
        DvBar_DpsiC = -alpha[matID] * (n_vg[matID] - 1.0) * pcBar_nM2 * sBar - pcBar_nM1 * DsBar_DpsiC;
        thetaW = thetaSR[matID] * sBar + thetaR[matID];
        DthetaW_DpsiC = thetaSR[matID] * DsBar_DpsiC;
        sqrt_sBar = sqrt(sBar);
        KWr = sqrt_sBar * vBar2;
        DKWr_DpsiC = ((0.5 / sqrt_sBar) * DsBar_DpsiC * vBar2 + 2.0 * sqrt_sBar * vBar * DvBar_DpsiC);
      } else {
        thetaW = thetaS;
        DthetaW_DpsiC = 0.0;
        KWr = 1.0;
        DKWr_DpsiC = 0.0;
      }
      rhom = rho * exp(beta * u[k]);
      drhom = beta * rhom;
      mass[k] = rhom * thetaW;
      dmass[k] = -rhom * DthetaW_DpsiC + drhom * thetaW;
      a[i * nPointsPerSimplex * nSpace2 + j * nSpace2 + 0 * nSpace + 0] = KWr;
      da[i * nPointsPerSimplex * nSpace2 + j * nSpace2 + 0 * nSpace + 0] = -DKWr_DpsiC;
      if (computeAverages) {
        a_avg[i * nSpace2 + 0 * nSpace + 0] += KWr * dV[k];
        da_avg[i * nSpace2 + 0 * nSpace + 0] += -DKWr_DpsiC * dV[k];
      }
    }
    if (computeAverages) {
      a_avg[i * nSpace2 + 0 * nSpace + 0] /= vol;
      da_avg[i * nSpace2 + 0 * nSpace + 0] /= vol;
    }
  }
  for (i = 0; i < nSimplex; i++) {
    matID = materialTypes[i];
    for (j = 0; j < nPointsPerSimplex; j++) {
      k = i * nPointsPerSimplex + j;
      ebN_global = quadraturePointToElementBoundary[k];
      KWs_left = KWs[matID];
      KWs_right = KWs_left;
      if (elementBoundaryElementsArray[ebN_global * 2 + 1] >= 0)
        KWs_right = KWs[materialTypes[elementBoundaryElementsArray[ebN_global * 2 + 1]]];
      KWs_harm = 2.0 * KWs_left * KWs_right / (KWs_left + KWs_right + 1.0e-24);
      drive = 0.0;
      for (I = 0; I < nSpace; I++) {
        drive += (rho2 * KWs_harm * gravity[I] - rho * KWs_harm * gradu[k * nSpace + I]) * n_global[ebN_global * nQuadraturePoints_elementBoundary * nSpace + 0 * nSpace + I];
      }
      if (drive >= 0.0 || elementBoundaryElementsArray[ebN_global * 2 + 1] < 0)
        eN_upwind = elementBoundaryElementsArray[ebN_global * 2 + 0];
      else
        eN_upwind = elementBoundaryElementsArray[ebN_global * 2 + 1];
      krw_val = a[i * nPointsPerSimplex * nSpace2 + j * nSpace2 + 0 * nSpace + 0];
      dkrw_val = da[i * nPointsPerSimplex * nSpace2 + j * nSpace2 + 0 * nSpace + 0];
      if (upwindFlag > 0) {
        krw_val = a_avg[eN_upwind * nSpace2 + 0 * nSpace + 0];
      }
      for (I = 0; I < nSpace; I++) {
        f[k * nSpace + I] = rho2 * krw_val * KWs_harm * gravity[I];
        df[k * nSpace + I] = rho2 * dkrw_val * KWs_harm * gravity[I];
        a[i * nPointsPerSimplex * nSpace2 + j * nSpace2 + I * nSpace + I] = rho * krw_val * KWs_harm;
        da[i * nPointsPerSimplex * nSpace2 + j * nSpace2 + I * nSpace + I] = rho * dkrw_val * KWs_harm;
      }
    }
  }
}
```