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

```asm
<main>:
  endbr64
  push   %r15
  lea    D22(%rip),%rdi
  push   %r14
  push   %r13
  push   %r12
  lea    D73(%rip),%r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <puts@plt>
  lea    D94(%rip),%rdi
  call   <puts@plt>
  lea    D58(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    0x10(%rsp),%rsi
  mov    %r12,%rdi
  call   <scanf@plt>
  lea    D4(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    0x14(%rsp),%rsi
  mov    %r12,%rdi
  call   <scanf@plt>
  mov    0x14(%rsp),%eax
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    %rax,(%rsp)
  test   %rax,%rax
  je     L152
  mov    0x14(%rsp),%eax
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    %rax,0x8(%rsp)
  test   %rax,%rax
  je     L152
  mov    0x14(%rsp),%eax
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L152
  xor    %eax,%eax
  cmpl   $0x0,0x14(%rsp)
  jle    L146
  nopl   0x0(%rax,%rax,1)
L65:
  movl   $0x0,0x0(%r13,%rax,4)
  mov    0x14(%rsp),%edx
  add    $0x1,%rax
  cmp    %eax,%edx
  jg     L65
  test   %edx,%edx
  jle    L146
  mov    (%rsp),%rbp
  mov    0x8(%rsp),%rbx
  xor    %r14d,%r14d
  lea    D59(%rip),%r15
  nopl   0x0(%rax)
L42:
  add    $0x1,%r14d
  mov    %r15,%rdi
  xor    %eax,%eax
  mov    %r14d,%esi
  call   <printf@plt>
  mov    %rbp,%rsi
  mov    %r12,%rdi
  add    $0x4,%rbp
  call   <scanf@plt>
  mov    %r14d,%esi
  lea    D86(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %rbx,%rsi
  mov    %r12,%rdi
  add    $0x4,%rbx
  call   <scanf@plt>
  cmp    0x14(%rsp),%r14d
  jl     L42
L146:
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    0x10(%rsp),%ecx
  mov    (%rsp),%rdi
  mov    %r13,%rsi
  mov    0x14(%rsp),%r8d
  mov    0x8(%rsp),%rdx
  call   <knapsack_greedy@plt>
  lea    D61(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D69(%rip),%rdi
  call   <puts@plt>
  cmpl   $0x0,0x14(%rsp)
  jle    L125
  xor    %ebx,%ebx
  xor    %r12d,%r12d
  lea    D67(%rip),%r14
  xor    %ebp,%ebp
  jmp    L59
L85:
  add    $0x1,%rbx
  cmp    %ebx,0x14(%rsp)
  jle    L114
L59:
  cmpl   $0x1,0x0(%r13,%rbx,4)
  lea    0x1(%rbx),%esi
  jne    L85
  mov    (%rsp),%rax
  mov    %r14,%rdi
  mov    (%rax,%rbx,4),%edx
  mov    0x8(%rsp),%rax
  mov    (%rax,%rbx,4),%ecx
  xor    %eax,%eax
  add    %edx,%ebp
  add    %ecx,%r12d
  call   <printf@plt>
  jmp    L85
L152:
  mov    $0x1,%eax
L18:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L80
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L114:
  test   %ebp,%ebp
  je     L125
  mov    %r12d,%edx
  mov    %ebp,%esi
  lea    D37(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
L101:
  mov    (%rsp),%rdi
  call   <free@plt>
  mov    %r13,%rdi
  call   <free@plt>
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  xor    %eax,%eax
  jmp    L18
L125:
  lea    D29(%rip),%rdi
  call   <puts@plt>
  jmp    L101
L80:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D22
data_type: string
name: retrieve_data
arguments: data_tag: D73
data_type: string
name: retrieve_data
arguments: data_tag: D94
data_type: string
name: retrieve_data
arguments: data_tag: D58
data_type: string
name: retrieve_data
arguments: data_tag: D4
data_type: string
name: retrieve_data
arguments: data_tag: D59
data_type: string
name: retrieve_data
arguments: data_tag: D86
data_type: string
name: retrieve_data
arguments: data_tag: D61
data_type: string
name: retrieve_data
arguments: data_tag: D69
data_type: string
name: retrieve_data
arguments: data_tag: D67
data_type: string
name: retrieve_data
arguments: data_tag: D37
data_type: string
name: retrieve_data
arguments: data_tag: D29
data_type: string

tool: D22: Knapsack Greedy

tool: D73: %d

tool: D94: ---------------


tool: D58: Give max size of sack:

tool: D4: 
Give size of total elements:

tool: D59: Give weight for %d element:

tool: D86: 
Give value for %d element:

tool: D61: Elements inside sack:

tool: D69: 


tool: D67: Element %d is inside with weight %d and value %d


tool: D37: Finally our elements inside sack weight %d and we have earned %d


tool: D29: There aren't elements indise sack!!

assistant: ```c
int main(void) {
  int *weight, *value, *pick;
  int size_sack;
  int size_elem;
  int i, sum_w = 0, sum_v = 0;
  printf("Knapsack Greedy\n");
  printf("---------------\n\n");
  printf("Give max size of sack:");
  scanf("%d", &size_sack);
  printf("\nGive size of total elements:");
  scanf("%d", &size_elem);
  weight = malloc(size_elem * sizeof(int));
  if (weight == NULL)
    return 1;
  value = malloc(size_elem * sizeof(int));
  if (value == NULL)
    return 1;
  pick = malloc(size_elem * sizeof(int));
  if (pick == NULL)
    return 1;
  for (i = 0; i < size_elem; i++)
    pick[i] = 0;
  for (i = 0; i < size_elem; i++) {
    printf("Give weight for %d element:", i + 1);
    scanf("%d", &weight[i]);
    printf("\nGive value for %d element:", i + 1);
    scanf("%d", &value[i]);
  }
  printf("\n");
  knapsack_greedy(weight, pick, value, size_sack, size_elem);
  printf("Elements inside sack:");
  printf("\n\n");
  for (i = 0; i < size_elem; i++) {
    if (pick[i] == 1) {
      sum_w += weight[i];
      sum_v += value[i];
      printf("Element %d is inside with weight %d and value %d\n", i + 1, weight[i], value[i]);
    }
  }
  if (sum_w == 0)
    printf("There aren't elements indise sack!!\n");
  else
    printf("Finally our elements inside sack weight %d and we have earned %d\n", sum_w, sum_v);
  free(weight);
  free(pick);
  free(value);
  return 0;
}
```