user: What would the C source look like for the assembly code provided here:

```asm
<hex2passwd>:
  endbr64
  push   %r15
  mov    %ecx,%eax
  push   %r14
  sar    $0x4,%eax
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    $0x4,%ebx
  sub    $0x38,%rsp
  and    $0x10,%ecx
  mov    %rdi,(%rsp)
  mov    %esi,0x8(%rsp)
  mov    %rdx,0x10(%rsp)
  mov    %r8d,0xc(%rsp)
  jne    L22
  nopl   0x0(%rax,%rax,1)
L49:
  sar    %eax
  add    $0x1,%ebx
  test   $0x1,%al
  je     L49
L22:
  mov    0x8(%rsp),%r15d
  mov    $0x1,%esi
  mov    $0x8,%r13d
  xor    %ebp,%ebp
  sub    %ebx,%r13d
  lea    0x0(,%r15,8),%eax
  cltd
  idiv   %ebx
  lea    0x1(%rax),%edi
  mov    %eax,0x2c(%rsp)
  call   <calloc@plt>
  mov    %ebx,%r8d
  mov    %rax,0x18(%rsp)
  mov    %rax,%r12
  test   %r15d,%r15d
  jg     L66
  jmp    L106
  nopw   0x0(%rax,%rax,1)
L89:
  mov    0xc(%rsp),%r10d
  test   %r10d,%r10d
  jne    L37
  movzbl (%r14),%eax
  mov    %r13d,%ecx
  mov    0x10(%rsp),%rdi
  add    %ebx,%r8d
  sar    %cl,%eax
  shl    %cl,%eax
  sar    %cl,%eax
  movzbl %al,%eax
  movzbl (%rdi,%rax,1),%eax
  mov    %al,(%r12)
L2:
  add    $0x1,%ebp
  sub    $0x8,%r8d
  add    $0x1,%r12
  cmp    0x8(%rsp),%ebp
  jge    L106
L66:
  mov    (%rsp),%rdi
  movslq %ebp,%rax
  lea    (%rdi,%rax,1),%r14
  movzbl (%r14),%r9d
  cmp    %r8d,%ebx
  jle    L89
  lea    -0x1(%rdi,%rax,1),%r15
  mov    %ebx,%esi
  mov    0xc(%rsp),%edi
  mov    $0x8,%r10d
  sub    %r8d,%esi
  mov    $0x8,%r11d
  movzbl (%r15),%edx
  sub    %esi,%r10d
  sub    %r8d,%r11d
  test   %edi,%edi
  jne    L12
  mov    %r11d,%ecx
  mov    0x10(%rsp),%rax
  sar    %cl,%r9d
  mov    %r13d,%ecx
  shl    %cl,%r9d
  sar    %cl,%r9d
  mov    %r10d,%ecx
  shl    %cl,%edx
  mov    %r13d,%ecx
  movzbl %dl,%edx
  sar    %cl,%edx
  add    %edx,%r9d
  movzbl %r9b,%r9d
  movzbl (%rax,%r9,1),%eax
  mov    %al,(%r12)
L85:
  add    %ebx,%r8d
  cmp    $0x7,%r8d
  jg     L2
  add    $0x1,%r12
  cmp    0x8(%rsp),%ebp
  jl     L66
L106:
  mov    0x18(%rsp),%rbx
  movslq 0x2c(%rsp),%rax
  movb   $0x0,(%rbx,%rax,1)
  add    $0x38,%rsp
  mov    %rbx,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L37:
  movzbl %r9b,%edx
  movzbl %bl,%esi
  lea    D24(%rip),%rdi
  xor    %eax,%eax
  mov    %edx,%ecx
  mov    %r8d,0x20(%rsp)
  call   <printf@plt>
  movzbl (%r14),%eax
  mov    %r13d,%ecx
  mov    0x10(%rsp),%rdi
  mov    0x20(%rsp),%r8d
  sar    %cl,%eax
  shl    %cl,%eax
  sar    %cl,%eax
  mov    %eax,%esi
  movzbl %al,%eax
  movzbl (%rdi,%rax,1),%edx
  mov    %dl,(%r12)
L110:
  movzbl %sil,%esi
  mov    %edx,%ecx
  lea    D13(%rip),%rdi
  xor    %eax,%eax
  mov    %r8d,0x20(%rsp)
  call   <printf@plt>
  mov    0x20(%rsp),%r8d
  jmp    L85
  nopl   0x0(%rax,%rax,1)
L12:
  mov    %r11d,0x28(%rsp)
  sub    $0x8,%rsp
  mov    %edx,%ecx
  movzbl %sil,%esi
  mov    %r10d,0x2c(%rsp)
  lea    D48(%rip),%rdi
  xor    %eax,%eax
  push   %r9
  mov    %r8d,0x30(%rsp)
  call   <printf@plt>
  mov    0x38(%rsp),%r11d
  movzbl (%r14),%esi
  xor    %eax,%eax
  lea    D15(%rip),%rdi
  mov    %r11d,%ecx
  sar    %cl,%esi
  mov    %r13d,%ecx
  shl    %cl,%esi
  sar    %cl,%esi
  mov    %esi,%r14d
  movzbl %sil,%esi
  call   <printf@plt>
  mov    0x34(%rsp),%r10d
  movzbl (%r15),%r15d
  xor    %eax,%eax
  lea    D1(%rip),%rdi
  mov    %r10d,%ecx
  shl    %cl,%r15d
  mov    %r13d,%ecx
  movzbl %r15b,%r15d
  sar    %cl,%r15d
  mov    %r15d,%esi
  call   <printf@plt>
  mov    0x20(%rsp),%rdi
  lea    (%r14,%r15,1),%esi
  movzbl %sil,%eax
  movzbl (%rdi,%rax,1),%edx
  mov    %dl,(%r12)
  pop    %rax
  pop    %rcx
  mov    0x20(%rsp),%r8d
  jmp    L110
```

