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

```asm
<decimal_to_hex>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  test   %rdx,%rdx
  sete   %al
  cmp    $0x4,%rcx
  setbe  %dl
  or     %dl,%al
  jne    L121
  mov    %rdi,%r14
  test   %rdi,%rdi
  je     L121
  mov    $0x7830,%eax
  cmp    $0x3,%rcx
  lea    -0x3(%rcx),%r13
  mov    %rsi,%r15
  mov    $0x1,%edx
  mov    %ax,(%r12)
  lea    0x2(%r12),%rbp
  mov    %rcx,%rbx
  cmovne %r13,%rdx
  mov    %rbp,%rdi
  xor    %esi,%esi
  call   <memset@plt>
  test   %r15,%r15
  je     L134
  mov    %r14,%rdi
  lea    (%r14,%r15,1),%r8
  lea    -0x2(%r12,%rbx,1),%rsi
  nopl   0x0(%rax,%rax,1)
L49:
  movzbl (%rdi),%eax
  test   %al,%al
  je     L134
  sub    $0x30,%eax
  cmp    $0x9,%al
  ja     L228
  mov    %rsi,%rdx
  mov    %rsi,%rcx
  nopl   0x0(%rax,%rax,1)
L183:
  movzbl (%rcx),%eax
  sub    $0x1,%rcx
  lea    (%rax,%rax,4),%eax
  add    %eax,%eax
  mov    %al,0x1(%rcx)
  mov    %rsi,%rax
  sub    %rcx,%rax
  cmp    %rax,%r13
  ja     L183
  movzbl (%rsi),%eax
  movzbl (%rdi),%ecx
  lea    -0x30(%rax,%rcx,1),%eax
  mov    %al,(%rsi)
  cs nopw 0x0(%rax,%rax,1)
L47:
  movzbl (%rdx),%eax
  cmp    $0xf,%al
  jbe    L199
  mov    %eax,%ecx
  and    $0xf,%eax
  shr    $0x4,%cl
  add    %cl,-0x1(%rdx)
  mov    %al,(%rdx)
L199:
  sub    $0x1,%rdx
  mov    %rsi,%rax
  sub    %rdx,%rax
  cmp    %rax,%r13
  ja     L47
  add    $0x1,%rdi
  cmp    %r8,%rdi
  jne    L49
L134:
  xor    %r14d,%r14d
  nop
L325:
  movsbl 0x2(%r12,%r14,1),%edi
  call   <nibble_to_hex@plt>
  mov    %al,0x2(%r12,%r14,1)
  add    $0x1,%r14
  cmp    %r14,%r13
  ja     L325
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L250:
  cmpb   $0x30,0x2(%r12,%rax,1)
  jne    L236
  add    $0x1,%rax
  cmp    %rax,%r13
  ja     L250
L236:
  test   $0x1,%al
  je     L181
  lea    0x1(%rax),%r15
  mov    %rax,%r14
  cmp    %r15,%r13
  ja     L167
L232:
  sub    %r14,%r13
  je     L160
  lea    -0x1(%r13),%rax
  cmp    $0x6,%rax
  jbe    L17
  cmp    $0xfffffffffffffff0,%r14
  ja     L17
  cmp    $0xe,%rax
  jbe    L297
  mov    %r13,%rdx
  lea    0x2(%r12,%r14,1),%rcx
  xor    %eax,%eax
  and    $0xfffffffffffffff0,%rdx
  nopw   0x0(%rax,%rax,1)
L157:
  movdqu (%rcx,%rax,1),%xmm0
  movups %xmm0,0x2(%r12,%rax,1)
  add    $0x10,%rax
  cmp    %rdx,%rax
  jne    L157
  mov    %r13,%rax
  and    $0xfffffffffffffff0,%rax
  test   $0xf,%r13b
  je     L160
  mov    %r13,%rdx
  sub    %rax,%rdx
  lea    -0x1(%rdx),%rcx
  cmp    $0x6,%rcx
  jbe    L152
L25:
  lea    (%r12,%r14,1),%rcx
  mov    0x2(%rax,%rcx,1),%rcx
  mov    %rcx,0x2(%r12,%rax,1)
  mov    %rdx,%rcx
  and    $0xfffffffffffffff8,%rcx
  add    %rcx,%rax
  cmp    %rdx,%rcx
  je     L160
L152:
  add    %r14,%rbp
  movzbl 0x0(%rbp,%rax,1),%edx
  mov    %dl,0x2(%r12,%rax,1)
  lea    0x1(%rax),%rdx
  cmp    %rdx,%r13
  jbe    L160
  movzbl 0x1(%rax,%rbp,1),%ecx
  lea    0x2(%rax),%rdx
  mov    %cl,0x3(%r12,%rax,1)
  cmp    %rdx,%r13
  jbe    L160
  movzbl 0x2(%rax,%rbp,1),%ecx
  lea    0x3(%rax),%rdx
  mov    %cl,0x4(%r12,%rax,1)
  cmp    %rdx,%r13
  jbe    L160
  movzbl 0x3(%rax,%rbp,1),%ecx
  lea    0x4(%rax),%rdx
  mov    %cl,0x5(%r12,%rax,1)
  cmp    %rdx,%r13
  jbe    L160
  movzbl 0x4(%rax,%rbp,1),%ecx
  lea    0x5(%rax),%rdx
  mov    %cl,0x6(%r12,%rax,1)
  cmp    %rdx,%r13
  jbe    L160
  movzbl 0x5(%rax,%rbp,1),%ecx
  mov    %cl,0x7(%r12,%rax,1)
  add    $0x6,%rax
  cmp    %rax,%r13
  jbe    L160
  movzbl 0x0(%rbp,%rax,1),%edx
  mov    %dl,0x2(%r12,%rax,1)
L160:
  sub    $0x1,%rbx
  mov    %r12,%rax
  sub    %r14,%rbx
  movb   $0x0,(%r12,%rbx,1)
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L121:
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L181:
  mov    %rax,%r15
  lea    -0x1(%rax),%r14
  cmp    %r15,%r13
  jbe    L232
L167:
  movzbl 0x2(%r12,%r14,1),%edi
  call   <hex_to_nibble@plt>
  movzbl 0x2(%r12,%r15,1),%edi
  shl    $0x4,%eax
  mov    %al,0xf(%rsp)
  call   <hex_to_nibble@plt>
  lea    -0x2(%r14),%rdx
  add    0xf(%rsp),%al
  cmovs  %rdx,%r14
  jmp    L232
L228:
  movb   $0x0,(%r12)
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L17:
  add    %rbp,%r13
  nop
L92:
  movzbl 0x0(%rbp,%r14,1),%eax
  add    $0x1,%rbp
  mov    %al,-0x1(%rbp)
  cmp    %rbp,%r13
  jne    L92
  jmp    L160
L297:
  mov    %r13,%rdx
  xor    %eax,%eax
  jmp    L25
```

