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

```asm
<unboundedknapsack>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0x38(%rbp),%rax
  mov    %rax,%rsi
  lea    D17(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  jmp    L106
L42:
  lea    -0x30(%rbp),%rdx
  lea    -0x34(%rbp),%rax
  mov    %rax,%rsi
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  mov    -0x34(%rbp),%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  movl   $0x0,-0x2c(%rbp)
  jmp    L60
L104:
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,%rsi
  lea    D17(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  addl   $0x1,-0x2c(%rbp)
L60:
  mov    -0x34(%rbp),%eax
  cmp    %eax,-0x2c(%rbp)
  jl     L104
  mov    -0x30(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  movl   $0x1,(%rax)
  movl   $0x0,-0x28(%rbp)
  movl   $0x1,-0x24(%rbp)
  jmp    L71
L102:
  movl   $0x0,-0x20(%rbp)
  jmp    L22
L74:
  mov    -0x20(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x24(%rbp),%eax
  sub    %edx,%eax
  mov    %eax,-0x1c(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  js     L76
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  je     L76
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movl   $0x1,(%rax)
  mov    -0x24(%rbp),%eax
  mov    %eax,-0x28(%rbp)
  jmp    L108
L76:
  addl   $0x1,-0x20(%rbp)
L22:
  mov    -0x34(%rbp),%eax
  cmp    %eax,-0x20(%rbp)
  jl     L74
L108:
  addl   $0x1,-0x24(%rbp)
L71:
  mov    -0x30(%rbp),%eax
  cmp    %eax,-0x24(%rbp)
  jle    L102
  mov    -0x28(%rbp),%eax
  mov    %eax,%esi
  lea    D13(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
L106:
  mov    -0x38(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x38(%rbp)
  test   %eax,%eax
  jne    L42
  mov    $0x0,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L29
  call   <__stack_chk_fail@plt>
L29:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: label: D17
type_guessed: string
name: disassemble_data
arguments: label: D18
type_guessed: string
name: disassemble_data
arguments: label: D13
type_guessed: string

tool: D17: %d

tool: D18: %d %d

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