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

```asm
<ArrayswapLog>:
  endbr64
  push   %r15
  movswl %dx,%r10d
  mov    %r9,%r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,0x18(%rsp)
  mov    %rsi,0x28(%rsp)
  mov    %edx,0x10(%rsp)
  mov    %ecx,0x40(%rsp)
  mov    %r8,0x8(%rsp)
  test   %r10d,%r10d
  jle    L157
  movswl %cx,%eax
  xor    %r8d,%r8d
  xor    %ebp,%ebp
  mov    $0xffffffff,%r12d
  mov    %eax,%edx
  lea    -0x1(%rax),%ebx
  pxor   %xmm4,%xmm4
  mov    %eax,%r9d
  shr    $0x3,%edx
  and    $0xfffffff8,%r9d
  sub    $0x1,%edx
  mov    %r9d,%ecx
  add    $0x1,%rdx
  lea    (%rcx,%rcx,1),%r13
  mov    %ebx,%ecx
  shl    $0x4,%rdx
  lea    0x2(%rcx,%rcx,1),%r11
  mov    %rdx,%rdi
  cs nopw 0x0(%rax,%rax,1)
L59:
  test   %eax,%eax
  jle    L175
  cmp    $0x6,%ebx
  jbe    L1
  movd   %r12d,%xmm3
  movd   %ebp,%xmm2
  lea    (%rdi,%rsi,1),%rcx
  mov    %rsi,%rdx
  punpcklwd %xmm3,%xmm3
  punpcklwd %xmm2,%xmm2
  pshufd $0x0,%xmm3,%xmm3
  pshufd $0x0,%xmm2,%xmm2
  nopl   0x0(%rax,%rax,1)
L161:
  movdqu (%rdx),%xmm1
  add    $0x10,%rdx
  movdqa %xmm1,%xmm0
  psubusw %xmm2,%xmm0
  paddw  %xmm0,%xmm2
  movdqa %xmm1,%xmm0
  psubusw %xmm3,%xmm0
  pcmpeqw %xmm4,%xmm0
  pand   %xmm0,%xmm1
  pandn  %xmm3,%xmm0
  movdqa %xmm0,%xmm3
  por    %xmm1,%xmm3
  cmp    %rcx,%rdx
  jne    L161
  movdqa %xmm3,%xmm0
  lea    (%rsi,%r13,1),%rcx
  psrldq $0x8,%xmm0
  movdqa %xmm0,%xmm1
  psubusw %xmm3,%xmm1
  pcmpeqw %xmm4,%xmm1
  pand   %xmm1,%xmm0
  pandn  %xmm3,%xmm1
  por    %xmm0,%xmm1
  movdqa %xmm1,%xmm3
  psrldq $0x4,%xmm3
  movdqa %xmm3,%xmm0
  psubusw %xmm1,%xmm0
  pcmpeqw %xmm4,%xmm0
  pand   %xmm0,%xmm3
  pandn  %xmm1,%xmm0
  por    %xmm3,%xmm0
  movdqa %xmm0,%xmm3
  psrldq $0x2,%xmm3
  movdqa %xmm3,%xmm1
  psubusw %xmm0,%xmm1
  pcmpeqw %xmm4,%xmm1
  pand   %xmm1,%xmm3
  pandn  %xmm0,%xmm1
  por    %xmm3,%xmm1
  pextrw $0x0,%xmm1,%r12d
  movdqa %xmm2,%xmm1
  psrldq $0x8,%xmm1
  psubusw %xmm2,%xmm1
  paddw  %xmm2,%xmm1
  movdqa %xmm1,%xmm0
  psrldq $0x4,%xmm0
  psubusw %xmm1,%xmm0
  paddw  %xmm1,%xmm0
  movdqa %xmm0,%xmm1
  psrldq $0x2,%xmm1
  psubusw %xmm0,%xmm1
  paddw  %xmm0,%xmm1
  pextrw $0x0,%xmm1,%ebp
  cmp    %eax,%r9d
  je     L138
  mov    %r9d,%edx
L73:
  movzwl (%rcx),%r14d
  cmp    %r14w,%bp
  cmovb  %r14d,%ebp
  cmp    %r14w,%r12w
  cmova  %r14d,%r12d
  lea    0x1(%rdx),%r14d
  cmp    %eax,%r14d
  jge    L138
  movzwl 0x2(%rcx),%r14d
  cmp    %r14w,%bp
  cmovb  %r14d,%ebp
  cmp    %r14w,%r12w
  cmova  %r14d,%r12d
  lea    0x2(%rdx),%r14d
  cmp    %r14d,%eax
  jle    L138
  movzwl 0x4(%rcx),%r14d
  cmp    %r14w,%bp
  cmovb  %r14d,%ebp
  cmp    %r14w,%r12w
  cmova  %r14d,%r12d
  lea    0x3(%rdx),%r14d
  cmp    %r14d,%eax
  jle    L138
  movzwl 0x6(%rcx),%r14d
  cmp    %r14w,%bp
  cmovb  %r14d,%ebp
  cmp    %r14w,%r12w
  cmova  %r14d,%r12d
  lea    0x4(%rdx),%r14d
  cmp    %r14d,%eax
  jle    L138
  movzwl 0x8(%rcx),%r14d
  cmp    %r14w,%bp
  cmovb  %r14d,%ebp
  cmp    %r14w,%r12w
  cmova  %r14d,%r12d
  lea    0x5(%rdx),%r14d
  cmp    %r14d,%eax
  jle    L138
  movzwl 0xa(%rcx),%r14d
  cmp    %r14w,%bp
  cmovb  %r14d,%ebp
  cmp    %r14w,%r12w
  cmova  %r14d,%r12d
  add    $0x6,%edx
  cmp    %edx,%eax
  jle    L138
  movzwl 0xc(%rcx),%edx
  cmp    %dx,%bp
  cmovb  %edx,%ebp
  cmp    %dx,%r12w
  cmova  %edx,%r12d
L138:
  add    %r11,%rsi
L175:
  add    $0x1,%r8d
  cmp    %r10d,%r8d
  jne    L59
  movzwl %bp,%ebp
  movzwl %r12w,%r12d
L52:
  mov    %ebp,%edx
  mov    %r12d,%esi
  lea    D5(%rip),%rdi
  call   <printf@plt>
  mov    0x40(%rsp),%esi
  mov    0x18(%rsp),%r11
  mov    0x10(%rsp),%ebx
  movswq %si,%rdx
  lea    (%r11,%rdx,1),%rax
  mov    %rax,0x20(%rsp)
  mov    %ebx,%eax
  shr    $0xf,%ax
  add    %ebx,%eax
  sar    %ax
  mov    %eax,%ecx
  cmp    $0x1,%bx
  jle    L178
  mov    %esi,%eax
  shr    $0xf,%ax
  add    %esi,%eax
  sar    %ax
  cmp    $0x1,%si
  jle    L178
  movswl %ax,%esi
  add    $0x1,%ecx
  movl   $0x1,0x40(%rsp)
  mov    %rsi,%rax
  lea    (%rsi,%rsi,1),%rdi
  movswl %cx,%ecx
  sub    $0x1,%eax
  lea    (%rdx,%rdi,1),%rbx
  mov    %ecx,0x44(%rsp)
  add    %r11,%rdi
  lea    0x0(,%rsi,8),%rcx
  lea    0x2(%rdx,%rax,2),%rax
  mov    %rbx,0x38(%rsp)
  mov    %rdi,0x10(%rsp)
  mov    %rcx,0x30(%rsp)
  mov    %rax,0x48(%rsp)
  xchg   %ax,%ax
L166:
  mov    0x28(%rsp),%rbx
  mov    0x20(%rsp),%r13
  mov    0x18(%rsp),%r14
  nop
L53:
  xor    %edi,%edi
  cmp    %r14,0x8(%rsp)
  seta   %dil
  call   <assert@plt>
  xor    %edi,%edi
  cmp    %rbx,%r15
  seta   %dil
  call   <assert@plt>
  movzwl (%rbx),%edi
  mov    %ebp,%edx
  mov    %r12d,%esi
  call   <mylog@plt>
  xor    %edi,%edi
  cmp    %r13,0x8(%rsp)
  mov    %al,(%r14)
  seta   %dil
  call   <assert@plt>
  lea    0x2(%rbx),%rax
  xor    %edi,%edi
  cmp    %rax,%r15
  seta   %dil
  call   <assert@plt>
  movzwl 0x2(%rbx),%edi
  mov    %ebp,%edx
  mov    %r12d,%esi
  call   <mylog@plt>
  xor    %edi,%edi
  mov    %al,0x0(%r13)
  lea    0x1(%r13),%rax
  cmp    %rax,0x8(%rsp)
  seta   %dil
  call   <assert@plt>
  lea    0x4(%rbx),%rax
  xor    %edi,%edi
  cmp    %rax,%r15
  seta   %dil
  add    $0x2,%r13
  call   <assert@plt>
  movzwl 0x4(%rbx),%edi
  mov    %ebp,%edx
  mov    %r12d,%esi
  call   <mylog@plt>
  xor    %edi,%edi
  mov    %al,-0x1(%r13)
  lea    0x1(%r14),%rax
  cmp    %rax,0x8(%rsp)
  seta   %dil
  call   <assert@plt>
  lea    0x6(%rbx),%rax
  xor    %edi,%edi
  cmp    %rax,%r15
  seta   %dil
  add    $0x8,%rbx
  add    $0x2,%r14
  call   <assert@plt>
  movzwl -0x2(%rbx),%edi
  mov    %ebp,%edx
  mov    %r12d,%esi
  call   <mylog@plt>
  mov    %al,-0x1(%r14)
  cmp    0x10(%rsp),%r14
  jne    L53
  mov    0x30(%rsp),%rsi
  addl   $0x1,0x40(%rsp)
  add    %rsi,0x28(%rsp)
  mov    0x40(%rsp),%eax
  mov    0x48(%rsp),%rsi
  add    %rsi,0x18(%rsp)
  add    %rsi,0x20(%rsp)
  mov    0x38(%rsp),%rsi
  add    %rsi,0x10(%rsp)
  cmp    0x44(%rsp),%eax
  jne    L166
L178:
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L1:
  mov    %rsi,%rcx
  xor    %edx,%edx
  jmp    L73
L157:
  mov    $0xffff,%r12d
  xor    %ebp,%ebp
  jmp    L52
```