assistant: ```c
char *decimal_to_hex(const char *dec_str, size_t dec_len, char *buf, size_t buf_len) {
  size_t i, j, k, hex_len;
  unsigned char *hex_buf, byte;
  if (dec_str == 0 || buf == 0 || buf_len < 5) {
    return NULL;
  }
  buf[0] = '0';
  buf[1] = 'x';
  hex_buf = (unsigned char *)buf + 2;
  hex_len = buf_len - 3;
  for (i = 0; i < hex_len; ++i) {
    hex_buf[i] = '\0';
  }
  for (i = 0; i < dec_len && dec_str[i] != '\0'; ++i) {
    if (dec_str[i] < '0' || dec_str[i] > '9') {
      buf[0] = '\0';
      return NULL;
    }
    for (j = 0; j < hex_len; ++j) {
      k = hex_len - 1 - j;
      hex_buf[k] *= 10;
    }
    hex_buf[hex_len - 1] += (dec_str[i] - '0');
    for (j = 0; j < hex_len; ++j) {
      k = hex_len - 1 - j;
      if (hex_buf[k] >= 16) {
        hex_buf[k - 1] += (hex_buf[k] / 16);
        hex_buf[k] = (hex_buf[k] % 16);
      }
    }
  }
  for (j = 0; j < hex_len; ++j) {
    hex_buf[j] = nibble_to_hex(buf[2 + j]);
  }
  for (j = 0; j < hex_len && hex_buf[j] == '0'; ++j) {
    ;
  }
  if (j % 2 == 0) {
    j -= 1;
  }
  if (j + 1 < hex_len) {
    byte = 0;
    byte = hex_to_nibble(hex_buf[j]) << 4;
    byte += hex_to_nibble(hex_buf[j + 1]);
    if (byte > 0x7F) {
      j -= 2;
    }
  }
  for (i = 0; i < (hex_len - j); ++i) {
    hex_buf[i] = hex_buf[i + j];
  }
  buf[buf_len - 1 - j] = '\0';
  return buf;
}
```