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

```asm
<conv_to_utf8>:
  endbr64
  mov    %rdi,%rcx
  mov    %esi,%eax
  xor    %r8d,%r8d
  cmp    $0x7f,%esi
  ja     L70
  test   %edx,%edx
  jne    L158
L81:
  mov    %r8d,%eax
  ret
  nopl   (%rax)
L70:
  cmp    $0x7ff,%esi
  ja     L75
  cmp    $0x1,%edx
  jbe    L81
  test   %rdi,%rdi
  je     L74
  mov    %esi,%edx
  shr    $0x6,%al
  and    $0x3f,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x1(%rdi)
  mov    %esi,%edx
  shr    $0x8,%edx
  shl    $0x2,%edx
  or     %edx,%eax
  or     $0xffffffc0,%eax
  mov    %al,(%rdi)
L74:
  mov    $0x2,%r8d
  mov    %r8d,%eax
  ret
  nopl   0x0(%rax)
L75:
  cmp    $0xffff,%esi
  ja     L93
  cmp    $0x2,%edx
  jbe    L81
  test   %rdi,%rdi
  je     L52
  mov    %esi,%edx
  shr    $0x8,%esi
  and    $0x3f,%edx
  shr    $0x6,%al
  or     $0xffffff80,%edx
  mov    %dl,0x2(%rdi)
  lea    0x0(,%rsi,4),%edx
  shr    $0x4,%sil
  and    $0x3c,%edx
  or     $0xffffffe0,%esi
  or     %edx,%eax
  mov    %sil,(%rdi)
  or     $0xffffff80,%eax
  mov    %al,0x1(%rdi)
L52:
  mov    $0x3,%r8d
  mov    %r8d,%eax
  ret
  nopl   0x0(%rax)
L158:
  test   %rdi,%rdi
  je     L41
  mov    %sil,(%rcx)
L41:
  mov    $0x1,%r8d
  mov    %r8d,%eax
  ret
  nopw   0x0(%rax,%rax,1)
L93:
  cmp    $0x1fffff,%esi
  jbe    L141
  cmp    $0x3ffffff,%esi
  ja     L128
  cmp    $0x4,%edx
  jbe    L81
  test   %rdi,%rdi
  je     L131
  mov    %esi,%edx
  and    $0x3f,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x4(%rdi)
  mov    %esi,%edi
  shr    $0x6,%sil
  shr    $0x8,%edi
  lea    0x0(,%rdi,4),%edx
  shr    $0x4,%dil
  and    $0x3c,%edx
  or     %esi,%edx
  mov    %eax,%esi
  shr    $0x18,%eax
  or     $0xffffff80,%edx
  shr    $0x10,%esi
  or     $0xfffffff8,%eax
  mov    %dl,0x3(%rcx)
  mov    %esi,%edx
  shr    $0x2,%sil
  shl    $0x4,%edx
  or     $0xffffff80,%esi
  mov    %al,(%rcx)
  and    $0x30,%edx
  mov    %sil,0x1(%rcx)
  or     %edi,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x2(%rcx)
L131:
  mov    $0x5,%r8d
  mov    %r8d,%eax
  ret
  nopw   0x0(%rax,%rax,1)
L141:
  cmp    $0x3,%edx
  jbe    L81
  test   %rdi,%rdi
  je     L129
  mov    %esi,%edx
  shr    $0x8,%esi
  and    $0x3f,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x3(%rdi)
  lea    0x0(,%rsi,4),%edx
  mov    %eax,%edi
  shr    $0x10,%eax
  shr    $0x6,%dil
  and    $0x3c,%edx
  shr    $0x4,%sil
  or     %edi,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x2(%rcx)
  mov    %eax,%edx
  sar    $0x2,%eax
  shl    $0x4,%edx
  or     $0xfffffff0,%eax
  and    $0x30,%edx
  mov    %al,(%rcx)
  or     %esi,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x1(%rcx)
L129:
  mov    $0x4,%r8d
  mov    %r8d,%eax
  ret
  nopl   (%rax)
L128:
  cmp    $0x5,%edx
  jbe    L81
  test   %rdi,%rdi
  je     L12
  mov    %esi,%edx
  and    $0x3f,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x5(%rdi)
  mov    %esi,%edi
  shr    $0x6,%sil
  shr    $0x8,%edi
  lea    0x0(,%rdi,4),%edx
  shr    $0x4,%dil
  and    $0x3c,%edx
  or     %esi,%edx
  mov    %eax,%esi
  shr    $0x18,%eax
  or     $0xffffff80,%edx
  shr    $0x10,%esi
  mov    %dl,0x4(%rcx)
  mov    %esi,%edx
  shr    $0x2,%sil
  shl    $0x4,%edx
  or     $0xffffff80,%esi
  and    $0x30,%edx
  mov    %sil,0x2(%rcx)
  or     %edi,%edx
  or     $0xffffff80,%edx
  mov    %dl,0x3(%rcx)
  mov    %eax,%edx
  sar    $0x6,%eax
  and    $0x3f,%edx
  and    $0x1,%eax
  or     $0xffffff80,%edx
  or     $0xfffffffc,%eax
  mov    %dl,0x1(%rcx)
  mov    %al,(%rcx)
L12:
  mov    $0x6,%r8d
  mov    %r8d,%eax
  ret
```

