user: 请从给定的汇编指令推导出C源代码:

```asm
<check_resid>:
  endbr64
  push   %r15
  lea    (%rdi,%rsi,1),%eax
  push   %r14
  mov    %r9,%r14
  push   %r13
  mov    %edi,%r13d
  push   %r12
  push   %rbp
  movslq %eax,%rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %esi,0x4(%rsp)
  mov    0x70(%rsp),%r12
  mov    %rdx,0x8(%rsp)
  mov    %rcx,0x10(%rsp)
  mov    %r8,0x18(%rsp)
  mov    %eax,0x20(%rsp)
  test   %eax,%eax
  jle    L85
  xor    %r15d,%r15d
  mov    %edi,0x24(%rsp)
  mov    0x8(%rsp),%r13
  lea    D6(%rip),%rbx
  mov    %r12,0x28(%rsp)
  mov    %r15,%r12
  mov    0x10(%rsp),%r15
  xchg   %ax,%ax
L363:
  mov    (%r15,%r12,4),%edx
  mov    0x0(%r13,%r12,4),%ecx
  mov    %r12d,%esi
  test   %edx,%edx
  js     L133
  cmp    %ecx,%edx
  jle    L256
L133:
  mov    %rbx,%rdi
  xor    %eax,%eax
  call   <printf@plt>
L256:
  add    $0x1,%r12
  cmp    %rbp,%r12
  jne    L363
  mov    0x24(%rsp),%r13d
  mov    0x28(%rsp),%r12
L85:
  test   %r13d,%r13d
  jle    L209
  lea    -0x1(%r13),%eax
  cmp    $0x2,%eax
  jbe    L320
  mov    %r13d,%edx
  mov    0x8(%rsp),%rcx
  mov    0x10(%rsp),%rsi
  xor    %eax,%eax
  shr    $0x2,%edx
  pxor   %xmm1,%xmm1
  shl    $0x4,%rdx
  nopl   0x0(%rax)
L200:
  movdqu (%rcx,%rax,1),%xmm0
  movdqu (%rsi,%rax,1),%xmm2
  add    $0x10,%rax
  psubd  %xmm2,%xmm0
  paddd  %xmm0,%xmm1
  cmp    %rdx,%rax
  jne    L200
  movdqa %xmm1,%xmm0
  mov    %r13d,%eax
  psrldq $0x8,%xmm0
  and    $0xfffffffc,%eax
  paddd  %xmm0,%xmm1
  movdqa %xmm1,%xmm0
  psrldq $0x4,%xmm0
  paddd  %xmm0,%xmm1
  movd   %xmm1,%esi
  test   $0x3,%r13b
  je     L75
L151:
  mov    0x8(%rsp),%rdi
  mov    0x10(%rsp),%rbx
  movslq %eax,%rcx
  lea    0x0(,%rcx,4),%rdx
  add    (%rdi,%rcx,4),%esi
  sub    (%rbx,%rcx,4),%esi
  lea    0x1(%rax),%ecx
  cmp    %r13d,%ecx
  jge    L75
  add    $0x2,%eax
  add    0x4(%rdi,%rdx,1),%esi
  sub    0x4(%rbx,%rdx,1),%esi
  cmp    %r13d,%eax
  jge    L75
  add    0x8(%rdi,%rdx,1),%esi
  sub    0x8(%rbx,%rdx,1),%esi
L75:
  cmp    0x20(%rsp),%r13d
  jge    L195
L147:
  mov    0x4(%rsp),%eax
  cmp    0x20(%rsp),%r13d
  mov    $0x1,%edi
  cmovl  %eax,%edi
  sub    $0x1,%eax
  cmp    $0x2,%eax
  jbe    L55
  mov    0x8(%rsp),%rax
  movslq %r13d,%rdx
  mov    %edi,%ecx
  pxor   %xmm1,%xmm1
  shl    $0x2,%rdx
  shr    $0x2,%ecx
  lea    (%rax,%rdx,1),%r8
  shl    $0x4,%rcx
  add    0x10(%rsp),%rdx
  xor    %eax,%eax
  nopl   0x0(%rax)
L57:
  movdqu (%r8,%rax,1),%xmm0
  movdqu (%rdx,%rax,1),%xmm3
  add    $0x10,%rax
  psubd  %xmm3,%xmm0
  paddd  %xmm0,%xmm1
  cmp    %rax,%rcx
  jne    L57
  movdqa %xmm1,%xmm0
  mov    %edi,%ecx
  psrldq $0x8,%xmm0
  and    $0xfffffffc,%ecx
  paddd  %xmm0,%xmm1
  lea    (%rcx,%r13,1),%eax
  movdqa %xmm1,%xmm0
  psrldq $0x4,%xmm0
  paddd  %xmm0,%xmm1
  movd   %xmm1,%edx
  cmp    %ecx,%edi
  je     L29
L73:
  mov    0x8(%rsp),%rbx
  mov    0x10(%rsp),%r10
  movslq %eax,%rdi
  mov    0x20(%rsp),%r11d
  lea    0x0(,%rdi,4),%rcx
  add    (%rbx,%rdi,4),%edx
  sub    (%r10,%rdi,4),%edx
  lea    0x1(%rax),%edi
  cmp    %r11d,%edi
  jge    L29
  add    $0x2,%eax
  add    0x4(%rbx,%rcx,1),%edx
  sub    0x4(%r10,%rcx,1),%edx
  cmp    %r11d,%eax
  jge    L29
  add    0x8(%rbx,%rcx,1),%edx
  sub    0x8(%r10,%rcx,1),%edx
L29:
  cmp    %edx,%esi
  jne    L143
L38:
  mov    0x20(%rsp),%ebx
  lea    0x0(,%rbx,4),%edi
  call   <smalloc@plt>
  mov    %rax,%r15
  test   %ebx,%ebx
  jle    L6
  xor    %esi,%esi
  lea    0x0(,%rbp,4),%rdx
  mov    %rax,%rdi
  call   <memset@plt>
  cmp    %ebx,%r13d
  jge    L69
L78:
  mov    0x18(%rsp),%r8
  movslq %r13d,%rbp
  mov    %r14,%rax
  shl    $0x2,%rbp
  add    %rbp,%r8
  add    %r15,%rbp
  mov    %r8,%r14
  mov    %rax,%r8
  nopl   0x0(%rax,%rax,1)
L137:
  movslq (%r14),%rbx
  cmp    0x4(%r14),%ebx
  jge    L307
  mov    %r13d,%esi
  mov    %r8,%r13
  jmp    L123
  nopl   0x0(%rax)
L349:
  add    %ecx,0x0(%rbp)
  movslq 0x0(%r13,%rbx,4),%rax
  mov    (%r12,%rbx,4),%edx
  add    $0x1,%rbx
  add    %edx,(%r15,%rax,4)
  cmp    %ebx,0x4(%r14)
  jle    L362
L123:
  mov    (%r12,%rbx,4),%ecx
  test   %ecx,%ecx
  jns    L349
  mov    0x0(%r13,%rbx,4),%edx
  lea    D29(%rip),%rdi
  xor    %eax,%eax
  mov    %esi,0x4(%rsp)
  call   <printf@plt>
  mov    (%r12,%rbx,4),%ecx
  mov    0x4(%rsp),%esi
  jmp    L349
  nopl   0x0(%rax,%rax,1)
L362:
  mov    %r13,%r8
  mov    %esi,%r13d
L307:
  add    $0x1,%r13d
  add    $0x4,%r14
  add    $0x4,%rbp
  cmp    0x20(%rsp),%r13d
  jl     L137
  mov    0x20(%rsp),%eax
  test   %eax,%eax
  jle    L351
L69:
  mov    0x20(%rsp),%r12d
  mov    0x8(%rsp),%r13
  xor    %ebx,%ebx
  lea    D21(%rip),%rbp
  mov    0x10(%rsp),%r14
  nopl   0x0(%rax)
L146:
  mov    0x0(%r13,%rbx,4),%ecx
  mov    (%r14,%rbx,4),%r8d
  mov    %ebx,%esi
  mov    (%r15,%rbx,4),%edx
  mov    %ecx,%eax
  sub    %r8d,%eax
  cmp    %eax,%edx
  je     L115
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <printf@plt>
L115:
  add    $0x1,%rbx
  cmp    %ebx,%r12d
  jg     L146
L351:
  add    $0x38,%rsp
  mov    %r15,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1090 <sfree@plt>
L143:
  lea    D27(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L38
L209:
  xor    %esi,%esi
  cmp    0x20(%rsp),%r13d
  jl     L147
  mov    0x20(%rsp),%ebx
  lea    0x0(,%rbx,4),%edi
  call   <smalloc@plt>
  mov    %rax,%r15
  test   %ebx,%ebx
  jle    L6
  lea    0x0(,%rbp,4),%rdx
  xor    %esi,%esi
  mov    %r15,%rdi
  call   <memset@plt>
  jmp    L69
  nop
L6:
  cmp    0x20(%rsp),%r13d
  jl     L78
  jmp    L351
L195:
  xor    %edx,%edx
  jmp    L29
L320:
  xor    %esi,%esi
  xor    %eax,%eax
  jmp    L151
L55:
  mov    %r13d,%eax
  xor    %edx,%edx
  jmp    L73
```

