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

```asm
<IPS_create>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x38,%rsp
  mov    %rdx,0x8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  test   %rsi,%rsi
  sete   %al
  test   %rdx,%rdx
  sete   %dl
  or     %dl,%al
  jne    L134
  mov    %rdi,%r12
  test   %rdi,%rdi
  je     L134
  mov    %rsi,%rbp
  call   <rewind@plt>
  mov    %rbp,%rdi
  call   <rewind@plt>
  mov    %rbx,%rdi
  call   <rewind@plt>
  mov    %rbx,%rcx
  mov    $0x1,%edx
  mov    $0x5,%esi
  lea    D6(%rip),%rdi
  call   <fwrite@plt>
  cmp    $0x1,%eax
  jne    L184
  mov    $0x10,%esi
  mov    $0x2,%edi
  call   <pow@plt>
  movswl %ax,%edi
  call   <malloc@plt>
  movl   $0x0,0x4(%rsp)
  mov    %rax,%r13
  cs nopw 0x0(%rax,%rax,1)
L58:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L76
L145:
  mov    %r12,%rdi
  call   <feof@plt>
  test   %rax,%rax
  je     L142
  jmp    L76
  nopl   0x0(%rax,%rax,1)
L139:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L32
  mov    %r12,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L32
L142:
  mov    %rbp,%rdi
  call   <fgetc@plt>
  mov    %r12,%rdi
  mov    %eax,%ebx
  call   <fgetc@plt>
  cmp    %bl,%al
  je     L139
L32:
  mov    %rbp,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L58
  mov    %r12,%rdi
  call   <feof@plt>
  test   %rax,%rax
  jne    L58
  mov    %rbp,%rdi
  call   <ftell@plt>
  mov    %bl,0x0(%r13)
  mov    $0x1,%ebx
  sub    $0x1,%eax
  mov    %eax,0x18(%rsp)
  cltq
  mov    %rax,0x10(%rsp)
  jmp    L117
  nopl   0x0(%rax,%rax,1)
L31:
  mov    %r14b,0x0(%r13,%rbx,1)
  mov    $0x10,%esi
  mov    $0x2,%edi
  lea    0x1(%rbx),%r15d
  call   <pow@plt>
  cmp    %r15w,%ax
  jl     L52
  movswq %r15w,%rbx
L117:
  mov    %rbp,%rdi
  call   <fgetc@plt>
  mov    %r12,%rdi
  mov    %eax,%r14d
  call   <fgetc@plt>
  cmp    %r14b,%al
  jne    L31
L72:
  mov    0x10(%rsp),%r15
  movswl %bx,%r8d
  lea    D20(%rip),%rdi
  rol    $0x8,%bx
  mov    %r8d,%ecx
  mov    %r8d,0x1c(%rsp)
  mov    %r15,%rdx
  mov    %r15,%rsi
  call   <printf@plt>
  mov    %r15,%rax
  mov    %bx,0x23(%rsp)
  mov    0x8(%rsp),%rbx
  sar    $0x10,%rax
  lea    0x25(%rsp),%rdi
  mov    $0x1,%edx
  mov    $0x3,%esi
  mov    %al,0x25(%rsp)
  movzwl 0x18(%rsp),%eax
  mov    %rbx,%rcx
  rol    $0x8,%ax
  mov    %ax,0x26(%rsp)
  call   <fwrite@plt>
  lea    0x23(%rsp),%rdi
  mov    %rbx,%rcx
  mov    $0x1,%edx
  mov    $0x2,%esi
  call   <fwrite@plt>
  mov    0x1c(%rsp),%esi
  mov    %r13,%rdi
  mov    %rbx,%rcx
  mov    $0x1,%edx
  call   <fwrite@plt>
  mov    %rbp,%rdi
  addl   $0x1,0x4(%rsp)
  call   <feof@plt>
  test   %rax,%rax
  je     L145
  nopl   0x0(%rax,%rax,1)
L76:
  mov    %r13,%rdi
  call   <free@plt>
  mov    0x8(%rsp),%rcx
  mov    $0x1,%edx
  mov    $0x3,%esi
  lea    D10(%rip),%rdi
  call   <fwrite@plt>
  cmp    $0x1,%eax
  mov    $0xffffffec,%eax
  cmove  0x4(%rsp),%eax
  mov    %eax,0x4(%rsp)
L54:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L159
  mov    0x4(%rsp),%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L52:
  mov    %r15d,%ebx
  jmp    L72
L184:
  movl   $0xfffffff6,0x4(%rsp)
  jmp    L54
L134:
  movl   $0xffffffff,0x4(%rsp)
  jmp    L54
L159:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_label: D6
type_infered: string
name: unpack_data
arguments: data_label: D20
type_infered: string
name: unpack_data
arguments: data_label: D10
type_infered: string

tool: D6: PATCH

tool: D20: Patch: Offset: %d (%08X), Length: %d(%04X)


tool: D10: EOF

assistant: ```c
int IPS_create(FILE *original, FILE *modified, FILE *patch, int use_rle) {
  if (!original || !modified || !patch)
    return -1;
  rewind(original);
  rewind(modified);
  rewind(patch);
  if (fwrite("PATCH", 5, 1, patch) != 1) {
    return -10;
  }
  char *buffer = (char *)malloc(pow(2, 16));
  long patch_offset = 0;
  short buffer_size = 0;
  int patch_count = 0;
  char c;
  while (!feof(modified) && !feof(original)) {
    while ((c = fgetc(modified)) == fgetc(original) && !feof(modified) && !feof(original))
      ;
    if (feof(modified) || feof(original)) {
      continue;
    }
    patch_offset = ftell(modified) - 1;
    buffer[buffer_size++] = c;
    while ((c = fgetc(modified)) != fgetc(original)) {
      buffer[buffer_size++] = c;
      if (buffer_size > pow(2, 16)) {
        break;
      }
    }
    printf("Patch: Offset: %d (%08X), Length: %d(%04X)\n", patch_offset, patch_offset, buffer_size, buffer_size);
    char offset_value[3] = {(patch_offset & 0x00ff0000) >> 16, (patch_offset & 0x0000ff00) >> 8, (patch_offset & 0x000000ff)};
    char size_value[2] = {(buffer_size & 0xff00) >> 8, (buffer_size & 0x00ff)};
    fwrite(offset_value, 3, 1, patch);
    fwrite(size_value, 2, 1, patch);
    fwrite(buffer, buffer_size, 1, patch);
    buffer_size = 0;
    patch_count++;
  }
  free(buffer);
  if (fwrite("EOF", 3, 1, patch) != 1) {
    return -20;
  }
  return patch_count;
}
```