tool_calls: name: read_data
arguments: data_label: D24
datatype: string
name: read_data
arguments: data_label: D13
datatype: string
name: read_data
arguments: data_label: D48
datatype: string
name: read_data
arguments: data_label: D15
datatype: string
name: read_data
arguments: data_label: D1
datatype: string

tool: D24: DEBUG - Value is first %d bits of '%c' (%d)


tool: D13: DEBUG - Value %d maps to character '%c' (%d)


tool: D48: DEBUG - Value is last %d bits of '%c' (%d) and first %d bits of '%c' (%d)


tool: D15: DEBUG - Intermediate value is %d


tool: D1: DEBUG - Intermediate othervalue is %d


assistant: ```c
unsigned char *hex2passwd(unsigned char *hex, int len, unsigned char *mapping, int mappinglength, int dflag) {
  int charpos = 0;
  int bitpos = 0;
  int numbits = 4;
  int length = mappinglength >> 4;
  unsigned char value = 0;
  unsigned char othervalue = 0;
  int outpos = 0;
  while ((length & 0x01) == 0x00) {
    length >>= 1;
    numbits++;
  }
  bitpos = numbits;
  unsigned char *out = calloc(len * 8 / numbits + 1, sizeof(char));
  while (charpos < len) {
    if (bitpos >= numbits) {
      if (dflag)
        printf("DEBUG - Value is first %d bits of '%c' (%d)\n", numbits, hex[charpos], hex[charpos]);
      value = (hex[charpos] >> (8 - numbits));
      value = (value << (8 - numbits)) >> (8 - numbits);
    } else {
      if (dflag)
        printf("DEBUG - Value is last %d bits of '%c' (%d) and first %d bits of '%c' (%d)\n", numbits - bitpos, hex[charpos - 1], hex[charpos - 1], bitpos, hex[charpos], hex[charpos]);
      value = (hex[charpos] >> (8 - bitpos));
      value = (value << (8 - numbits)) >> (8 - numbits);
      if (dflag)
        printf("DEBUG - Intermediate value is %d\n", value);
      othervalue = hex[charpos - 1] << (8 - (numbits - bitpos));
      othervalue = othervalue >> (8 - numbits);
      if (dflag)
        printf("DEBUG - Intermediate othervalue is %d\n", othervalue);
      value = value + othervalue;
    }
    out[outpos] = mapping[value];
    if (dflag)
      printf("DEBUG - Value %d maps to character '%c' (%d)\n", value, out[outpos], out[outpos]);
    bitpos += numbits;
    if (bitpos >= 8) {
      charpos++;
      bitpos -= 8;
    }
    outpos++;
  };
  out[len * 8 / numbits] = 0x00;
  return out;
}
```