user: Please show me the C implementation that matches the assembly code listed below:

```asm
<Extend>:
  endbr64
  push   %r15
  mov    %edx,%eax
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %esi,%ebx
  mov    %ecx,%esi
  mov    %ebx,%r13d
  imul   %edx,%r13d
  sub    $0x48,%rsp
  mov    %ecx,0x10(%rsp)
  mov    0x80(%rsp),%ebp
  mov    %r8d,0x28(%rsp)
  test   %ecx,%ecx
  jle    L406
  lea    -0x1(%rbx),%ecx
  xor    %edx,%edx
  lea    -0x1(%rsi),%r12d
  mov    %r8d,%esi
  mov    %ecx,0x30(%rsp)
  mov    %r13d,%ecx
  sub    %ebx,%ecx
  test   %r8d,%r8d
  cmovg  %ecx,%edx
  mov    %edx,0xc(%rsp)
L534:
  test   %esi,%esi
  mov    $0xffffffff,%edi
  lea    -0x1(%rsi),%edx
  mov    0x10(%rsp),%ecx
  cmovs  %esi,%edi
  add    $0x1,%edi
  test   %esi,%esi
  cmovg  %edx,%edi
  imul   %ebx,%edi
  mov    %edi,%r15d
  test   %ecx,%ecx
  js     L288
  lea    -0x1(%rbx),%ecx
  mov    %ecx,%edx
  shr    $0x1f,%edx
  add    %ecx,%edx
  sar    %edx
  mov    %edx,0x2c(%rsp)
L482:
  mov    0x28(%rsp),%edx
  test   %edx,%edx
  js     L83
  lea    -0x1(%rax),%edx
  mov    %edx,%eax
  shr    $0x1f,%eax
  add    %edx,%eax
  sar    %eax
  mov    %eax,0x38(%rsp)
  test   %r13d,%r13d
  jle    L563
L527:
  movslq %r13d,%rdx
  mov    %r9,%rdi
  xor    %esi,%esi
  shl    $0x3,%rdx
  call   <memset@plt>
  mov    %rax,%r9
  test   %ebp,%ebp
  jne    L559
  mov    0x30(%rsp),%r11d
  mov    0xc(%rsp),%esi
  mov    %r15d,%edi
  xor    %r10d,%r10d
  mov    %r14,0x10(%rsp)
  mov    %r11d,%eax
  mov    %r13d,0x20(%rsp)
  add    %esi,%eax
  cltq
  lea    (%r9,%rax,8),%r8
  movslq %ebx,%rax
  shl    $0x3,%rax
  mov    %rax,0x18(%rsp)
  lea    (%rsi,%rbx,1),%eax
  mov    %r15d,%esi
  sub    %eax,%esi
  mov    %esi,0x24(%rsp)
  nopl   (%rax)
L401:
  add    %ebx,%ebp
  test   %edi,%edi
  js     L28
  cmp    %edi,0x20(%rsp)
  jle    L28
  cmp    %ebp,%r10d
  jge    L178
  lea    (%r11,%rdi,1),%eax
  mov    %ebp,%r14d
  mov    %r12d,%esi
  mov    0x10(%rsp),%rcx
  cltq
  sub    %r10d,%r14d
  sub    %r11d,%esi
  lea    (%r9,%rax,8),%r15
  add    %r12d,%r14d
  mov    %r12d,%eax
  jmp    L25
L585:
  lea    (%rax,%rdi,1),%edx
  add    $0x1,%eax
  add    $0x8,%rcx
  add    $0x1,%esi
  movslq %edx,%rdx
  lea    (%r9,%rdx,8),%rdx
  addsd  (%rdx),%xmm0
  movsd  %xmm0,(%rdx)
  cmp    %r14d,%eax
  je     L178
L25:
  movsd  (%rcx),%xmm0
  test   %eax,%eax
  js     L89
  cmp    %eax,%ebx
  jg     L585
L89:
  mov    %esi,%edx
  mov    %r11d,%r13d
  neg    %edx
  cmovs  %esi,%edx
  sub    %edx,%r13d
  mov    %r13d,%edx
  neg    %edx
  cmovs  %r13d,%edx
  add    $0x1,%eax
  add    $0x8,%rcx
  add    $0x1,%esi
  add    %edi,%edx
  movslq %edx,%rdx
  lea    (%r9,%rdx,8),%rdx
  movsd  (%rdx),%xmm1
  subsd  %xmm0,%xmm1
  movsd  %xmm1,(%rdx)
  movsd  -0x8(%rcx),%xmm0
  addsd  %xmm0,%xmm0
  addsd  (%r15),%xmm0
  movsd  %xmm0,(%r15)
  cmp    %r14d,%eax
  jne    L25
L178:
  mov    0x18(%rsp),%rsi
  add    %ebx,%edi
  add    %rsi,0x10(%rsp)
  add    %ebx,%r10d
  cmp    %ebp,0x20(%rsp)
  jg     L401
L62:
  add    $0x48,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L559:
  mov    %r15d,%eax
  mov    0xc(%rsp),%esi
  mov    %r12d,%ecx
  neg    %eax
  cmovns %eax,%r15d
  neg    %ecx
  mov    %esi,%r10d
  cmovs  %r12d,%ecx
  sub    %r13d,%esi
  mov    %r15d,0x18(%rsp)
  sub    %r15d,%r10d
  mov    %esi,0x20(%rsp)
  cmp    %r15d,%r13d
  jle    L419
  mov    0x30(%rsp),%r15d
  lea    (%rcx,%rcx,1),%edx
  lea    (%r15,%rcx,1),%eax
  mov    %r15d,%esi
  mov    %eax,%edi
  mov    %eax,%r11d
  sub    %ebx,%esi
  sub    %edx,%edi
  sub    %eax,%edx
  sub    $0x1,%edi
  mov    %edi,0x3c(%rsp)
  mov    0x2c(%rsp),%edi
  lea    (%rdi,%rdi,1),%ebp
  mov    %r15d,%edi
  sub    %ecx,%r15d
  sub    %ebp,%r11d
  sub    %eax,%ebp
  lea    (%rsi,%rdi,1),%eax
  mov    %r15d,0x24(%rsp)
  mov    %r11d,0x34(%rsp)
  sub    %edi,%r11d
  lea    0x1(%rdi,%rdx,1),%r15d
  add    %eax,%ebp
  mov    %r11d,%r12d
  nopw   0x0(%rax,%rax,1)
L9:
  mov    0x18(%rsp),%eax
  mov    %r10d,%r8d
  mov    0x24(%rsp),%edx
  lea    (%r10,%rax,1),%r13d
  mov    %r13d,%r11d
  neg    %r11d
  cmovs  %r13d,%r11d
  neg    %r8d
  cmovs  %r10d,%r8d
  cmp    %ecx,%ebx
  jle    L439
  nopl   0x0(%rax)
L422:
  lea    (%rdx,%rcx,1),%edi
  mov    %edi,%eax
  neg    %eax
  cmovs  %edi,%eax
  add    %r11d,%eax
  cltq
  lea    (%r9,%rax,8),%rdi
  mov    %edx,%eax
  neg    %eax
  movsd  (%rdi),%xmm0
  cmovs  %edx,%eax
  sub    $0x1,%edx
  add    %r8d,%eax
  cltq
  addsd  (%r14,%rax,8),%xmm0
  movsd  %xmm0,(%rdi)
  cmp    %esi,%edx
  jg     L422
L439:
  mov    0x10(%rsp),%eax
  test   %eax,%eax
  je     L256
  cmp    %ecx,0x2c(%rsp)
  je     L512
  cmp    %esi,0x34(%rsp)
  jle    L256
  mov    %r13d,%eax
  mov    %r10d,%r11d
  mov    0x30(%rsp),%edx
  neg    %eax
  cmovns %eax,%r13d
  neg    %r11d
  cmovs  %r10d,%r11d
  nopl   0x0(%rax,%rax,1)
L179:
  mov    %edx,%eax
  lea    (%r12,%rdx,1),%r8d
  neg    %eax
  cmovs  %edx,%eax
  add    %r13d,%eax
  cltq
  lea    (%r9,%rax,8),%rdi
  mov    %r8d,%eax
  neg    %eax
  movsd  (%rdi),%xmm0
  cmovs  %r8d,%eax
  sub    $0x1,%edx
  add    %r11d,%eax
  cltq
  subsd  (%r14,%rax,8),%xmm0
  movsd  %xmm0,(%rdi)
  cmp    %ebp,%edx
  jne    L179
L256:
  sub    %ebx,%r10d
  cmp    0x20(%rsp),%r10d
  jg     L9
L419:
  mov    0x28(%rsp),%eax
  test   %eax,%eax
  je     L62
  mov    0x38(%rsp),%edx
  mov    0xc(%rsp),%edi
  imul   %ebx,%edx
  mov    %edi,%eax
  lea    (%rdx,%rdx,1),%esi
  sub    %esi,%eax
  mov    0x18(%rsp),%esi
  add    %esi,%eax
  cmp    %esi,%edx
  je     L210
  cmp    %eax,0x20(%rsp)
  jge    L62
  mov    0x30(%rsp),%r10d
  mov    0x10(%rsp),%ebp
  mov    0x2c(%rsp),%r8d
  mov    %r10d,%r11d
  sub    %ebx,%r11d
  test   %ebp,%ebp
  setne  %sil
  cmp    %ecx,%r8d
  setne  %dl
  sub    %eax,%edi
  and    %edx,%esi
  lea    (%r8,%r8,1),%edx
  mov    %edi,0x10(%rsp)
  mov    %r10d,%r8d
  mov    %esi,%r15d
  lea    (%r10,%rcx,1),%esi
  sub    %ecx,%r10d
  mov    %esi,%ebp
  mov    %r10d,0xc(%rsp)
  mov    %eax,%r10d
  lea    (%r11,%r8,1),%eax
  sub    %edx,%ebp
  sub    %esi,%edx
  mov    %ebp,0x18(%rsp)
  sub    %r8d,%ebp
  lea    (%rdx,%rax,1),%r13d
  mov    %ebp,%r12d
  nopl   0x0(%rax)
L479:
  mov    0x10(%rsp),%eax
  mov    %r10d,%edi
  mov    0xc(%rsp),%edx
  lea    (%rax,%r10,1),%ebp
  mov    %ebp,%r8d
  neg    %r8d
  cmovs  %ebp,%r8d
  neg    %edi
  cmovs  %r10d,%edi
  cmp    %ecx,%ebx
  jle    L269
  nopl   0x0(%rax,%rax,1)
L576:
  lea    (%rdx,%rcx,1),%esi
  mov    %esi,%eax
  neg    %eax
  cmovs  %esi,%eax
  add    %r8d,%eax
  cltq
  lea    (%r9,%rax,8),%rsi
  mov    %edx,%eax
  neg    %eax
  movsd  (%rsi),%xmm0
  cmovs  %edx,%eax
  sub    $0x1,%edx
  add    %edi,%eax
  cltq
  subsd  (%r14,%rax,8),%xmm0
  movsd  %xmm0,(%rsi)
  cmp    %r11d,%edx
  jg     L576
L269:
  test   %r15b,%r15b
  jne    L546
L378:
  sub    %ebx,%r10d
  cmp    0x20(%rsp),%r10d
  jg     L479
  jmp    L62
  nopl   0x0(%rax)
L28:
  cmp    %ebp,%r10d
  jge    L178
  mov    0x24(%rsp),%eax
  mov    %ebp,%r14d
  mov    %r12d,%esi
  add    %ebp,%eax
  mov    %eax,%edx
  neg    %edx
  cmovs  %eax,%edx
  mov    0xc(%rsp),%eax
  sub    %edx,%eax
  mov    0x10(%rsp),%rdx
  mov    %eax,%r15d
  neg    %r15d
  cmovs  %eax,%r15d
  sub    %r10d,%r14d
  sub    %r11d,%esi
  mov    %r12d,%eax
  add    %r12d,%r14d
  jmp    L126
  nopw   0x0(%rax,%rax,1)
L147:
  lea    (%r15,%rax,1),%ecx
  movslq %ecx,%rcx
  lea    (%r9,%rcx,8),%rcx
  movsd  (%rcx),%xmm0
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rcx)
  mov    0xc(%rsp),%ecx
  movsd  (%rdx),%xmm0
  add    %eax,%ecx
  addsd  %xmm0,%xmm0
  movslq %ecx,%rcx
  lea    (%r9,%rcx,8),%rcx
  addsd  (%rcx),%xmm0
  movsd  %xmm0,(%rcx)
L32:
  add    $0x1,%eax
  add    $0x8,%rdx
  add    $0x1,%esi
  cmp    %r14d,%eax
  je     L178
L126:
  movsd  (%rdx),%xmm1
  test   %eax,%eax
  js     L245
  cmp    %eax,%ebx
  jg     L147
L245:
  mov    %esi,%ecx
  mov    %r11d,%r13d
  neg    %ecx
  cmovs  %esi,%ecx
  sub    %ecx,%r13d
  mov    %r13d,%ecx
  neg    %ecx
  cmovs  %r13d,%ecx
  add    %r15d,%ecx
  movslq %ecx,%rcx
  lea    (%r9,%rcx,8),%rcx
  movsd  (%rcx),%xmm0
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rcx)
  movsd  (%rdx),%xmm0
  addsd  %xmm0,%xmm0
  addsd  (%r8),%xmm0
  movsd  %xmm0,(%r8)
  jmp    L32
L512:
  mov    0x3c(%rsp),%r11d
  cmp    %esi,%r11d
  jle    L256
  mov    %r13d,%eax
  mov    %r10d,%r8d
  neg    %eax
  cmovns %eax,%r13d
  neg    %r8d
  cmovs  %r10d,%r8d
  nopl   0x0(%rax)
L143:
  lea    (%r15,%r11,1),%edx
  mov    %edx,%eax
  neg    %eax
  cmovs  %edx,%eax
  mov    %r11d,%edx
  add    %r13d,%eax
  cltq
  lea    (%r9,%rax,8),%rdi
  movsd  (%rdi),%xmm1
  nopl   0x0(%rax,%rax,1)
L15:
  mov    %edx,%eax
  neg    %eax
  cmovs  %edx,%eax
  sub    $0x1,%edx
  add    %r8d,%eax
  cltq
  movsd  (%r14,%rax,8),%xmm0
  addsd  %xmm0,%xmm0
  addsd  %xmm0,%xmm1
  movsd  %xmm1,(%rdi)
  cmp    %esi,%edx
  jg     L15
  sub    $0x1,%r11d
  cmp    %esi,%r11d
  jg     L143
  sub    %ebx,%r10d
  cmp    0x20(%rsp),%r10d
  jg     L9
  jmp    L419
L83:
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,0x38(%rsp)
  test   %r13d,%r13d
  jg     L527
L563:
  test   %ebp,%ebp
  je     L62
  mov    %r15d,%eax
  mov    %r12d,%ecx
  neg    %eax
  cmovns %eax,%r15d
  mov    0xc(%rsp),%eax
  neg    %ecx
  cmovs  %r12d,%ecx
  sub    %r13d,%eax
  mov    %r15d,0x18(%rsp)
  mov    %eax,0x20(%rsp)
  jmp    L419
L288:
  mov    %ebx,%edx
  shr    $0x1f,%edx
  add    %ebx,%edx
  sar    %edx
  mov    %edx,0x2c(%rsp)
  jmp    L482
L406:
  mov    0x28(%rsp),%edi
  mov    %r13d,%ecx
  xor    %edx,%edx
  mov    $0xffffffff,%r12d
  sub    %ebx,%ecx
  movl   $0x0,0x30(%rsp)
  test   %edi,%edi
  cmovg  %ecx,%edx
  test   %esi,%esi
  cmovs  %esi,%r12d
  mov    %r8d,%esi
  mov    %edx,0xc(%rsp)
  add    $0x1,%r12d
  jmp    L534
L210:
  mov    0x20(%rsp),%r11d
  sub    %ebx,%eax
  cmp    %r11d,%eax
  jle    L62
  mov    0x30(%rsp),%edi
  mov    0x10(%rsp),%r8d
  mov    %eax,0x10(%rsp)
  mov    0x2c(%rsp),%r15d
  mov    %edi,%esi
  sub    %ebx,%esi
  test   %r8d,%r8d
  setne  %bpl
  cmp    %ecx,%r15d
  sete   %dl
  and    %edx,%ebp
  lea    (%r15,%r15,1),%edx
  mov    %edi,%r15d
  lea    (%rdi,%rcx,1),%edi
  mov    %edi,%r8d
  sub    %edx,%r8d
  sub    %edi,%edx
  lea    -0x1(%r8),%r10d
  mov    %r10d,0x20(%rsp)
  mov    %r15d,%r10d
  lea    0x1(%r15,%rdx,1),%r15d
  sub    %ecx,%r10d
  mov    %r10d,%r12d
  mov    0xc(%rsp),%r10d
  mov    %r12d,0xc(%rsp)
  mov    %r11d,%r12d
  sub    %eax,%r10d
  mov    %r10d,0x18(%rsp)
L252:
  mov    0x18(%rsp),%eax
  mov    0x10(%rsp),%r13d
  add    %r13d,%eax
  mov    %eax,%r11d
  neg    %r11d
  cmovs  %eax,%r11d
  nopl   (%rax)
L190:
  mov    %r13d,%r8d
  mov    0xc(%rsp),%edx
  neg    %r8d
  cmovs  %r13d,%r8d
  cmp    %ecx,%ebx
  jle    L231
  nopw   0x0(%rax,%rax,1)
L24:
  lea    (%rdx,%rcx,1),%edi
  mov    %edi,%eax
  neg    %eax
  cmovs  %edi,%eax
  add    %r11d,%eax
  cltq
  lea    (%r9,%rax,8),%rdi
  mov    %edx,%eax
  neg    %eax
  cmovs  %edx,%eax
  sub    $0x1,%edx
  add    %r8d,%eax
  cltq
  movsd  (%r14,%rax,8),%xmm0
  addsd  %xmm0,%xmm0
  addsd  (%rdi),%xmm0
  movsd  %xmm0,(%rdi)
  cmp    %esi,%edx
  jg     L24
L231:
  test   %bpl,%bpl
  jne    L405
L212:
  sub    %ebx,%r13d
  cmp    %r12d,%r13d
  jg     L190
  sub    %ebx,0x10(%rsp)
  mov    0x10(%rsp),%eax
  cmp    %r12d,%eax
  jg     L252
  jmp    L62
  nopl   0x0(%rax,%rax,1)
L405:
  mov    0x20(%rsp),%r10d
  cmp    %esi,%r10d
  jle    L212
  mov    %r13d,%r8d
  neg    %r8d
  cmovs  %r13d,%r8d
  nopl   0x0(%rax)
L351:
  lea    (%r15,%r10,1),%edx
  mov    %edx,%eax
  neg    %eax
  cmovs  %edx,%eax
  mov    %r10d,%edx
  add    %r11d,%eax
  cltq
  lea    (%r9,%rax,8),%rdi
  movsd  (%rdi),%xmm1
  nopl   0x0(%rax,%rax,1)
L19:
  mov    %edx,%eax
  neg    %eax
  cmovs  %edx,%eax
  sub    $0x1,%edx
  add    %r8d,%eax
  cltq
  movsd  (%r14,%rax,8),%xmm0
  addsd  %xmm0,%xmm0
  addsd  %xmm0,%xmm1
  movsd  %xmm1,(%rdi)
  cmp    %esi,%edx
  jg     L19
  sub    $0x1,%r10d
  cmp    %esi,%r10d
  jg     L351
  jmp    L212
L546:
  cmp    %r11d,0x18(%rsp)
  jle    L378
  mov    %ebp,%eax
  mov    %r10d,%r8d
  mov    0x30(%rsp),%edx
  neg    %eax
  cmovns %eax,%ebp
  neg    %r8d
  cmovs  %r10d,%r8d
  nopl   0x0(%rax,%rax,1)
L431:
  mov    %edx,%eax
  lea    (%r12,%rdx,1),%edi
  neg    %eax
  cmovs  %edx,%eax
  add    %ebp,%eax
  cltq
  lea    (%r9,%rax,8),%rsi
  mov    %edi,%eax
  neg    %eax
  movsd  (%rsi),%xmm0
  cmovs  %edi,%eax
  sub    $0x1,%edx
  add    %r8d,%eax
  cltq
  subsd  (%r14,%rax,8),%xmm0
  movsd  %xmm0,(%rsi)
  cmp    %r13d,%edx
  jne    L431
  jmp    L378
```

