user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm_sd>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xe8,%rsp
  mov    %edi,0x6c(%rsp)
  mov    %esi,0x68(%rsp)
  mov    %edx,%ebx
  mov    %ecx,0x44(%rsp)
  mov    %r8d,%eax
  mov    %r8d,0x14(%rsp)
  mov    %r9d,0x70(%rsp)
  mov    0x128(%rsp),%r12
  movsd  %xmm0,0x8(%rsp)
  movsd  %xmm1,0x20(%rsp)
  mov    0x148(%rsp),%r13
  mov    0x1d8(%rsp),%r15
  mov    0x1e0(%rsp),%rbp
  mov    %r8d,%edx
  imul   %r8d,%edx
  mov    %edx,0xdc(%rsp)
  movapd %xmm0,%xmm5
  mulsd  %xmm0,%xmm5
  movsd  %xmm5,0x38(%rsp)
  cltq
  mov    0x120(%rsp),%rdx
  mov    (%rdx,%rax,4),%eax
  mov    %eax,0x40(%rsp)
  test   %edi,%edi
  jg     L4
L20:
  test   %ebx,%ebx
  jle    L314
  mov    0x140(%rsp),%rax
  mov    %rax,0x98(%rsp)
  mov    0x40(%rsp),%eax
  imul   0x44(%rsp),%eax
  mov    %eax,0xd8(%rsp)
  lea    -0x1(%rbx),%eax
  mov    0x140(%rsp),%rbx
  lea    0x4(%rbx,%rax,4),%rax
  mov    %rax,0xd0(%rsp)
  mov    %rbx,0xa0(%rsp)
  movl   $0x0,0xcc(%rsp)
  movl   $0x0,0xc8(%rsp)
  movl   $0x0,0xbc(%rsp)
  movl   $0x0,0xb8(%rsp)
  mov    %r12,0x128(%rsp)
  mov    %r13,0x148(%rsp)
  mov    %r15,0x1d8(%rsp)
  mov    %rbp,%r13
  jmp    L281
L4:
  mov    %esi,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  jmp    L20
L284:
  mov    0xa8(%rsp),%rax
  movsd  (%rax),%xmm7
  mov    0xb0(%rsp),%rax
  movsd  (%rax),%xmm6
  movsd  0x18(%rsp),%xmm0
  xorpd  D27(%rip),%xmm0
  movsd  %xmm6,0x30(%rsp)
  mulsd  %xmm6,%xmm0
  movsd  %xmm7,0x28(%rsp)
  movapd %xmm7,%xmm1
  subsd  D49(%rip),%xmm1
  movsd  %xmm0,0x80(%rsp)
  call   <pow@plt>
  movsd  0x80(%rsp),%xmm4
  movapd %xmm4,%xmm5
  movsd  %xmm0,0x80(%rsp)
  mulsd  %xmm0,%xmm5
  movapd %xmm4,%xmm0
  movsd  %xmm5,0x88(%rsp)
  mulsd  %xmm5,%xmm0
  movapd %xmm0,%xmm2
  addsd  D53(%rip),%xmm2
  movsd  D53(%rip),%xmm0
  divsd  0x28(%rsp),%xmm0
  movsd  D53(%rip),%xmm1
  subsd  %xmm0,%xmm1
  xorpd  D27(%rip),%xmm1
  movsd  %xmm2,0x90(%rsp)
  movapd %xmm2,%xmm0
  call   <pow@plt>
  movsd  D53(%rip),%xmm1
  movsd  0x28(%rsp),%xmm7
  subsd  %xmm7,%xmm1
  movsd  0x30(%rsp),%xmm6
  mulsd  %xmm6,%xmm1
  movapd %xmm0,%xmm9
  divsd  0x90(%rsp),%xmm9
  mulsd  %xmm9,%xmm1
  movapd %xmm1,%xmm3
  movsd  0x88(%rsp),%xmm5
  mulsd  %xmm5,%xmm3
  movsd  %xmm3,0x30(%rsp)
  movapd %xmm5,%xmm1
  mulsd  %xmm0,%xmm1
  movsd  D53(%rip),%xmm4
  subsd  %xmm1,%xmm4
  movsd  %xmm4,0x88(%rsp)
  mulsd  %xmm4,%xmm4
  movsd  %xmm4,0x90(%rsp)
  xorpd  D27(%rip),%xmm6
  movapd %xmm6,%xmm1
  movapd %xmm7,%xmm2
  subsd  D53(%rip),%xmm2
  mulsd  %xmm2,%xmm1
  mulsd  0x80(%rsp),%xmm1
  mulsd  %xmm0,%xmm1
  mulsd  %xmm3,%xmm5
  subsd  %xmm5,%xmm1
  movsd  %xmm1,0x80(%rsp)
  movq   %r15,%xmm1
  mulsd  %xmm0,%xmm1
  movq   %r14,%xmm5
  addsd  %xmm1,%xmm5
  movsd  %xmm5,0x28(%rsp)
  movq   %r15,%xmm5
  mulsd  %xmm3,%xmm5
  movq   %xmm5,%r14
  pxor   %xmm1,%xmm1
  ucomisd %xmm0,%xmm1
  ja     L325
  sqrtsd %xmm0,%xmm0
