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

```asm
<ts_sdt_add_service_descriptor>:
  endbr64
  mov    %r8,%rax
  or     %rcx,%rax
  je     L135
  push   %r15
  mov    %edx,%r15d
  push   %r14
  mov    %esi,%r14d
  push   %r13
  mov    %rdi,%r13
  push   %r12
  push   %rbp
  mov    %rcx,%rbp
  push   %rbx
  mov    %r8,%rbx
  sub    $0x18,%rsp
  test   %rcx,%rcx
  je     L76
  mov    %rcx,%rdi
  call   <strlen@plt>
  lea    0x4(%rax),%r12d
  mov    $0x1,%eax
  test   %rbx,%rbx
  je     L56
L46:
  mov    %rbx,%rdi
  call   <strlen@plt>
  add    $0x1,%eax
L56:
  lea    (%r12,%rax,1),%esi
  cmp    $0x101,%esi
  jg     L107
  mov    $0x1,%edi
  mov    %esi,0xc(%rsp)
  call   <calloc@plt>
  mov    0xc(%rsp),%ecx
  cmp    $0x1,%r15b
  movb   $0x48,(%rax)
  mov    %rax,%r12
  lea    -0x2(%rcx),%eax
  mov    %al,0x1(%r12)
  mov    $0x1,%eax
  adc    $0x0,%al
  mov    %al,0x2(%r12)
  test   %rbp,%rbp
  je     L55
  mov    %rbp,%rdi
  mov    $0x5,%r15d
  call   <strlen@plt>
  mov    0xc(%rsp),%ecx
  mov    %al,0x3(%r12)
  movzbl 0x0(%rbp),%edx
  test   %dl,%dl
  jne    L91
L4:
  test   %rbx,%rbx
  je     L34
  cmpb   $0x0,(%rbx)
  je     L34
  mov    %rbx,%rdi
  mov    %ecx,0xc(%rsp)
  call   <strlen@plt>
  mov    0xc(%rsp),%ecx
  mov    %rax,%r8
  lea    0x1(%r15),%eax
  mov    %r8b,(%r12,%r15,1)
  movzbl (%rbx),%edx
  test   %dl,%dl
  je     L34
  cltq
  sub    %r15,%rbx
  nopl   0x0(%rax)
L111:
  mov    %dl,(%r12,%rax,1)
  add    $0x1,%rax
  movzbl -0x1(%rbx,%rax,1),%edx
  test   %dl,%dl
  jne    L111
L34:
  add    $0x18,%rsp
  mov    %r12,%rdx
  mov    %r14d,%esi
  mov    %r13,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10a0 <ts_sdt_add_stream@plt>
  nopl   (%rax)
L107:
  lea    D2(%rip),%rdi
  call   <ts_LOGf@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L76:
  mov    $0x4,%r12d
  test   %r8,%r8
  jne    L46
  mov    $0x5,%esi
  mov    $0x1,%edi
  call   <calloc@plt>
  mov    %rax,%r12
  mov    $0x348,%eax
  mov    %ax,(%r12)
  test   %r15b,%r15b
  je     L68
  movb   $0x1,0x2(%r12)
  mov    $0x5,%ecx
L55:
  movb   $0x0,0x3(%r12)
  mov    $0x5,%r15d
  jmp    L4
  nopl   0x0(%rax)
L91:
  mov    $0x5,%eax
  nopl   (%rax)
L33:
  mov    %dl,-0x1(%r12,%rax,1)
  movslq %eax,%r15
  add    $0x1,%rax
  movzbl -0x5(%rbp,%rax,1),%edx
  test   %dl,%dl
  jne    L33
  jmp    L4
  nopw   0x0(%rax,%rax,1)
L135:
  xor    %eax,%eax
  ret
  nopl   0x0(%rax,%rax,1)
L68:
  movb   $0x2,0x2(%r12)
  mov    $0x5,%ecx
  jmp    L55
```

tool_calls: name: extract_symbolic_data
arguments: tag: D2
type: string

tool: D2: SDT service_descriptor size > 255 is not supported (%d)!


assistant: ```c
int ts_sdt_add_service_descriptor(struct ts_sdt *sdt, uint16_t service_id, uint8_t video, char *provider_name, char *service_name) {
  char *name;
  if (!service_name && !provider_name)
    return 0;
  int desc_size = 2 + 1;
  desc_size += 1 + (provider_name ? strlen(provider_name) : 0);
  desc_size += 1 + (service_name ? strlen(service_name) : 0);
  if (desc_size > 257) {
    ts_LOGf("SDT service_descriptor size > 255 is not supported (%d)!\n", desc_size);
    return 0;
  }
  int dpos = 0;
  uint8_t *desc = calloc(1, desc_size);
  desc[dpos + 0] = 0x48;
  desc[dpos + 1] = desc_size - 2;
  desc[dpos + 2] = video ? 0x01 : 0x02;
  desc[dpos + 3] = (provider_name ? strlen(provider_name) : 0);
  dpos += 4;
  if (!provider_name || strlen(provider_name) == 0) {
    dpos++;
  } else {
    name = provider_name;
    while (name[0]) {
      desc[dpos++] = name[0];
      name++;
    }
  }
  if (!service_name || strlen(service_name) == 0) {
    dpos++;
  } else {
    desc[dpos++] = (service_name ? strlen(service_name) : 0);
    name = service_name;
    while (name[0]) {
      desc[dpos++] = name[0];
      name++;
    }
  }
  return ts_sdt_add_stream(sdt, service_id, desc, desc_size);
}
```