user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<unboundedknapsack>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  lea    D16(%rip),%rbp
  push   %rbx
  mov    %rbp,%rdi
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rsi
  call   <scanf@plt>
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,0xc(%rsp)
  test   %eax,%eax
  je     L84
  lea    0x14(%rsp),%r15
  lea    0x10(%rsp),%r14
  nopl   0x0(%rax,%rax,1)
L67:
  mov    %r14,%rsi
  mov    %r15,%rdx
  lea    D29(%rip),%rdi
  xor    %eax,%eax
  call   <scanf@plt>
  mov    0x10(%rsp),%eax
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    0x10(%rsp),%esi
  mov    %rax,%rbx
  test   %esi,%esi
  jle    L86
  mov    %rax,%r13
  xor    %r12d,%r12d
  nopl   (%rax)
L129:
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  add    $0x1,%r12d
  call   <scanf@plt>
  add    $0x4,%r13
  cmp    %r12d,0x10(%rsp)
  jg     L129
L86:
  mov    0x14(%rsp),%eax
  lea    0x4(,%rax,4),%edi
  call   <malloc@plt>
  mov    $0x1,%r8d
  xor    %r9d,%r9d
  movl   $0x1,(%rax)
  mov    0x14(%rsp),%ecx
  mov    %rax,%rdi
  test   %ecx,%ecx
  jle    L2
  cs nopw 0x0(%rax,%rax,1)
L62:
  mov    0x10(%rsp),%edx
  mov    %r8d,%ecx
  mov    %rbx,%rax
  lea    (%rbx,%rdx,4),%rsi
  test   %edx,%edx
  jle    L115
  nopw   0x0(%rax,%rax,1)
L5:
  mov    %ecx,%edx
  sub    (%rax),%edx
  js     L101
  movslq %edx,%rdx
  mov    (%rdi,%rdx,4),%edx
  test   %edx,%edx
  jne    L60
L101:
  add    $0x4,%rax
  cmp    %rax,%rsi
  jne    L5
L115:
  add    $0x1,%r8
  cmp    %r8d,0x14(%rsp)
  jge    L62
L2:
  mov    %r9d,%esi
  lea    D5(%rip),%rdi
  call   <printf@plt>
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,0xc(%rsp)
  test   %eax,%eax
  jne    L67
L84:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L82
  add    $0x28,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L60:
  movl   $0x1,(%rdi,%r8,4)
  mov    %ecx,%r9d
  add    $0x1,%r8
  cmp    %r8d,0x14(%rsp)
  jge    L62
  jmp    L2
L82:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: label: D16
datatype: string
name: parse_data
arguments: label: D29
datatype: string
name: parse_data
arguments: label: D5
datatype: string

tool: D16: %d

tool: D29: %d %d

tool: D5: %d


assistant: ```c
int unboundedknapsack(void) {
  int numTestCases;
  scanf("%d", &numTestCases);
  while (numTestCases--) {
    int *sizes;
    int numSizes;
    int capacity;
    int *validCapacities;
    scanf("%d %d", &numSizes, &capacity);
    sizes = malloc(sizeof(int) * numSizes);
    for (int i = 0; i < numSizes; i++) {
      scanf("%d", sizes + i);
    }
    validCapacities = malloc(sizeof(int) * (capacity + 1));
    validCapacities[0] = 1;
    int maxValidCapacity = 0;
    for (int i = 1; i <= capacity; i++) {
      for (int j = 0; j < numSizes; j++) {
        int oldCapacity = i - sizes[j];
        if (oldCapacity >= 0 && validCapacities[oldCapacity]) {
          validCapacities[i] = 1;
          maxValidCapacity = i;
          break;
        }
      }
    }
    printf("%d\n", maxValidCapacity);
  }
  return 0;
}
```