L63:
  movsd  0x90(%rsp),%xmm5
  movapd %xmm5,%xmm4
  mulsd  %xmm0,%xmm4
  movq   %xmm4,%r15
  movsd  D66(%rip),%xmm1
  divsd  %xmm0,%xmm1
  mulsd  0x30(%rsp),%xmm1
  mulsd  %xmm5,%xmm1
  addsd  %xmm0,%xmm0
  mulsd  0x88(%rsp),%xmm0
  mulsd  0x80(%rsp),%xmm0
  addsd  %xmm0,%xmm1
  movsd  %xmm1,0x30(%rsp)
  jmp    L299
L325:
  call   <sqrt@plt>
  jmp    L63
L190:
  add    $0x1,%rbx
  add    0x40(%rsp),%ebp
  cmp    %ebx,0x44(%rsp)
  jle    L100
L324:
  mov    0x50(%rsp),%rax
  movsd  (%rax,%rbx,8),%xmm4
  movsd  %xmm4,0x18(%rsp)
  mov    (%r12),%r14
  mov    0x48(%rsp),%rax
  mov    (%rax),%r15
  pxor   %xmm0,%xmm0
  comisd %xmm4,%xmm0
  ja     L284
  movq   %r14,%xmm4
  movq   %r15,%xmm5
  addsd  %xmm5,%xmm4
  movsd  %xmm4,0x28(%rsp)
  movsd  %xmm0,0x30(%rsp)
  mov    D53(%rip),%r15
  movq   %xmm0,%r14
L299:
  movsd  0x18(%rsp),%xmm0
  mulsd  0x20(%rsp),%xmm0
  call   <exp@plt>
  mulsd  0x8(%rsp),%xmm0
  movsd  0x28(%rsp),%xmm5
  movapd %xmm5,%xmm1
  mulsd  %xmm0,%xmm1
  mov    0x58(%rsp),%rax
  movsd  %xmm1,(%rax,%rbx,8)
  movq   %r14,%xmm1
  mulsd  %xmm0,%xmm1
  mulsd  0x20(%rsp),%xmm0
  mulsd  %xmm5,%xmm0
  subsd  %xmm1,%xmm0
  mov    0x60(%rsp),%rax
  movsd  %xmm0,(%rax,%rbx,8)
  mov    0x120(%rsp),%rax
  mov    (%rax),%r14d
  lea    0x0(%rbp,%r14,1),%eax
  cltq
  mov    0x1d8(%rsp),%rdi
  mov    %r15,(%rdi,%rax,8)
  movsd  0x30(%rsp),%xmm0
  xorpd  D27(%rip),%xmm0
  movsd  %xmm0,0x0(%r13,%rax,8)
  cmpl   $0x0,0x68(%rsp)
  je     L190
  mov    0x74(%rsp),%eax
  add    %r14d,%eax
  cltq
  shl    $0x3,%rax
  mov    %rax,%rdx
  add    0x1b8(%rsp),%rdx
  mov    0x78(%rsp),%rdi
  movq   %r15,%xmm1
  mulsd  (%rdi,%rbx,8),%xmm1
  addsd  (%rdx),%xmm1
  movsd  %xmm1,(%rdx)
  add    0x1c0(%rsp),%rax
  mulsd  (%rdi,%rbx,8),%xmm0
  addsd  (%rax),%xmm0
  movsd  %xmm0,(%rax)
  jmp    L190
