user: 请将以下的汇编代码转换成C语言代码：

```asm
<unboundedknapsack>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  lea    D15(%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
  lea    0x14(%rsp),%r15
  lea    0x10(%rsp),%r14
  call   <scanf@plt>
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,0xc(%rsp)
  test   %eax,%eax
  je     L31
  nopl   0x0(%rax,%rax,1)
L93:
  mov    %r15,%rdx
  mov    %r14,%rsi
  lea    D24(%rip),%rdi
  xor    %eax,%eax
  call   <scanf@plt>
  mov    0x10(%rsp),%eax
  xor    %r12d,%r12d
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    0x10(%rsp),%ecx
  mov    %rax,%rbx
  mov    %rax,%r13
  test   %ecx,%ecx
  jle    L70
  nopl   (%rax)
L1:
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  add    $0x1,%r12d
  call   <scanf@plt>
  add    $0x4,%r13
  cmp    %r12d,0x10(%rsp)
  jg     L1
L70:
  mov    0x14(%rsp),%eax
  lea    0x4(,%rax,4),%edi
  call   <malloc@plt>
  mov    $0x2,%r8d
  xor    %r10d,%r10d
  movl   $0x1,(%rax)
  mov    0x14(%rsp),%r9d
  mov    %rax,%rdi
  test   %r9d,%r9d
  jle    L111
  mov    0x10(%rsp),%edx
  lea    -0x1(%r8),%ecx
  test   %edx,%edx
  jle    L111
  nopl   0x0(%rax)
L49:
  mov    %rbx,%rax
  lea    (%rbx,%rdx,4),%rsi
  nop
L76:
  mov    %ecx,%edx
  sub    (%rax),%edx
  js     L120
  movslq %edx,%rdx
  mov    (%rdi,%rdx,4),%edx
  test   %edx,%edx
  jne    L115
L120:
  add    $0x4,%rax
  cmp    %rax,%rsi
  jne    L76
L124:
  cmp    %r8d,%r9d
  jl     L111
  mov    0x10(%rsp),%edx
  add    $0x1,%r8
  lea    -0x1(%r8),%ecx
  test   %edx,%edx
  jg     L49
L111:
  mov    %r10d,%esi
  lea    D14(%rip),%rdi
  call   <printf@plt>
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,0xc(%rsp)
  test   %eax,%eax
  jne    L93
L31:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L114
  add    $0x28,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L115:
  movl   $0x1,-0x4(%rdi,%r8,4)
  mov    %ecx,%r10d
  mov    0x14(%rsp),%r9d
  jmp    L124
L114:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D15
type_guessed: string
name: retrieve_data
arguments: label: D24
type_guessed: string
name: retrieve_data
arguments: label: D14
type_guessed: string

tool: D15: %d

tool: D24: %d %d

tool: D14: %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;
}
```