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

```asm
<fmerge>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdx,0x18(%rsp)
  mov    %r8d,%edx
  mov    %rdi,0x10(%rsp)
  sub    %ecx,%edx
  mov    %rsi,0x8(%rsp)
  mov    %ecx,0x20(%rsp)
  mov    %r8d,0x24(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  movl   $0x0,0x30(%rsp)
  movl   $0x0,0x34(%rsp)
  test   %edx,%edx
  jle    L114
  movslq %ecx,%rax
  shl    $0x3,%rax
  lea    (%rsi,%rax,1),%rbx
  cmp    $0x1,%edx
  je     L58
  mov    (%rbx),%r13
  mov    0x8(%rsp),%rbx
  lea    0x34(%rsp),%r12
  lea    0x8(%rbx,%rax,1),%rax
  lea    0x30(%rsp),%rbx
  mov    %rax,0x28(%rsp)
  mov    (%rax),%r14
  xor    %eax,%eax
  call   <tmpfile@plt>
  mov    %r13,%rcx
  mov    $0x1,%edx
  mov    %rbx,%rdi
  mov    $0x4,%esi
  mov    %rax,%rbp
  call   <fread@plt>
  mov    %eax,0x4(%rsp)
  nopl   (%rax)
L121:
  mov    %r14,%rcx
  mov    $0x1,%edx
  mov    $0x4,%esi
  mov    %r12,%rdi
  call   <fread@plt>
  mov    0x4(%rsp),%r8d
  mov    %eax,%r15d
L79:
  test   %r8d,%r8d
  setne  %al
  test   %r15d,%r15d
  jne    L119
L128:
  test   %al,%al
  je     L119
L85:
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x4,%esi
  mov    %rbx,%rdi
  call   <fwrite@plt>
  mov    %r13,%rcx
  mov    $0x1,%edx
  mov    %rbx,%rdi
  mov    $0x4,%esi
  call   <fread@plt>
  mov    %eax,%r8d
  test   %r8d,%r8d
  setne  %al
  test   %r15d,%r15d
  je     L128
L119:
  test   %r15d,%r15d
  setne  %dl
  test   %r8d,%r8d
  jne    L117
  test   %dl,%dl
  je     L117
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x4,%esi
  mov    %r12,%rdi
  call   <fwrite@plt>
  mov    %r14,%rcx
  mov    $0x1,%edx
  mov    %r12,%rdi
  mov    $0x4,%esi
  call   <fread@plt>
  xor    %r8d,%r8d
  mov    %eax,%r15d
  jmp    L79
  nopl   0x0(%rax,%rax,1)
L117:
  test   %al,%al
  je     L73
  test   %dl,%dl
  je     L73
  mov    0x34(%rsp),%eax
  cmp    %eax,0x30(%rsp)
  jl     L85
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x4,%esi
  mov    %r12,%rdi
  mov    %r8d,0x4(%rsp)
  call   <fwrite@plt>
  jmp    L121
  nopl   (%rax)
L73:
  mov    %r13,%rdi
  call   <fclose@plt>
  mov    %r14,%rdi
  call   <fclose@plt>
  xor    %eax,%eax
  call   <tmpfile@plt>
  mov    %rbp,%rdi
  mov    %rax,%rbx
  call   <rewind@plt>
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <copy_content@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %rbx,%rdi
  call   <rewind@plt>
  mov    0x28(%rsp),%rax
  mov    0x20(%rsp),%ecx
  mov    0x24(%rsp),%r8d
  mov    0x18(%rsp),%rdx
  mov    0x8(%rsp),%rsi
  mov    0x10(%rsp),%rdi
  mov    %rbx,(%rax)
  add    $0x1,%ecx
  call   <fmerge>
L114:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L47
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L58:
  mov    %rdi,%rdx
  lea    D3(%rip),%rsi
  xor    %edi,%edi
  call   <freopen@plt>
  mov    (%rbx),%rdi
  mov    %rax,%rsi
  call   <copy_content@plt>
  mov    (%rbx),%rdi
  call   <fclose@plt>
  jmp    L114
L47:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D3
type_infered: string

tool: D3: wb

assistant: ```c
void fmerge(FILE *f, FILE **file_list, size_t buffer_size, int begin, int end) {
  int len = end - begin;
  FILE *f1 = 0;
  FILE *f2 = 0;
  FILE *f3 = 0;
  int a = 0;
  int read_a = 0;
  int b = 0;
  int read_b = 0;
  if (len < 1) {
    return;
  }
  if (len == 1) {
    f = freopen(0, "wb", f);
    copy_content(file_list[begin], f);
    fclose(file_list[begin]);
    return;
  }
  f1 = file_list[begin];
  f2 = file_list[begin + 1];
  f3 = tmpfile();
  read_a = (int)fread(&a, sizeof(a), 1, f1);
  read_b = (int)fread(&b, sizeof(b), 1, f2);
  while (1) {
    if (read_a && !read_b) {
      fwrite(&a, sizeof(a), 1, f3);
      read_a = (int)fread(&a, sizeof(a), 1, f1);
    } else if (read_b && !read_a) {
      fwrite(&b, sizeof(b), 1, f3);
      read_b = (int)fread(&b, sizeof(b), 1, f2);
    } else if (read_a && read_b) {
      if (a < b) {
        fwrite(&a, sizeof(a), 1, f3);
        read_a = (int)fread(&a, sizeof(a), 1, f1);
      } else {
        fwrite(&b, sizeof(b), 1, f3);
        read_b = (int)fread(&b, sizeof(b), 1, f2);
      }
    } else {
      break;
    }
  }
  fclose(f1);
  fclose(f2);
  f2 = tmpfile();
  rewind(f3);
  copy_content(f3, f2);
  fclose(f3);
  rewind(f2);
  file_list[begin + 1] = f2;
  fmerge(f, file_list, buffer_size, begin + 1, end);
}
```