L116:
  mov    0x128(%rsp),%r12
  mov    0x1d8(%rsp),%r15
  mov    %r13,%rbp
  mov    0x148(%rsp),%r13
  mov    0x14(%rsp),%eax
  mov    %eax,%ebx
  mov    0x44(%rsp),%edi
  imul   %edi,%ebx
  mov    %ebx,0x50(%rsp)
  movl   $0x0,0x48(%rsp)
  movl   $0x0,0x68(%rsp)
  movl   $0x0,0x30(%rsp)
  lea    -0x1(%rdi),%ebx
  mov    %rbx,0x58(%rsp)
  mov    0x138(%rsp),%rbx
  add    $0x4,%rbx
  mov    %rbx,0x60(%rsp)
  movsd  D104(%rip),%xmm4
  mov    %eax,%r14d
  pxor   %xmm5,%xmm5
  jmp    L186
L221:
  test   %esi,%esi
  jns    L69
  jmp    L317
L199:
  movslq %edx,%rcx
  movq   $0x0,(%r15,%rcx,8)
  movq   $0x0,0x0(%rbp,%rcx,8)
L53:
  add    $0x1,%rax
  add    $0x1,%edx
  cmp    %eax,(%rdi)
  jle    L348
L211:
  cmp    %esi,(%r12,%rax,4)
  jne    L199
  movslq %edx,%rcx
  movsd  0x8(%rsp),%xmm8
  movapd %xmm8,%xmm0
  mulsd  %xmm2,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,(%r15,%rcx,8)
  movapd %xmm8,%xmm0
  mulsd  %xmm3,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,0x0(%rbp,%rcx,8)
  jmp    L53
L348:
  add    $0x1,%rsi
  add    $0x4,%r8
  cmp    %r14,%rsi
  je     L200
L386:
  movapd %xmm7,%xmm0
  mulsd  0x0(%r13,%rsi,8),%xmm0
  movsd  %xmm0,(%r11,%rsi,8)
  movapd %xmm6,%xmm0
  mulsd  0x0(%r13,%rsi,8),%xmm0
  movsd  %xmm0,(%r9,%rsi,8)
  mov    %r8,%rdi
  mov    -0x4(%r8),%edx
  cmp    (%r8),%edx
  jge    L348
  movslq %edx,%rax
  add    %r10d,%edx
  jmp    L211
L200:
  add    $0x4,%rbx
  add    0x40(%rsp),%r10d
  mov    0x14(%rsp),%edi
  add    %edi,0x18(%rsp)
  cmp    0x28(%rsp),%rbx
  je     L134
L81:
  mov    (%rbx),%eax
  mov    0x20(%rsp),%rdi
  movsd  (%rdi),%xmm2
  lea    (%rax,%rax,1),%edi
  movslq %edi,%rdi
  mov    0x130(%rsp),%rsi
  mov    0x4(%rsi,%rdi,4),%esi
  movapd %xmm2,%xmm0
  test   %esi,%esi
  js     L182
  movslq %esi,%rdx
  mov    0x140(%rsp),%rcx
  movslq (%rcx,%rdx,4),%rdx
  mov    0x170(%rsp),%rcx
  movsd  (%rcx,%rdx,8),%xmm0
L182:
  movapd %xmm2,%xmm1
  addsd  %xmm2,%xmm1
  mulsd  %xmm0,%xmm1
  addsd  %xmm2,%xmm0
  addsd  %xmm4,%xmm0
  divsd  %xmm0,%xmm1
  mov    0x14(%rsp),%r11d
  test   %r11d,%r11d
  jle    L317
  movsd  0x38(%rsp),%xmm7
  mulsd  %xmm1,%xmm7
  movsd  0x8(%rsp),%xmm6
  mulsd  %xmm1,%xmm6
  movslq 0x18(%rsp),%rdx
  mov    0x180(%rsp),%rcx
  lea    (%rcx,%rdx,8),%rcx
  imul   0x70(%rsp),%eax
  imul   %r11d,%eax
  cltq
  mov    0x188(%rsp),%rdx
  lea    (%rdx,%rax,8),%rdx
  mov    $0x0,%eax
  pxor   %xmm2,%xmm2
L212:
  movapd %xmm7,%xmm0
  mulsd  0x0(%r13,%rax,8),%xmm0
  movapd %xmm6,%xmm3
  mulsd  (%rcx,%rax,8),%xmm3
  subsd  %xmm3,%xmm0
  mulsd  (%rdx,%rax,8),%xmm0
  addsd  %xmm0,%xmm2
  add    $0x1,%rax
  cmp    %r14,%rax
  jne    L212
  comisd %xmm5,%xmm2
  jb     L221