tool_calls: name: parse_data
arguments: label: D5
data_type: string

tool: D5: MinPix %d, MaxPix %d


assistant: ```c
void ArrayswapLog(unsigned char *Imptr1, unsigned short *Imptr2, short height, short width, unsigned char *end1, unsigned short *end2) {
  unsigned short *srcPix, minPix, maxPix;
  int x, y, z;
  double scale;
  unsigned char *Impt1, *Impt2;
  unsigned short *Impt5;
  minPix = 0xFFFF;
  maxPix = 0x0000;
  srcPix = Imptr2;
  for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++, srcPix++) {
      if (*srcPix > maxPix)
        maxPix = *srcPix;
      if (*srcPix < minPix)
        minPix = *srcPix;
    }
  }
  if (maxPix == minPix)
    scale = 0.0;
  else
    scale = 255.0 / (maxPix - minPix);
  printf("MinPix %d, MaxPix %d\n", minPix, maxPix);
  Impt1 = Imptr1;
  Impt2 = Imptr1 + width;
  Impt5 = Imptr2;
  for (y = 1; y <= height / 2; y++) {
    for (z = 1; z <= width / 2; z++) {
      assert(Impt1 < end1);
      assert(Impt5 < end2);
      *Impt1++ = mylog(*Impt5++, minPix, maxPix);
      assert(Impt2 < end1);
      assert(Impt5 < end2);
      *Impt2++ = mylog(*Impt5++, minPix, maxPix);
      assert(Impt2 < end1);
      assert(Impt5 < end2);
      *Impt2++ = mylog(*Impt5++, minPix, maxPix);
      assert(Impt1 < end1);
      assert(Impt5 < end2);
      *Impt1++ = mylog(*Impt5++, minPix, maxPix);
    };
    Impt1 += width;
    Impt2 += width;
  }
}
```