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

```asm
<d_to_h>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %esi,-0x48(%rbp)
  mov    %edx,-0x4c(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x23,-0x30(%rbp)
  mov    -0x44(%rbp),%eax
  mov    %eax,-0x38(%rbp)
  movl   $0x2,-0x3c(%rbp)
  jmp    L8
L95:
  mov    -0x38(%rbp),%eax
  cltd
  shr    $0x1c,%edx
  add    %edx,%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,-0x34(%rbp)
  cmpl   $0x9,-0x34(%rbp)
  jg     L127
  addl   $0x30,-0x34(%rbp)
  jmp    L114
L127:
  addl   $0x57,-0x34(%rbp)
L114:
  mov    -0x3c(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x3c(%rbp)
  cltq
  mov    -0x34(%rbp),%edx
  mov    %edx,-0x30(%rbp,%rax,4)
  mov    -0x38(%rbp),%eax
  lea    0xf(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x4,%eax
  mov    %eax,-0x38(%rbp)
L8:
  cmpl   $0x0,-0x38(%rbp)
  jne    L95
  mov    -0x48(%rbp),%eax
  mov    %eax,-0x38(%rbp)
  movl   $0x4,-0x3c(%rbp)
  jmp    L39
L109:
  mov    -0x38(%rbp),%eax
  cltd
  shr    $0x1c,%edx
  add    %edx,%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,-0x34(%rbp)
  cmpl   $0x9,-0x34(%rbp)
  jg     L148
  addl   $0x30,-0x34(%rbp)
  jmp    L104
L148:
  addl   $0x57,-0x34(%rbp)
L104:
  mov    -0x3c(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x3c(%rbp)
  cltq
  mov    -0x34(%rbp),%edx
  mov    %edx,-0x30(%rbp,%rax,4)
  mov    -0x38(%rbp),%eax
  lea    0xf(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x4,%eax
  mov    %eax,-0x38(%rbp)
L39:
  cmpl   $0x0,-0x38(%rbp)
  jne    L109
  mov    -0x4c(%rbp),%eax
  mov    %eax,-0x38(%rbp)
  movl   $0x6,-0x3c(%rbp)
  jmp    L122
L32:
  mov    -0x38(%rbp),%eax
  cltd
  shr    $0x1c,%edx
  add    %edx,%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,-0x34(%rbp)
  cmpl   $0x9,-0x34(%rbp)
  jg     L123
  addl   $0x30,-0x34(%rbp)
  jmp    L98
L123:
  addl   $0x57,-0x34(%rbp)
L98:
  mov    -0x3c(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x3c(%rbp)
  cltq
  mov    -0x34(%rbp),%edx
  mov    %edx,-0x30(%rbp,%rax,4)
  mov    -0x38(%rbp),%eax
  lea    0xf(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x4,%eax
  mov    %eax,-0x38(%rbp)
L122:
  cmpl   $0x0,-0x38(%rbp)
  jne    L32
  movl   $0x0,-0x3c(%rbp)
  jmp    L78
L68:
  mov    -0x3c(%rbp),%eax
  cltq
  mov    -0x30(%rbp,%rax,4),%eax
  mov    %eax,%edi
  call   <putchar@plt>
  addl   $0x1,-0x3c(%rbp)
L78:
  cmpl   $0x6,-0x3c(%rbp)
  jle    L68
  lea    D2(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  mov    $0x0,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L71
  call   <__stack_chk_fail@plt>
L71:
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D2
datatype: string

tool: D2: 


assistant: ```c
int d_to_h(int r, int g, int b) {
  int final[7];
  int i, temp, temp1;
  final[0] = '#';
  temp = r;
  i = 2;
  while (temp != 0) {
    temp1 = temp % 16;
    if (temp1 < 10)
      temp1 += 48;
    else
      temp1 += 87;
    final[i--] = temp1;
    temp = temp / 16;
  }
  temp = g;
  i = 4;
  while (temp != 0) {
    temp1 = temp % 16;
    if (temp1 < 10)
      temp1 += 48;
    else
      temp1 += 87;
    final[i--] = temp1;
    temp = temp / 16;
  }
  temp = b;
  i = 6;
  while (temp != 0) {
    temp1 = temp % 16;
    if (temp1 < 10)
      temp1 += 48;
    else
      temp1 += 87;
    final[i--] = temp1;
    temp = temp / 16;
  }
  for (i = 0; i < 7; i++) {
    printf("%c", final[i]);
  }
  printf("\n\n");
  return 0;
}
```