tool_calls: name: unpack_data
arguments: data_label: D6
type_guessed: string
name: unpack_data
arguments: data_label: D29
type_guessed: string
name: unpack_data
arguments: data_label: D21
type_guessed: string
name: unpack_data
arguments: data_label: D27
type_guessed: string

tool: D6: BAD resid[%d] = %d, vweight = %d


tool: D29: Negative flow (%d,%d) = %d


tool: D21: ERROR: diff[%d] = %d, but vweight = %d and resid = %d


tool: D27: left_used = %d, NOT EQUAL TO right_resid = %d


assistant: ```c
void check_resid(int n_left, int n_right, int *vweight, int *resid, int *pointers, int *indices, int *flow) {
  int i, j, left_used, right_used;
  int *diff;
  for (i = 0; i < n_left + n_right; i++) {
    if (resid[i] < 0 || resid[i] > vweight[i]) {
      printf("BAD resid[%d] = %d, vweight = %d\n", i, resid[i], vweight[i]);
    }
  }
  left_used = right_used = 0;
  for (i = 0; i < n_left; i++) {
    left_used += vweight[i] - resid[i];
  }
  for (i = n_left; i < n_left + n_right; i++) {
    right_used += vweight[i] - resid[i];
  }
  if (left_used != right_used) {
    printf("left_used = %d, NOT EQUAL TO right_resid = %d\n", left_used, right_used);
  }
  diff = smalloc((n_left + n_right) * sizeof(int));
  for (i = 0; i < n_left + n_right; i++) {
    diff[i] = 0;
  }
  for (i = n_left; i < n_left + n_right; i++) {
    for (j = pointers[i]; j < pointers[i + 1]; j++) {
      if (flow[j] < 0) {
        printf("Negative flow (%d,%d) = %d\n", i, indices[j], flow[j]);
      }
      diff[i] += flow[j];
      diff[indices[j]] += flow[j];
    }
  }
  for (i = 0; i < n_left + n_right; i++) {
    if (diff[i] != vweight[i] - resid[i]) {
      printf("ERROR: diff[%d] = %d, but vweight = %d and resid = %d\n", i, diff[i], vweight[i], resid[i]);
    }
  }
  sfree(diff);
}
```