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

```asm
<opera_mem>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %edi,%r13d
  mov    %rdx,%r15
  mov    %rcx,(%rsp)
  mov    %r8d,%r12d
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  test   %esi,%esi
  je     L163
  cmpq   $0x0,(%rsp)
  je     L157
L37:
  movslq %r12d,%rax
  shr    $0x2,%rax
  mov    (%rsp),%rbp
  lea    0x1(%rax),%rdx
  mov    %r12d,%ecx
  and    $0x3,%ecx
  mov    %ecx,0xc(%rsp)
  cmove  %rax,%rdx
  mov    %rdx,(%rsp)
  mov    $0x0,%ebx
  lea    0x10(%rsp),%r14
  jmp    L173
L163:
  mov    %r8d,%ebx
  and    $0xfffffffc,%ebx
  movslq %ebx,%rax
  and    $0x3,%r12d
  je     L124
  mov    %rax,%r14
  lea    0x4(%rax),%rbp
  lea    0x10(%rsp),%rdx
  add    %r15,%rax
  mov    %rax,%rsi
  mov    $0x4,%ecx
  call   <getdata@plt>
  movslq %r12d,%r12
  mov    $0x0,%eax
  add    (%rsp),%r14
L34:
  movzbl (%r14,%rax,1),%edx
  mov    %dl,0x10(%rsp,%rax,1)
  add    $0x1,%rax
  cmp    %r12,%rax
  jne    L34
L39:
  mov    %rbp,%r14
  shr    $0x2,%r14
  cmp    $0x3,%rbp
  jbe    L181
  movslq %ebx,%r12
  shr    $0x2,%r12
  mov    %r15,%rbp
  mov    $0x0,%ebx
  mov    (%rsp),%rax
  sub    %r15,%rax
  mov    %rax,%r15
  jmp    L188
L125:
  lea    0x10(%rsp),%rdx
  mov    $0x4,%ecx
  mov    %rbp,%rsi
  mov    %r13d,%edi
  call   <putdata@plt>
L189:
  add    $0x1,%rbx
  add    $0x4,%rbp
  cmp    %rbx,%r14
  jbe    L138
L188:
  cmp    %rbx,%r12
  je     L125
  lea    (%r15,%rbp,1),%rdx
  mov    $0x4,%ecx
  mov    %rbp,%rsi
  mov    %r13d,%edi
  call   <putdata@plt>
  jmp    L189
L138:
  mov    $0x1,%eax
  jmp    L136
L157:
  mov    %r8d,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    $0x0,%eax
  test   %rdx,%rdx
  je     L136
  mov    %rdx,(%rsp)
  jmp    L37
L107:
  mov    $0x4,%edx
  mov    %r14,%rsi
  mov    %rbp,%rdi
  call   <memcpy@plt>
L30:
  add    $0x1,%rbx
  add    $0x4,%rbp
L173:
  cmp    (%rsp),%rbx
  je     L165
  lea    (%r15,%rbx,4),%rsi
  mov    $0x4,%ecx
  mov    %r14,%rdx
  mov    %r13d,%edi
  call   <getdata@plt>
  movslq %r12d,%rax
  cmp    %rbx,%rax
  jge    L107
  mov    0xc(%rsp),%edx
  mov    %r14,%rsi
  mov    %rbp,%rdi
  call   <memcpy@plt>
  jmp    L30
L165:
  mov    $0x1,%eax
L136:
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L153
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L181:
  mov    $0x1,%eax
  jmp    L136
L124:
  lea    0x10(%rsp),%rdx
  mov    %rax,%rbp
  lea    (%r15,%rax,1),%rsi
  mov    $0x4,%ecx
  call   <getdata@plt>
  jmp    L39
L153:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int opera_mem(pid_t target, int mode, long addr, unsigned char *bytes, int numbytes) {
  unsigned char buff[16];
  long cont, endpadd, startcopy;
  if (mode == 0) {
    startcopy = (numbytes / sizeof(int)) * sizeof(int);
    endpadd = (numbytes % sizeof(int) == 0 ? startcopy : startcopy + sizeof(int));
    getdata(target, addr + startcopy, buff, sizeof(int));
    for (cont = 0; cont < numbytes % sizeof(int); cont++) {
      buff[cont] = bytes[startcopy + cont];
    }
    for (cont = 0; cont < endpadd / sizeof(int); cont++) {
      if (cont == (startcopy / sizeof(int))) {
        putdata(target, (cont * sizeof(int)) + addr, buff, sizeof(int));
      } else {
        putdata(target, (cont * sizeof(int)) + addr, bytes + (cont * sizeof(int)), sizeof(int));
      }
    }
    return 1;
  } else {
    if (bytes == NULL) {
      bytes = (unsigned char *)malloc(sizeof(char) * numbytes);
      if (bytes == NULL)
        return 0;
    }
    for (cont = 0; cont < (numbytes % sizeof(int) == 0 ? numbytes / sizeof(int) : (numbytes / sizeof(int)) + 1); cont++) {
      getdata(target, addr + (cont * sizeof(int)), buff, sizeof(int));
      if (cont > numbytes)
        memcpy(bytes + (cont * sizeof(int)), buff, (numbytes % sizeof(int)));
      else
        memcpy(bytes + (cont * sizeof(int)), buff, sizeof(int));
    }
    return 1;
  }
}
```