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

```asm
<packEx>:
  endbr64
  push   %r15
  mov    %r8,%r15
  push   %r14
  push   %r13
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %r9,%rbx
  lea    D30(%rip),%r9
  sub    $0x48,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  cmp    $0x1,%ecx
  mov    %edx,0x14(%rsp)
  setg   %r8b
  movzbl %r8b,%r8d
  call   <out@plt>
  test   %eax,%eax
  je     L280
  lea    D30(%rip),%r13
  mov    %r15,%rsi
  mov    %r13,%rdi
  call   <in@plt>
  test   %rax,%rax
  je     L280
  mov    (%rbx),%r14d
  lea    D60(%rip),%rax
  movq   $0x0,0x28(%rsp)
  movq   $0x0,0x30(%rsp)
  mov    %rax,(%rsp)
  cmp    $0xffffffff,%r14d
  je     L23
  cmp    $0x1,%r14d
  je     L23
L190:
  cmpl   $0x2,(%rbx)
  je     L305
  mov    0x28(%rsp),%r14
  mov    0x14(%rsp),%ecx
  movl   $0x0,(%rbx)
  test   %r14,%r14
  je     L235
  mov    0x18(%rsp),%edx
  cmp    %edx,%ecx
  jg     L249
L235:
  lea    D56(%rip),%rdi
  xor    %eax,%eax
  mov    %ecx,0xc(%rsp)
  mov    %rbp,%r14
  call   <printf@plt>
  mov    0xc(%rsp),%edx
L266:
  pxor   %xmm0,%xmm0
  pxor   %xmm1,%xmm1
  mov    %r12d,%esi
  mov    $0x1,%eax
  cvtsi2sd %edx,%xmm0
  mulsd  D52(%rip),%xmm0
  lea    D0(%rip),%rdi
  mov    %edx,0xc(%rsp)
  cvtsi2ss %r12d,%xmm1
  lea    0x20(%rsp),%rbx
  lea    0x38(%rsp),%r12
  cvtss2sd %xmm1,%xmm1
  divsd  %xmm1,%xmm0
  call   <printf@plt>
  mov    0xc(%rsp),%edx
  mov    %edx,(%r15)
  test   %rbp,%rbp
  je     L259
L20:
  cmp    %rbp,%r14
  je     L259
  mov    %rbp,%rdi
  call   <free@plt>
L259:
  add    $0x8,%rbx
  cmp    %r12,%rbx
  je     L24
L38:
  mov    (%rbx),%rbp
  test   %rbp,%rbp
  jne    L20
  add    $0x8,%rbx
  cmp    %r12,%rbx
  jne    L38
L24:
  mov    %r13,%rdi
  call   <remove@plt>
  mov    (%rsp),%rdi
  call   <remove@plt>
L132:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L9
  add    $0x48,%rsp
  mov    %r14,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L23:
  mov    %rax,%rsi
  mov    %r13,%rdi
  call   <appack@plt>
  test   %eax,%eax
  jne    L14
L165:
  cmp    $0xffffffff,%r14d
  jne    L190
L305:
  mov    (%rsp),%rsi
  mov    %r13,%rdi
  call   <lz4wpack@plt>
  test   %eax,%eax
  jne    L109
  mov    0x28(%rsp),%r14
  mov    0x14(%rsp),%ecx
  movl   $0x0,(%rbx)
  test   %r14,%r14
  je     L235
  xor    %esi,%esi
L186:
  mov    0x18(%rsp),%edx
  cmp    %ecx,%edx
  jge    L199
  movl   $0x1,(%rbx)
  test   %rsi,%rsi
  je     L291
  mov    0x1c(%rsp),%eax
  cmp    %edx,%eax
  jl     L75
L291:
  lea    D53(%rip),%rdi
  xor    %eax,%eax
  mov    %edx,0xc(%rsp)
  call   <printf@plt>
  mov    0xc(%rsp),%edx
  jmp    L266
  nopl   0x0(%rax)
L280:
  movl   $0x0,(%r15)
  xor    %r14d,%r14d
  jmp    L132
  nop
L14:
  mov    (%rsp),%rdi
  lea    0x18(%rsp),%rsi
  call   <in@plt>
  mov    %rax,0x28(%rsp)
  jmp    L165
  nopl   0x0(%rax,%rax,1)
L249:
  movl   $0x1,(%rbx)
  jmp    L291
  nopl   0x0(%rax,%rax,1)
L109:
  mov    (%rsp),%rdi
  lea    0x1c(%rsp),%rsi
  call   <in@plt>
  movl   $0x0,(%rbx)
  mov    0x14(%rsp),%ecx
  mov    %rax,0x30(%rsp)
  mov    %rax,%r14
  mov    0x28(%rsp),%rax
  test   %rax,%rax
  jne    L238
L299:
  test   %r14,%r14
  je     L235
  mov    0x1c(%rsp),%edx
  cmp    %ecx,%edx
  jge    L235
L309:
  movl   $0x2,(%rbx)
  lea    D66(%rip),%rdi
  xor    %eax,%eax
  mov    %edx,0xc(%rsp)
  call   <printf@plt>
  mov    0xc(%rsp),%edx
  jmp    L266
L75:
  mov    %eax,%edx
  mov    %rsi,%r14
  jmp    L309
L9:
  call   <__stack_chk_fail@plt>
L199:
  mov    %rsi,%r14
  jmp    L299
L238:
  mov    %r14,%rsi
  mov    %rax,%r14
  jmp    L186
```

tool_calls: name: disassemble_data
arguments: label: D30
type_guessed: string
name: disassemble_data
arguments: label: D60
type_guessed: string
name: disassemble_data
arguments: label: D56
type_guessed: string
name: disassemble_data
arguments: label: D52
type_guessed: f64
name: disassemble_data
arguments: label: D0
type_guessed: string
name: disassemble_data
arguments: label: D53
type_guessed: string
name: disassemble_data
arguments: label: D66
type_guessed: string

tool: D30: pack.in

tool: D60: pack.out

tool: D56: No compression, 

tool: D52: 100

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


tool: D53: Packed with APLIB, 

tool: D66: Packed with LZ4W, 

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;
}
```