L317:
  mov    0x130(%rsp),%rax
  mov    (%rax,%rdi,4),%esi
L69:
  mov    0x120(%rsp),%rax
  mov    (%rax),%edx
  lea    (%r10,%rdx,1),%eax
  cltq
  movsd  (%r15,%rax,8),%xmm2
  movsd  0x0(%rbp,%rax,8),%xmm3
  cmpl   $0x0,0x6c(%rsp)
  jle    L3
  imul   0x40(%rsp),%esi
  add    %edx,%esi
  movslq %esi,%rax
  mov    0x1b8(%rsp),%rdi
  movsd  (%rdi,%rax,8),%xmm2
L3:
  cmpl   $0x0,0x14(%rsp)
  jle    L200
  movsd  0x38(%rsp),%xmm6
  movapd %xmm6,%xmm7
  mulsd  %xmm2,%xmm7
  mulsd  %xmm1,%xmm7
  mulsd  %xmm3,%xmm6
  mulsd  %xmm1,%xmm6
  mov    0x120(%rsp),%rax
  lea    0x4(%rax),%r8
  movslq 0x18(%rsp),%r9
  shl    $0x3,%r9
  mov    %r9,%r11
  add    0x1c8(%rsp),%r11
  add    0x1d0(%rsp),%r9
  mov    $0x0,%esi
  jmp    L386
L134:
  addq   $0x4,0x98(%rsp)
  mov    0x98(%rsp),%rax
  mov    0xd8(%rsp),%edi
  add    %edi,0x30(%rsp)
  mov    0x50(%rsp),%edi
  add    %edi,0x68(%rsp)
  mov    0x44(%rsp),%edi
  add    %edi,0x48(%rsp)
  cmp    0xd0(%rsp),%rax
  je     L314
L186:
  mov    0x98(%rsp),%rax
  mov    (%rax),%eax
  cmpl   $0x0,0x44(%rsp)
  jle    L134
  cltq
  mov    0x170(%rsp),%rbx
  lea    (%rbx,%rax,8),%rax
  mov    %rax,0x20(%rsp)
  movslq 0x48(%rsp),%rax
  mov    0x138(%rsp),%rbx
  lea    (%rbx,%rax,4),%rbx
  add    0x58(%rsp),%rax
  mov    0x60(%rsp),%rdi
  lea    (%rdi,%rax,4),%rax
  mov    %rax,0x28(%rsp)
  mov    0x68(%rsp),%eax
  mov    %eax,0x18(%rsp)
  mov    0x30(%rsp),%r10d
  jmp    L81
L139:
  cmpl   $0x0,0x68(%rsp)
  je     L240
  movslq 0xbc(%rsp),%rax
  mov    0x1b8(%rsp),%rbx
  movq   $0x0,(%rbx,%rax,8)
  mov    0x1c0(%rsp),%rbx
  movq   $0x0,(%rbx,%rax,8)
  pxor   %xmm4,%xmm4
  movsd  %xmm4,0xc0(%rsp)
L100:
  cmpl   $0x0,0x68(%rsp)
  je     L240
  mov    0xb8(%rsp),%eax
  add    %r14d,%eax
  cltq
  shl    $0x3,%rax
  mov    %rax,%rdx
  add    0x1b8(%rsp),%rdx
  movsd  (%rdx),%xmm0
  movsd  0xc0(%rsp),%xmm5
  divsd  %xmm5,%xmm0
  movsd  %xmm0,(%rdx)
  add    0x1c0(%rsp),%rax
  movsd  (%rax),%xmm0
  divsd  %xmm5,%xmm0
  movsd  %xmm0,(%rax)
L240:
  addq   $0x4,0xa0(%rsp)
  mov    0xa0(%rsp),%rax
  mov    0x40(%rsp),%edi
  add    %edi,0xb8(%rsp)
  mov    0xdc(%rsp),%edi
  add    %edi,0xbc(%rsp)
  mov    0x44(%rsp),%edi
  add    %edi,0xc8(%rsp)
  mov    0xd8(%rsp),%edi
  add    %edi,0xcc(%rsp)
  cmp    0xd0(%rsp),%rax
  je     L116
