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

```asm
<packEx>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,%r13
  mov    %edx,%ebp
  mov    %r8,%r14
  mov    %r9,%r12
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  mov    %rdi,0x20(%rsp)
  mov    %edx,0x14(%rsp)
  cmp    $0x1,%ecx
  lea    D68(%rip),%r9
  setg   %r8b
  movzbl %r8b,%r8d
  call   <out@plt>
  test   %eax,%eax
  je     L141
  mov    %r14,%rsi
  lea    D68(%rip),%rdi
  call   <in@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L299
  movq   $0x0,0x28(%rsp)
  movq   $0x0,0x30(%rsp)
  mov    (%r12),%r15d
  mov    $0x2,%ebx
  lea    0x18(%rsp),%rax
  mov    %rax,0x8(%rsp)
  jmp    L61
L141:
  movl   $0x0,(%r14)
  mov    $0x0,%ebx
  jmp    L83
L299:
  movl   $0x0,(%r14)
  jmp    L83
L10:
  cmp    $0x1,%eax
  je     L237
  cmp    $0x2,%eax
  je     L307
L309:
  cmp    $0x2,%ebx
  jg     L165
L13:
  add    $0x1,%ebx
L61:
  lea    -0x1(%rbx),%eax
  cmp    $0xffffffff,%r15d
  je     L10
  cmp    %eax,(%r12)
  jne    L309
  jmp    L10
L237:
  lea    D19(%rip),%rsi
  lea    D68(%rip),%rdi
  call   <appack@plt>
  test   %eax,%eax
  je     L13
  mov    0x8(%rsp),%rsi
  lea    D19(%rip),%rdi
  call   <in@plt>
  mov    %rax,0x28(%rsp)
  jmp    L13
L307:
  lea    D19(%rip),%rsi
  lea    D68(%rip),%rdi
  call   <lz4wpack@plt>
  test   %eax,%eax
  jne    L318
L165:
  mov    0x14(%rsp),%r15d
  movl   $0x0,(%r12)
  mov    0x28(%rsp),%rax
  test   %rax,%rax
  je     L100
  mov    0x18(%rsp),%edx
  cmp    %edx,%r15d
  jle    L100
  movl   $0x1,(%r12)
  mov    0x30(%rsp),%rbx
  test   %rbx,%rbx
  je     L179
  mov    %edx,%r15d
  mov    %rax,%r13
  jmp    L130
L318:
  lea    0x1c(%rsp),%rsi
  lea    D19(%rip),%rdi
  call   <in@plt>
  mov    %rax,0x30(%rsp)
  jmp    L165
L74:
  mov    (%r12),%eax
  cmp    $0x1,%eax
  jne    L128
L50:
  lea    D128(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    %r13,%rbx
L39:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r15d,%xmm0
  mulsd  D43(%rip),%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2ss %ebp,%xmm1
  cvtss2sd %xmm1,%xmm1
  divsd  %xmm1,%xmm0
  mov    %r15d,%edx
  mov    %ebp,%esi
  lea    D126(%rip),%rdi
  mov    $0x1,%eax
  call   <printf@plt>
  mov    %r15d,(%r14)
  lea    0x20(%rsp),%rbp
  lea    0x38(%rsp),%r12
  jmp    L11
L128:
  cmp    $0x2,%eax
  je     L199
L24:
  lea    D70(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    %r13,%rbx
  jmp    L39
L179:
  mov    %edx,%r15d
  mov    %rax,%r13
  jmp    L50
L199:
  mov    %r15d,0x8(%rsp)
  mov    %r13,%rbx
  jmp    L131
L225:
  add    $0x8,%rbp
  cmp    %rbp,%r12
  je     L291
L11:
  mov    0x0(%rbp),%rdi
  cmp    %rbx,%rdi
  je     L225
  test   %rdi,%rdi
  je     L225
  call   <free@plt>
  jmp    L225
L291:
  lea    D68(%rip),%rdi
  call   <remove@plt>
  lea    D19(%rip),%rdi
  call   <remove@plt>
L83:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L311
  mov    %rbx,%rax
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L100:
  mov    0x30(%rsp),%rbx
  test   %rbx,%rbx
  je     L24
L130:
  mov    0x1c(%rsp),%eax
  mov    %eax,0x8(%rsp)
  cmp    %r15d,%eax
  jge    L74
  movl   $0x2,(%r12)
L131:
  lea    D47(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    0x8(%rsp),%r15d
  jmp    L39
L311:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D68
data_type: string
name: retrieve_data
arguments: data_tag: D19
data_type: string
name: retrieve_data
arguments: data_tag: D128
data_type: string
name: retrieve_data
arguments: data_tag: D43
data_type: f64
name: retrieve_data
arguments: data_tag: D126
data_type: string
name: retrieve_data
arguments: data_tag: D70
data_type: string
name: retrieve_data
arguments: data_tag: D47
data_type: string

tool: D68: pack.in

tool: D19: pack.out

tool: D128: Packed with APLIB, 

tool: D43: 100

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


tool: D70: No compression, 

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