user: Converte this assembly snippet into its equivalent C code:

```asm
<packEx>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  add    $0xffffffffffffff80,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %esi,-0x5c(%rbp)
  mov    %edx,-0x60(%rbp)
  mov    %ecx,-0x64(%rbp)
  mov    %r8,-0x70(%rbp)
  mov    %r9,-0x78(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x58(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x60(%rbp),%eax
  mov    %eax,-0x2c(%rbp)
  cmpl   $0x1,-0x64(%rbp)
  setg   %al
  movzbl %al,%edi
  mov    -0x64(%rbp),%ecx
  mov    -0x60(%rbp),%edx
  mov    -0x5c(%rbp),%esi
  mov    -0x58(%rbp),%rax
  lea    D57(%rip),%r9
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <out@plt>
  test   %eax,%eax
  jne    L200
  mov    -0x70(%rbp),%rax
  movl   $0x0,(%rax)
  mov    $0x0,%eax
  jmp    L32
L200:
  mov    -0x70(%rbp),%rax
  mov    %rax,%rsi
  lea    D57(%rip),%rax
  mov    %rax,%rdi
  call   <in@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L228
  mov    -0x70(%rbp),%rax
  movl   $0x0,(%rax)
  mov    $0x0,%eax
  jmp    L32
L228:
  movl   $0x1,-0x48(%rbp)
  jmp    L70
L34:
  mov    -0x48(%rbp),%eax
  cltq
  movq   $0x0,-0x20(%rbp,%rax,8)
  addl   $0x1,-0x48(%rbp)
L70:
  cmpl   $0x2,-0x48(%rbp)
  jle    L34
  mov    -0x78(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0xffffffff,%eax
  sete   %al
  movzbl %al,%eax
  mov    %eax,-0x44(%rbp)
  movl   $0x1,-0x48(%rbp)
  jmp    L20
L209:
  cmpl   $0x0,-0x44(%rbp)
  jne    L283
  mov    -0x78(%rbp),%rax
  mov    (%rax),%eax
  cmp    %eax,-0x48(%rbp)
  jne    L55
L283:
  cmpl   $0x1,-0x48(%rbp)
  je     L69
  cmpl   $0x2,-0x48(%rbp)
  je     L83
  jmp    L55
L69:
  lea    D18(%rip),%rax
  mov    %rax,%rsi
  lea    D57(%rip),%rax
  mov    %rax,%rdi
  call   <appack@plt>
  test   %eax,%eax
  je     L179
  lea    -0x2c(%rbp),%rax
  add    $0x4,%rax
  mov    %rax,%rsi
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  call   <in@plt>
  mov    %rax,-0x18(%rbp)
  jmp    L179
L83:
  lea    D18(%rip),%rax
  mov    %rax,%rsi
  lea    D57(%rip),%rax
  mov    %rax,%rdi
  call   <lz4wpack@plt>
  test   %eax,%eax
  je     L53
  lea    -0x2c(%rbp),%rax
  add    $0x8,%rax
  mov    %rax,%rsi
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  call   <in@plt>
  mov    %rax,-0x10(%rbp)
  jmp    L53
L179:
  nop
  jmp    L55
L53:
  nop
L55:
  addl   $0x1,-0x48(%rbp)
L20:
  cmpl   $0x2,-0x48(%rbp)
  jle    L209
  mov    -0x2c(%rbp),%eax
  mov    %eax,-0x4c(%rbp)
  mov    -0x20(%rbp),%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x78(%rbp),%rax
  movl   $0x0,(%rax)
  movl   $0x1,-0x48(%rbp)
  jmp    L285
L61:
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x20(%rbp,%rax,8),%rax
  test   %rax,%rax
  je     L192
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x2c(%rbp,%rax,4),%eax
  cmp    %eax,-0x4c(%rbp)
  jle    L192
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x2c(%rbp,%rax,4),%eax
  mov    %eax,-0x4c(%rbp)
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x20(%rbp,%rax,8),%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x78(%rbp),%rax
  mov    -0x48(%rbp),%edx
  mov    %edx,(%rax)
L192:
  addl   $0x1,-0x48(%rbp)
L285:
  cmpl   $0x2,-0x48(%rbp)
  jle    L61
  mov    -0x78(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0x1,%eax
  je     L122
  cmp    $0x2,%eax
  je     L76
  jmp    L98
L122:
  lea    D7(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L313
L76:
  lea    D143(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L313
L98:
  lea    D147(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L313:
  pxor   %xmm1,%xmm1
  cvtsi2sdl -0x4c(%rbp),%xmm1
  movsd  D149(%rip),%xmm0
  mulsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2ssl -0x60(%rbp),%xmm1
  cvtss2sd %xmm1,%xmm1
  divsd  %xmm1,%xmm0
  movq   %xmm0,%rcx
  mov    -0x4c(%rbp),%edx
  mov    -0x60(%rbp),%eax
  movq   %rcx,%xmm0
  mov    %eax,%esi
  lea    D82(%rip),%rax
  mov    %rax,%rdi
  mov    $0x1,%eax
  call   <printf@plt>
  mov    -0x70(%rbp),%rax
  mov    -0x4c(%rbp),%edx
  mov    %edx,(%rax)
  movl   $0x0,-0x48(%rbp)
  jmp    L6
L115:
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x20(%rbp,%rax,8),%rax
  test   %rax,%rax
  je     L301
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x20(%rbp,%rax,8),%rax
  cmp    %rax,-0x40(%rbp)
  je     L301
  mov    -0x48(%rbp),%eax
  cltq
  mov    -0x20(%rbp,%rax,8),%rax
  mov    %rax,%rdi
  call   <free@plt>
L301:
  addl   $0x1,-0x48(%rbp)
L6:
  cmpl   $0x2,-0x48(%rbp)
  jle    L115
  lea    D57(%rip),%rax
  mov    %rax,%rdi
  call   <remove@plt>
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  call   <remove@plt>
  mov    -0x40(%rbp),%rax
L32:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L210
  call   <__stack_chk_fail@plt>
L210:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D57
type_infered: string
name: disassemble_data
arguments: data_label: D18
type_infered: string
name: disassemble_data
arguments: data_label: D7
type_infered: string
name: disassemble_data
arguments: data_label: D143
type_infered: string
name: disassemble_data
arguments: data_label: D147
type_infered: string
name: disassemble_data
arguments: data_label: D149
type_infered: f64
name: disassemble_data
arguments: data_label: D82
type_infered: string

tool: D57: pack.in

tool: D18: pack.out

tool: D7: Packed with APLIB, 

tool: D143: Packed with LZ4W, 

tool: D147: No compression, 

tool: D149: 100

tool: D82: original size = %d compressed to %d (%g %%)


assistant: ```c
unsigned char *packEx(unsigned char *data, int inOffset, int size, int intSize, int *outSize, int *method) {
  unsigned char *src;
  unsigned char *result;
  unsigned char *results[2 + 1];
  int sizes[2 + 1];
  int minSize;
  int autoSelect;
  int i;
  results[0] = data;
  sizes[0] = size;
  if (!out(data, inOffset, size, intSize, (intSize > 1) ? 1 : 0, "pack.in")) {
    *outSize = 0;
    return 0;
  }
  src = in("pack.in", outSize);
  if (src == 0) {
    *outSize = 0;
    return 0;
  }
  for (i = 1; i <= 2; i++)
    results[i] = 0;
  autoSelect = (*method == -1);
  for (i = 1; i <= 2; i++) {
    if (autoSelect || (*method == i)) {
      switch (i) {
      case 1:
        if (appack("pack.in", "pack.out"))
          results[1] = in("pack.out", &sizes[1]);
        break;
      case 2:
        if (lz4wpack("pack.in", "pack.out"))
          results[2] = in("pack.out", &sizes[2]);
        break;
      }
    }
  }
  minSize = sizes[0];
  result = results[0];
  *method = 0;
  for (i = 1; i <= 2; i++) {
    if (results[i] != 0) {
      if (sizes[i] < minSize) {
        minSize = sizes[i];
        result = results[i];
        *method = i;
      }
    }
  }
  switch (*method) {
  case 1:
    printf("Packed with APLIB, ");
    break;
  case 2:
    printf("Packed with LZ4W, ");
    break;
  default:
    printf("No compression, ");
  }
  printf("original size = %d compressed to %d (%g %%)\n", size, minSize, (minSize * 100.0) / (float)size);
  *outSize = minSize;
  for (i = 0; i <= 2; i++) {
    if ((results[i] != 0) && (results[i] != result))
      free(results[i]);
  }
  remove("pack.in");
  remove("pack.out");
  return result;
}
```