assistant: ```c
int Extend(filt, x_dim, y_dim, x_pos, y_pos, result, r_or_e)
register double *filt, *result;
register int x_dim;
int y_dim, x_pos, y_pos, r_or_e;
{
  int filt_sz = x_dim * y_dim;
  register int y_filt, x_filt, y_res, x_res, y_tmp, x_tmp;
  register int x_base = (x_pos > 0) ? (x_dim - 1) : 0;
  register int y_base = x_dim * ((y_pos > 0) ? (y_dim - 1) : 0);
  int x_overhang = (x_pos > 0) ? (x_pos - 1) : ((x_pos < 0) ? (x_pos + 1) : 0);
  int y_overhang = x_dim * ((y_pos > 0) ? (y_pos - 1) : ((y_pos < 0) ? (y_pos + 1) : 0));
  int mx_pos = (x_pos < 0) ? (x_dim / 2) : ((x_dim - 1) / 2);
  int my_pos = x_dim * ((y_pos < 0) ? (y_dim / 2) : ((y_dim - 1) / 2));
  int i;
  for (i = 0; i < filt_sz; i++)
    result[i] = 0.0;
  if (r_or_e == 0)
    for (y_filt = 0, y_res = y_overhang; y_filt < filt_sz; y_filt += x_dim, y_res += x_dim)
      if ((y_res >= 0) && (y_res < filt_sz))
        for (x_filt = y_filt, x_res = x_overhang; x_filt < y_filt + x_dim; x_filt++, x_res++)
          if ((x_res >= 0) && (x_res < x_dim))
            result[y_res + x_res] += filt[x_filt];
          else {
            result[y_res + (((x_base - (((x_res - x_base) >= 0) ? (x_res - x_base) : (-(x_res - x_base)))) >= 0) ? (x_base - (((x_res - x_base) >= 0) ? (x_res - x_base) : (-(x_res - x_base)))) : (-(x_base - (((x_res - x_base) >= 0) ? (x_res - x_base) : (-(x_res - x_base))))))] -= filt[x_filt];
            result[y_res + x_base] += 2 * filt[x_filt];
          }
      else
        for (x_filt = y_filt, x_res = x_overhang; x_filt < y_filt + x_dim; x_filt++, x_res++)
          if ((x_res >= 0) && (x_res < x_dim)) {
            result[(((y_base - (((y_res - y_base) >= 0) ? (y_res - y_base) : (-(y_res - y_base)))) >= 0) ? (y_base - (((y_res - y_base) >= 0) ? (y_res - y_base) : (-(y_res - y_base)))) : (-(y_base - (((y_res - y_base) >= 0) ? (y_res - y_base) : (-(y_res - y_base)))))) + x_res] -= filt[x_filt];
            result[y_base + x_res] += 2 * filt[x_filt];
          } else {
            result[(((y_base - (((y_res - y_base) >= 0) ? (y_res - y_base) : (-(y_res - y_base)))) >= 0) ? (y_base - (((y_res - y_base) >= 0) ? (y_res - y_base) : (-(y_res - y_base)))) : (-(y_base - (((y_res - y_base) >= 0) ? (y_res - y_base) : (-(y_res - y_base)))))) + (((x_base - (((x_res - x_base) >= 0) ? (x_res - x_base) : (-(x_res - x_base)))) >= 0) ? (x_base - (((x_res - x_base) >= 0) ? (x_res - x_base) : (-(x_res - x_base)))) : (-(x_base - (((x_res - x_base) >= 0) ? (x_res - x_base) : (-(x_res - x_base))))))] -= filt[x_filt];
            result[y_base + x_base] += 2 * filt[x_filt];
          }
  else {
    y_overhang = (((y_overhang) >= 0) ? (y_overhang) : (-(y_overhang)));
    x_overhang = (((x_overhang) >= 0) ? (x_overhang) : (-(x_overhang)));
    for (y_res = y_base, y_filt = y_base - y_overhang; y_filt > y_base - filt_sz; y_filt -= x_dim, y_res -= x_dim) {
      for (x_res = x_base, x_filt = x_base - x_overhang; x_filt > x_base - x_dim; x_res--, x_filt--)
        result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] += filt[(((y_filt) >= 0) ? (y_filt) : (-(y_filt))) + (((x_filt) >= 0) ? (x_filt) : (-(x_filt)))];
      if (x_pos != 0)
        if (x_overhang != mx_pos)
          for (x_res = x_base, x_filt = x_base - 2 * mx_pos + x_overhang; x_filt > x_base - x_dim; x_res--, x_filt--)
            result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] -= filt[(((y_filt) >= 0) ? (y_filt) : (-(y_filt))) + (((x_filt) >= 0) ? (x_filt) : (-(x_filt)))];
        else
          for (x_res = x_base, x_filt = x_base - 2 * mx_pos + x_overhang - 1; x_filt > x_base - x_dim; x_res--, x_filt--)
            for (x_tmp = x_filt; x_tmp > x_base - x_dim; x_tmp--)
              result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] += 2 * filt[(((y_filt) >= 0) ? (y_filt) : (-(y_filt))) + (((x_tmp) >= 0) ? (x_tmp) : (-(x_tmp)))];
    }
    if (y_pos != 0)
      if (y_overhang != my_pos)
        for (y_res = y_base, y_filt = y_base - 2 * my_pos + y_overhang; y_filt > y_base - filt_sz; y_filt -= x_dim, y_res -= x_dim) {
          for (x_res = x_base, x_filt = x_base - x_overhang; x_filt > x_base - x_dim; x_res--, x_filt--)
            result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] -= filt[(((y_filt) >= 0) ? (y_filt) : (-(y_filt))) + (((x_filt) >= 0) ? (x_filt) : (-(x_filt)))];
          if ((x_pos != 0) && (x_overhang != mx_pos))
            for (x_res = x_base, x_filt = x_base - 2 * mx_pos + x_overhang; x_filt > x_base - x_dim; x_res--, x_filt--)
              result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] -= filt[(((y_filt) >= 0) ? (y_filt) : (-(y_filt))) + (((x_filt) >= 0) ? (x_filt) : (-(x_filt)))];
        }
      else
        for (y_res = y_base, y_filt = y_base - 2 * my_pos + y_overhang - x_dim; y_filt > y_base - filt_sz; y_res -= x_dim, y_filt -= x_dim)
          for (y_tmp = y_filt; y_tmp > y_base - filt_sz; y_tmp -= x_dim) {
            for (x_res = x_base, x_filt = x_base - x_overhang; x_filt > x_base - x_dim; x_res--, x_filt--)
              result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] += 2 * filt[(((y_tmp) >= 0) ? (y_tmp) : (-(y_tmp))) + (((x_filt) >= 0) ? (x_filt) : (-(x_filt)))];
            if ((x_pos != 0) && (x_overhang == mx_pos))
              for (x_res = x_base, x_filt = x_base - 2 * mx_pos + x_overhang - 1; x_filt > x_base - x_dim; x_res--, x_filt--)
                for (x_tmp = x_filt; x_tmp > x_base - x_dim; x_tmp--)
                  result[(((y_res) >= 0) ? (y_res) : (-(y_res))) + (((x_res) >= 0) ? (x_res) : (-(x_res)))] += 2 * filt[(((y_tmp) >= 0) ? (y_tmp) : (-(y_tmp))) + (((x_tmp) >= 0) ? (x_tmp) : (-(x_tmp)))];
          }
  }
  return (0);
}
```