L281:
  mov    0xa0(%rsp),%rax
  mov    (%rax),%ecx
  mov    0x44(%rsp),%ebx
  test   %ebx,%ebx
  jle    L139
  movslq 0xc8(%rsp),%rsi
  mov    0x190(%rsp),%rax
  lea    (%rax,%rsi,8),%rax
  lea    -0x1(%rbx),%edx
  add    %rsi,%rdx
  mov    0x190(%rsp),%rbx
  lea    0x8(%rbx,%rdx,8),%rdx
  pxor   %xmm0,%xmm0
L193:
  addsd  (%rax),%xmm0
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L193
  movsd  %xmm0,0xc0(%rsp)
  cmpl   $0x0,0x68(%rsp)
  jne    L130
L293:
  movslq %ecx,%rax
  shl    $0x3,%rax
  mov    %rax,%rbx
  add    0x158(%rsp),%rbx
  mov    %rbx,0xa8(%rsp)
  mov    %rax,%r12
  add    0x160(%rsp),%r12
  mov    %rax,%rbx
  add    0x168(%rsp),%rbx
  mov    %rbx,0x48(%rsp)
  add    0x150(%rsp),%rax
  mov    %rax,0xb0(%rsp)
  mov    0xb8(%rsp),%eax
  mov    %eax,0x74(%rsp)
  movslq 0xc8(%rsp),%rax
  shl    $0x3,%rax
  mov    %rax,%rbx
  add    0x178(%rsp),%rbx
  mov    %rbx,0x50(%rsp)
  mov    %rax,%rbx
  add    0x198(%rsp),%rbx
  mov    %rbx,0x58(%rsp)
  mov    %rax,%rbx
  add    0x1a0(%rsp),%rbx
  mov    %rbx,0x60(%rsp)
  add    0x190(%rsp),%rax
  mov    %rax,0x78(%rsp)
  mov    0xcc(%rsp),%ebp
  mov    $0x0,%ebx
  jmp    L324
L130:
  movslq 0xbc(%rsp),%rax
  mov    0x1b8(%rsp),%rbx
  movq   $0x0,(%rbx,%rax,8)
  mov    0x1c0(%rsp),%rbx
  movq   $0x0,(%rbx,%rax,8)
  jmp    L293
L314:
  add    $0xe8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: read_data
arguments: data_tag: D27
datatype: f32[4]
name: read_data
arguments: data_tag: D49
datatype: f64
name: read_data
arguments: data_tag: D53
datatype: f64
name: read_data
arguments: data_tag: D66
datatype: f64
name: read_data
arguments: data_tag: D104
datatype: byte[8]

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

tool: D49: 2

tool: D53: 1

tool: D66: 0.5

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

assistant: ```c
void conservativeHeadRichardsMualemVanGenuchtenHetEvaluateV2withUpwindAndHarm_sd(const int upwindFlag, const int computeAverages, const int nSimplex, const int nPointsPerSimplex, const int nSpace, const int nQuadraturePoints_elementBoundary, const int *rowptr, const int *colind, 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, J, nnz;
  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;
  nnz = rowptr[nSpace];
  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;
      J = rowptr[0];
      a[i * nPointsPerSimplex * nnz + j * nnz + J] = KWr;
      da[i * nPointsPerSimplex * nnz + j * nnz + J] = -DKWr_DpsiC;
      if (computeAverages) {
        a_avg[i * nnz + J] += KWr * dV[k];
        da_avg[i * nnz + J] += -DKWr_DpsiC * dV[k];
      }
    }
    if (computeAverages) {
      a_avg[i * nnz + J] /= vol;
      da_avg[i * nnz + J] /= 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];
      J = rowptr[0];
      krw_val = a[i * nPointsPerSimplex * nnz + j * nnz + J];
      dkrw_val = da[i * nPointsPerSimplex * nnz + j * nnz + J];
      if (upwindFlag > 0) {
        krw_val = a_avg[eN_upwind * nnz + J];
      }
      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];
        for (J = rowptr[I]; J < rowptr[I + 1]; J++) {
          if (colind[J] == I) {
            a[i * nPointsPerSimplex * nnz + j * nnz + J] = rho * krw_val * KWs_harm;
            da[i * nPointsPerSimplex * nnz + j * nnz + J] = rho * dkrw_val * KWs_harm;
          } else {
            a[i * nPointsPerSimplex * nnz + j * nnz + J] = 0.0;
            da[i * nPointsPerSimplex * nnz + j * nnz + J] = 0.0;
          }
        }
      }
    }
  }
}
```