user: Converte this assembly snippet into its equivalent C code:

```asm
<printf>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  mov    %rdi,%r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  movsbl (%rdi),%edi
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  test   %dil,%dil
  je     L171
  lea    0x8(%rbp),%r15
  lea    -0x41(%rbp),%rbx
  nopl   0x0(%rax,%rax,1)
L189:
  cmp    $0x25,%dil
  jne    L52
  movzbl 0x1(%r13),%eax
  lea    0x2(%r13),%r12
  cmp    $0x73,%al
  je     L5
  jg     L164
  cmp    $0x63,%al
  je     L103
  cmp    $0x64,%al
  jne    L55
  mov    (%r15),%edx
  lea    0x4(%r15),%r13
  mov    %rbx,%r14
  nopl   0x0(%rax,%rax,1)
L35:
  movslq %edx,%rax
  mov    %edx,%ecx
  sub    $0x1,%r14
  imul   $0x66666667,%rax,%rax
  sar    $0x1f,%ecx
  sar    $0x22,%rax
  sub    %ecx,%eax
  lea    (%rax,%rax,4),%ecx
  add    %ecx,%ecx
  sub    %ecx,%edx
  add    $0x30,%edx
  mov    %dl,(%r14)
  mov    %eax,%edx
  test   %eax,%eax
  jne    L35
  cmp    %rbx,%r14
  jae    L77
  nopl   0x0(%rax)
L44:
  movsbl (%r14),%edi
  add    $0x1,%r14
  call   <putchar@plt>
  cmp    %rbx,%r14
  jne    L44
L77:
  mov    %r13,%r15
  mov    %r12,%r13
L57:
  movsbl 0x0(%r13),%edi
  test   %dil,%dil
  jne    L189
L171:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L155
  add    $0x28,%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L164:
  cmp    $0x78,%al
  jne    L55
  mov    (%r15),%r13d
  lea    0x4(%r15),%r14
  mov    $0x1c,%r15d
  nopl   (%rax)
L29:
  mov    %r15d,%ecx
  mov    %r13d,%eax
  sar    %cl,%eax
  and    $0xf,%eax
  cmp    $0xa,%eax
  lea    0x37(%rax),%edx
  lea    0x30(%rax),%edi
  cmovge %edx,%edi
  sub    $0x4,%r15d
  call   <putchar@plt>
  cmp    $0xfffffffc,%r15d
  jne    L29
  mov    %r14,%r15
  mov    %r12,%r13
  jmp    L57
  cs nopw 0x0(%rax,%rax,1)
L52:
  add    $0x1,%r13
  call   <putchar@plt>
  jmp    L57
  xchg   %ax,%ax
L5:
  movslq (%r15),%r14
  lea    0x4(%r15),%r13
  movsbl (%r14),%edi
  test   %dil,%dil
  je     L77
  nopl   0x0(%rax)
L183:
  call   <putchar@plt>
  movsbl 0x1(%r14),%edi
  add    $0x1,%r14
  test   %dil,%dil
  jne    L183
  jmp    L77
L55:
  mov    $0x3f,%edi
  mov    %r12,%r13
  call   <putchar@plt>
  jmp    L57
  nopw   0x0(%rax,%rax,1)
L103:
  movsbl (%r15),%edi
  lea    0x4(%r15),%r13
  mov    %r13,%r15
  mov    %r12,%r13
  call   <putchar@plt>
  jmp    L57
L155:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void printf(const char *fmt, ...) {
  int *stack_head = __builtin_frame_address(0);
  stack_head += 2;
  while (*fmt) {
    if (*fmt == '%') {
      fmt++;
      switch (*fmt++) {
      case 'c':
        putchar(*stack_head++);
        break;
      case 's': {
        const char *s = (char *)*stack_head++;
        while (*s) {
          putchar(*s++);
        }
        break;
      }
      case 'x': {
        int num = *stack_head++;
        int shift = 28;
        while (shift >= 0) {
          int hd = (num >> shift) & 0xf;
          if (hd > 9)
            hd += 'A' - 10;
          else
            hd += '0';
          putchar(hd);
          shift -= 4;
        }
        break;
      }
      case 'd': {
        int num = *stack_head++;
        char buf[16];
        char *s = buf + (sizeof(buf) / sizeof(buf[0])) - 1;
        char *e = s;
        do {
          *--s = '0' + num % 10;
        } while (num /= 10);
        while (s < e)
          putchar(*s++);
        break;
      }
      default:
        putchar('?');
      }
    } else {
      putchar(*fmt++);
    }
  }
}
```