assistant: ```c
int conv_to_utf8(unsigned char *target, unsigned source, unsigned limit) {
  int rc = 0;
  if (source <= 0x0000007f)
    rc = 1;
  else if (source <= 0x000007ff)
    rc = 2;
  else if (source <= 0x0000ffff)
    rc = 3;
  else if (source <= 0x001fffff)
    rc = 4;
  else if (source <= 0x03ffffff)
    rc = 5;
  else
    rc = 6;
  if ((unsigned)rc > limit) {
    rc = 0;
  }
  if (target != 0) {
    switch (rc) {
    case 1:
      target[0] = ((unsigned char)((source) >> ((0) * 8)));
      break;
    case 2:
      target[1] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) & 0x3f)));
      target[0] = ((unsigned char)(0xc0 | (((unsigned char)((source) >> ((0) * 8))) >> 6) | ((((unsigned char)((source) >> ((1) * 8))) & 0x07) << 2)));
      break;
    case 3:
      target[2] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) & 0x3f)));
      target[1] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) >> 6) | ((((unsigned char)((source) >> ((1) * 8))) & 0x0f) << 2)));
      target[0] = ((unsigned char)(0xe0 | ((int)(((unsigned char)((source) >> ((1) * 8))) & 0xf0) >> 4)));
      break;
    case 4:
      target[3] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) & 0x3f)));
      target[2] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) >> 6) | ((((unsigned char)((source) >> ((1) * 8))) & 0x0f) << 2)));
      target[1] = ((unsigned char)(0x80 | ((int)(((unsigned char)((source) >> ((1) * 8))) & 0xf0) >> 4) | ((int)(((unsigned char)((source) >> ((2) * 8))) & 0x03) << 4)));
      target[0] = ((unsigned char)(0xf0 | ((int)(((unsigned char)((source) >> ((2) * 8))) & 0x1f) >> 2)));
      break;
    case 5:
      target[4] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) & 0x3f)));
      target[3] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) >> 6) | ((((unsigned char)((source) >> ((1) * 8))) & 0x0f) << 2)));
      target[2] = ((unsigned char)(0x80 | ((int)(((unsigned char)((source) >> ((1) * 8))) & 0xf0) >> 4) | ((int)(((unsigned char)((source) >> ((2) * 8))) & 0x03) << 4)));
      target[1] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((2) * 8))) >> 2)));
      target[0] = ((unsigned char)(0xf8 | (((unsigned char)((source) >> ((3) * 8))) & 0x03)));
      break;
    case 6:
      target[5] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) & 0x3f)));
      target[4] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((0) * 8))) >> 6) | ((((unsigned char)((source) >> ((1) * 8))) & 0x0f) << 2)));
      target[3] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((1) * 8))) >> 4) | ((((unsigned char)((source) >> ((2) * 8))) & 0x03) << 4)));
      target[2] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((2) * 8))) >> 2)));
      target[1] = ((unsigned char)(0x80 | (((unsigned char)((source) >> ((3) * 8))) & 0x3f)));
      target[0] = ((unsigned char)(0xfc | ((int)(((unsigned char)((source) >> ((3) * 8))) & 0x40) >> 6)));
      break;
    }
  }
  return rc;
}
```