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

```asm
<main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x30(%rbp)
  movl   $0x0,-0x2c(%rbp)
  movl   $0x0,-0x28(%rbp)
  movl   $0x0,-0x24(%rbp)
  movl   $0x0,-0x1c(%rbp)
  movl   $0x1,-0x18(%rbp)
  lea    -0x32(%rbp),%rax
  mov    %rax,%rsi
  lea    D38(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  movzbl -0x32(%rbp),%eax
  cmp    $0x64,%al
  jne    L149
  lea    -0x28(%rbp),%rcx
  lea    -0x2c(%rbp),%rdx
  lea    -0x30(%rbp),%rax
  mov    %rax,%rsi
  lea    D48(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  mov    -0x28(%rbp),%eax
  test   %eax,%eax
  jne    L249
  mov    -0x1c(%rbp),%eax
  cltq
  movb   $0x30,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  cltq
  movb   $0x30,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  jmp    L249
L125:
  mov    -0x28(%rbp),%eax
  cltd
  shr    $0x1c,%edx
  add    %edx,%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,-0x14(%rbp)
  cmpl   $0x0,-0x14(%rbp)
  js     L160
  cmpl   $0x9,-0x14(%rbp)
  jg     L160
  mov    -0x14(%rbp),%eax
  add    $0x30,%eax
  mov    %al,-0x31(%rbp)
  jmp    L186
L160:
  mov    -0x14(%rbp),%eax
  add    $0x57,%eax
  mov    %al,-0x31(%rbp)
L186:
  mov    -0x1c(%rbp),%eax
  cltq
  movzbl -0x31(%rbp),%edx
  mov    %dl,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  mov    -0x28(%rbp),%eax
  lea    0xf(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x4,%eax
  mov    %eax,-0x28(%rbp)
L249:
  mov    -0x28(%rbp),%eax
  test   %eax,%eax
  jne    L125
  mov    -0x2c(%rbp),%eax
  test   %eax,%eax
  jne    L247
  mov    -0x1c(%rbp),%eax
  cltq
  movb   $0x30,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  cltq
  movb   $0x30,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  jmp    L247
L274:
  mov    -0x2c(%rbp),%eax
  cltd
  shr    $0x1c,%edx
  add    %edx,%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,-0x14(%rbp)
  cmpl   $0x0,-0x14(%rbp)
  js     L33
  cmpl   $0x9,-0x14(%rbp)
  jg     L33
  mov    -0x14(%rbp),%eax
  add    $0x30,%eax
  mov    %al,-0x31(%rbp)
  jmp    L189
L33:
  mov    -0x14(%rbp),%eax
  add    $0x57,%eax
  mov    %al,-0x31(%rbp)
L189:
  mov    -0x1c(%rbp),%eax
  cltq
  movzbl -0x31(%rbp),%edx
  mov    %dl,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  mov    -0x2c(%rbp),%eax
  lea    0xf(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x4,%eax
  mov    %eax,-0x2c(%rbp)
L247:
  mov    -0x2c(%rbp),%eax
  test   %eax,%eax
  jne    L274
  mov    -0x30(%rbp),%eax
  test   %eax,%eax
  jne    L36
  mov    -0x1c(%rbp),%eax
  cltq
  movb   $0x30,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  cltq
  movb   $0x30,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  jmp    L36
L256:
  mov    -0x30(%rbp),%eax
  cltd
  shr    $0x1c,%edx
  add    %edx,%eax
  and    $0xf,%eax
  sub    %edx,%eax
  mov    %eax,-0x14(%rbp)
  cmpl   $0x0,-0x14(%rbp)
  js     L286
  cmpl   $0x9,-0x14(%rbp)
  jg     L286
  mov    -0x14(%rbp),%eax
  add    $0x30,%eax
  mov    %al,-0x31(%rbp)
  jmp    L7
L286:
  mov    -0x14(%rbp),%eax
  add    $0x57,%eax
  mov    %al,-0x31(%rbp)
L7:
  mov    -0x1c(%rbp),%eax
  cltq
  movzbl -0x31(%rbp),%edx
  mov    %dl,-0xf(%rbp,%rax,1)
  addl   $0x1,-0x1c(%rbp)
  mov    -0x30(%rbp),%eax
  lea    0xf(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x4,%eax
  mov    %eax,-0x30(%rbp)
L36:
  mov    -0x30(%rbp),%eax
  test   %eax,%eax
  jne    L256
  mov    $0x23,%edi
  call   <putchar@plt>
  movl   $0x6,-0x1c(%rbp)
  jmp    L128
L164:
  mov    -0x1c(%rbp),%eax
  cltq
  movzbl -0xf(%rbp,%rax,1),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <putchar@plt>
  subl   $0x1,-0x1c(%rbp)
L128:
  cmpl   $0x0,-0x1c(%rbp)
  jns    L164
  jmp    L254
L149:
  movzbl -0x32(%rbp),%eax
  cmp    $0x68,%al
  jne    L254
  lea    -0xf(%rbp),%rax
  mov    %rax,%rsi
  lea    D14(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  lea    D1(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  movl   $0x1,-0x20(%rbp)
  jmp    L113
L38:
  mov    -0x20(%rbp),%eax
  cltq
  movzbl -0xf(%rbp,%rax,1),%eax
  mov    %al,-0x31(%rbp)
  cmpb   $0x2f,-0x31(%rbp)
  jle    L51
  cmpb   $0x39,-0x31(%rbp)
  jg     L51
  movsbl -0x31(%rbp),%eax
  sub    $0x30,%eax
  mov    %eax,-0x14(%rbp)
  jmp    L269
L51:
  movsbl -0x31(%rbp),%eax
  sub    $0x57,%eax
  mov    %eax,-0x14(%rbp)
L269:
  mov    -0x18(%rbp),%eax
  mov    %eax,%esi
  mov    $0x10,%edi
  call   <pow@plt>
  imul   -0x14(%rbp),%eax
  add    %eax,-0x24(%rbp)
  cmpl   $0x0,-0x18(%rbp)
  jne    L105
  mov    -0x24(%rbp),%eax
  mov    %eax,%esi
  lea    D65(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  cmpl   $0x6,-0x20(%rbp)
  je     L71
  lea    D62(%rip),%rax
  mov    %rax,%rsi
  lea    D14(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L94
L71:
  mov    $0x29,%edi
  call   <putchar@plt>
L94:
  movl   $0x0,-0x24(%rbp)
  movl   $0x1,-0x18(%rbp)
  jmp    L172
L105:
  subl   $0x1,-0x18(%rbp)
L172:
  addl   $0x1,-0x20(%rbp)
L113:
  cmpl   $0x6,-0x20(%rbp)
  jle    L38
L254:
  mov    $0x0,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L258
  call   <__stack_chk_fail@plt>
L258:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: tag: D38
type_infered: string
name: retrieve_data
arguments: tag: D48
type_infered: string
name: retrieve_data
arguments: tag: D14
type_infered: string
name: retrieve_data
arguments: tag: D1
type_infered: string
name: retrieve_data
arguments: tag: D65
type_infered: string
name: retrieve_data
arguments: tag: D62
type_infered: string

tool: D38: %c

tool: D48: %d, %d, %d

tool: D14: %s

tool: D1: rgb(

tool: D65: %d

tool: D62: , 

assistant: ```c
int main() {
  char ch, hex;
  char s[7];
  int a = 0, b = 0, c = 0, dec = 0, i, j = 0, power = 1, digit;
  scanf("%c", &ch);
  if (ch == 'd') {
    scanf("%d, %d, %d", &a, &b, &c);
    if (c == 0) {
      s[j] = 0 + 48;
      j++;
      s[j] = 0 + 48;
      j++;
    }
    while (c != 0) {
      digit = c % 16;
      if (digit >= 0 && digit <= 9) {
        hex = digit + 48;
      } else {
        hex = digit + 87;
      }
      s[j] = hex;
      j++;
      c = c / 16;
    }
    if (b == 0) {
      s[j] = 0 + 48;
      j++;
      s[j] = 0 + 48;
      j++;
    }
    while (b != 0) {
      digit = b % 16;
      if (digit >= 0 && digit <= 9) {
        hex = digit + 48;
      } else {
        hex = digit + 87;
      }
      s[j] = hex;
      j++;
      b = b / 16;
    }
    if (a == 0) {
      s[j] = 0 + 48;
      j++;
      s[j] = 0 + 48;
      j++;
    }
    while (a != 0) {
      digit = a % 16;
      if (digit >= 0 && digit <= 9) {
        hex = digit + 48;
      } else {
        hex = digit + 87;
      }
      s[j] = hex;
      j++;
      a = a / 16;
    }
    printf("%s", "#");
    for (j = 6; j >= 0; j--) {
      printf("%c", s[j]);
    }
  } else if (ch == 'h') {
    scanf("%s", s);
    printf("rgb(");
    for (i = 1; i < 7; i++) {
      hex = s[i];
      if (hex >= '0' && hex <= '9') {
        digit = hex - 48;
      } else {
        digit = hex - 87;
      }
      dec += digit * pow(16, power);
      if (power == 0) {
        printf("%d", dec);
        if (i != 6) {
          printf("%s", ", ");
        } else {
          printf("%s", ")");
        }
        dec = 0;
        power = 1;
      } else {
        power--;
      }
    }
  }
  return 0;
}
```