user: Translate the below assembly code into C programming language:

```asm
<to_octets>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%r14
  mov    %esi,%ebx
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  mov    $0xff,%eax
  cmp    %eax,%esi
  cmovle %esi,%eax
  mov    %eax,%r15d
  lea    0xf(%rax),%r12d
  test   %eax,%eax
  cmovns %eax,%r12d
  sar    $0x4,%r12d
  add    $0x2,%r12d
  imul   $0x39,%r12d,%r12d
  add    $0x1,%r12d
  mov    %r12d,%edi
  call   <oml_malloc@plt>
  mov    %rax,(%rsp)
  movb   $0x0,0x20(%rsp)
  test   %rax,%rax
  je     L47
  mov    %rax,%rdi
  mov    $0x0,%ecx
  lea    D37(%rip),%rdx
  mov    %r12d,%esi
  mov    $0x0,%eax
  call   <snprintf@plt>
  mov    %eax,%ebp
  test   %ebx,%ebx
  jle    L51
  mov    $0x1,%ebx
  movl   $0x0,0x8(%rsp)
  movl   $0x1,0xc(%rsp)
  jmp    L160
L116:
  mov    0xc(%rsp),%r8d
  lea    0x1(%r8),%eax
  mov    %eax,0xc(%rsp)
  lea    0x10(%rsp),%rcx
  mov    %r12d,%esi
  sub    %r13d,%esi
  movslq %r13d,%rdi
  add    (%rsp),%rdi
  lea    D4(%rip),%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  lea    0x0(%r13,%rax,1),%ebp
L115:
  add    $0x1,%rbx
L160:
  movzbl -0x1(%r14,%rbx,1),%ecx
  mov    %r12d,%esi
  sub    %ebp,%esi
  movslq %ebp,%rdi
  add    (%rsp),%rdi
  lea    D51(%rip),%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  lea    0x0(%rbp,%rax,1),%r13d
  mov    %r13d,%ebp
  movzbl -0x1(%r14,%rbx,1),%edi
  call   <isprint@plt>
  mov    %rax,%rdx
  mov    $0x2e,%eax
  test   %rdx,%rdx
  je     L41
  movzbl -0x1(%r14,%rbx,1),%eax
L41:
  movslq 0x8(%rsp),%rdx
  mov    %al,0x10(%rsp,%rdx,1)
  mov    %ebx,%ecx
  cmp    %r15d,%ebx
  jge    L51
  mov    %ebx,%edx
  sar    $0x1f,%edx
  shr    $0x1c,%edx
  lea    (%rdx,%rbx,1),%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,0x8(%rsp)
  test   %ebx,%ebx
  je     L115
  test   $0xf,%cl
  je     L116
  test   $0x7,%al
  je     L122
  test   $0x3,%al
  jne    L115
  mov    %r12d,%esi
  sub    %r13d,%esi
  movslq %r13d,%rdi
  add    (%rsp),%rdi
  lea    D48(%rip),%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  lea    0x0(%r13,%rax,1),%ebp
  jmp    L115
L122:
  mov    %r12d,%esi
  sub    %r13d,%esi
  movslq %r13d,%rdi
  add    (%rsp),%rdi
  lea    D32(%rip),%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  lea    0x0(%r13,%rax,1),%ebp
  jmp    L115
L51:
  mov    0x8(%rsp),%eax
  test   %eax,%eax
  je     L47
  mov    %eax,%ebx
  add    $0x1,%ebx
  cmp    $0xf,%ebx
  jg     L110
  lea    D32(%rip),%r14
  lea    D5(%rip),%r13
  lea    D26(%rip),%r15
  jmp    L197
L145:
  mov    %r12d,%esi
  sub    %ebp,%esi
  movslq %ebp,%rdi
  add    (%rsp),%rdi
  mov    %r15,%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  add    %eax,%ebp
  jmp    L189
L161:
  mov    %r12d,%esi
  sub    %ebp,%esi
  movslq %ebp,%rdi
  add    (%rsp),%rdi
  mov    %r14,%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  add    %eax,%ebp
L189:
  add    $0x1,%ebx
  cmp    $0x10,%ebx
  je     L110
L197:
  test   $0x7,%bl
  je     L145
  test   $0x3,%bl
  jne    L161
  mov    %r12d,%esi
  sub    %ebp,%esi
  movslq %ebp,%rdi
  add    (%rsp),%rdi
  mov    %r13,%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
  add    %eax,%ebp
  jmp    L189
L110:
  movslq %ebx,%rbx
  movb   $0x0,0x10(%rsp,%rbx,1)
  lea    0x10(%rsp),%rcx
  mov    %r12d,%esi
  sub    %ebp,%esi
  movslq %ebp,%rdi
  add    (%rsp),%rdi
  lea    D75(%rip),%rdx
  mov    $0x0,%eax
  call   <snprintf@plt>
L47:
  movslq %r12d,%r12
  mov    (%rsp),%rax
  movb   $0x0,-0x1(%rax,%r12,1)
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L146
  mov    (%rsp),%rax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L146:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D37
datatype: string
name: unpack_data
arguments: label: D4
datatype: string
name: unpack_data
arguments: label: D51
datatype: string
name: unpack_data
arguments: label: D48
datatype: string
name: unpack_data
arguments: label: D32
datatype: string
name: unpack_data
arguments: label: D5
datatype: string
name: unpack_data
arguments: label: D26
datatype: string
name: unpack_data
arguments: label: D75
datatype: string

tool: D37:    0 1 2 3  4 5 6 7   8 9 a b  c d e f  0123456789abcdef
%2x 

tool: D4:  %s
%2x 

tool: D51: %02x

tool: D48:  

tool: D32:   

tool: D5:    

tool: D26:     

tool: D75:  %s

assistant: ```c
char *to_octets(unsigned char *buf, int len) {
  const int octet_width = 2;
  const int columns = 16;
  len = (len > 0xff) ? 0xff : len;
  const int rows = len / columns + 2;
  const int rowlength = (octet_width * columns + 7 + 1 + columns + 1);
  const int outlength = rows * rowlength + 1;
  char *out = oml_malloc(outlength);
  char strrep[columns + 1];
  int n = 0, i, col, rw = 0;
  strrep[columns] = 0;
  if (out) {
    n += snprintf(out, outlength - n, "   0 1 2 3  4 5 6 7   8 9 a b  c d e f  0123456789abcdef\n%2x ", rw++);
    for (i = 0; i < len; i++) {
      col = i % columns;
      if (i == 0) {
        while (0)
          ;
      } else if (col == 0) {
        n += snprintf(&out[n], outlength - n, " %s\n%2x ", strrep, rw++);
      } else if (0 == (col % 8)) {
        n += snprintf(&out[n], outlength - n, "  ");
      } else if (0 == (col % 4)) {
        n += snprintf(&out[n], outlength - n, " ");
      }
      n += snprintf(&out[n], outlength - n, "%02x", (unsigned int)buf[i]);
      if (isprint(buf[i])) {
        strrep[col] = buf[i];
      } else {
        strrep[col] = '.';
      }
    }
    if (col != 0) {
      while (++col < columns) {
        if (0 == (col % 8)) {
          n += snprintf(&out[n], outlength - n, "    ");
        } else if (0 == (col % 4)) {
          n += snprintf(&out[n], outlength - n, "   ");
        } else {
          n += snprintf(&out[n], outlength - n, "  ");
        }
      }
      strrep[col] = 0;
      n += snprintf(&out[n], outlength - n, " %s", strrep);
    }
  }
  out[outlength - 1] = 0;
  return out;
}
```