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

```asm
<vis5d_unlink_slice>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %esi,%ebx
  sub    $0x48,%rsp
  mov    %edi,0xc(%rsp)
  lea    0x10(%rsp),%rsi
  mov    %edx,0x8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  call   <vis5d_get_ctx_numvars@plt>
  cmp    $0x4,%ebx
  jle    L67
  lea    -0x6(%rbx),%edx
  mov    $0xfffffffe,%eax
  cmp    $0x3,%edx
  ja     L32
  mov    $0x2,%eax
L130:
  mov    0x8(%rsp),%r12d
  test   %r12d,%r12d
  js     L45
  cmp    %r12d,%eax
  jle    L45
  mov    0xc(%rsp),%eax
  mov    %ebx,0x18(%rsp)
  mov    %ebx,%ebp
  lea    0x1c(%rsp),%r15
  mov    %r12d,0x1c(%rsp)
  lea    0x18(%rsp),%r14
  lea    0x14(%rsp),%r13
  mov    %eax,0x14(%rsp)
  mov    %eax,0x4(%rsp)
  nopw   0x0(%rax,%rax,1)
L89:
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  call   <follow_slice_link@plt>
  test   %rax,%rax
  je     L137
  mov    0x18(%rsp),%eax
  mov    0x1c(%rsp),%edx
  mov    0x14(%rsp),%ecx
  cmp    %ebx,%eax
  je     L136
  mov    %ecx,0x4(%rsp)
  mov    %edx,%r12d
  mov    %eax,%ebp
  jmp    L89
  nopw   0x0(%rax,%rax,1)
L136:
  cmp    %edx,0x8(%rsp)
  je     L76
  mov    %ecx,0x4(%rsp)
  mov    %edx,%r12d
  mov    %ebx,%ebp
  jmp    L89
  nopl   0x0(%rax)
L76:
  cmp    %ecx,0xc(%rsp)
  je     L137
  mov    %ecx,0x4(%rsp)
  mov    0x8(%rsp),%r12d
  mov    %ebx,%ebp
  jmp    L89
  nopl   0x0(%rax,%rax,1)
L67:
  mov    $0xfffffffe,%eax
  test   %ebx,%ebx
  jg     L94
L32:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L207
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L137:
  mov    0x8(%rsp),%edx
  mov    0xc(%rsp),%edi
  lea    0x28(%rsp),%r15
  mov    %ebx,%esi
  lea    0x20(%rsp),%r14
  lea    0x30(%rsp),%r13
  mov    %r15,%r9
  mov    %r13,%rcx
  mov    %r14,%r8
  call   <vis5d_get_slice_link@plt>
  mov    0x20(%rsp),%rcx
  mov    0x28(%rsp),%rdx
  cmp    %ebx,%ebp
  mov    (%rcx),%eax
  mov    %eax,0x18(%rsp)
  mov    (%rdx),%eax
  mov    %eax,0x1c(%rsp)
  mov    0x30(%rsp),%rax
  mov    (%rax),%esi
  mov    %esi,0x14(%rsp)
  movl   $0xffffffff,(%rcx)
  movl   $0xffffffff,(%rdx)
  movl   $0xffffffff,(%rax)
  setne  %al
  cmp    0x8(%rsp),%r12d
  setne  %dl
  or     %dl,%al
  jne    L183
  mov    0xc(%rsp),%edi
  xor    %eax,%eax
  cmp    %edi,0x4(%rsp)
  je     L32
L183:
  mov    0x4(%rsp),%edi
  mov    %r15,%r9
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %r12d,%edx
  mov    %ebp,%esi
  call   <vis5d_get_slice_link@plt>
  mov    0x18(%rsp),%eax
  cmp    %ebp,%eax
  je     L51
L31:
  mov    0x20(%rsp),%rdx
  mov    %eax,(%rdx)
  mov    0x28(%rsp),%rax
  mov    0x1c(%rsp),%edx
  mov    %edx,(%rax)
  mov    0x30(%rsp),%rax
  mov    0x14(%rsp),%edx
  mov    %edx,(%rax)
  xor    %eax,%eax
  jmp    L32
  xchg   %ax,%ax
L94:
  mov    0x10(%rsp),%eax
  jmp    L130
  nopl   0x0(%rax)
L51:
  cmp    %r12d,0x1c(%rsp)
  jne    L31
  mov    0x4(%rsp),%edi
  cmp    %edi,0x14(%rsp)
  jne    L31
  movl   $0xffffffff,0x14(%rsp)
  mov    $0xffffffff,%eax
  movl   $0xffffffff,0x1c(%rsp)
  jmp    L31
L45:
  mov    $0xfffffffb,%eax
  jmp    L32
L207:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int vis5d_unlink_slice(int vindex, int type, int number) {
  int numvar, nmax;
  int cur_vindex, end_vindex, cur_type, cur_num, end_type, end_num;
  int *p_type, *p_num, *p_vindex;
  vis5d_get_ctx_numvars(vindex, &numvar);
  switch (type) {
  case 1:
  case 2:
  case 3:
  case 4:
    nmax = numvar;
    break;
  case 6:
  case 7:
  case 8:
  case 9:
    nmax = 2;
    break;
  default:
    return -2;
  }
  if ((number < 0) || (number >= nmax))
    return -5;
  end_type = type;
  end_num = number;
  end_vindex = vindex;
  cur_type = type;
  cur_num = number;
  cur_vindex = vindex;
  while (follow_slice_link(&cur_vindex, &cur_type, &cur_num)) {
    if ((cur_type == type) && (cur_num == number) && (cur_vindex == vindex)) {
      break;
    }
    end_type = cur_type;
    end_num = cur_num;
    end_vindex = cur_vindex;
  }
  vis5d_get_slice_link(vindex, type, number, &p_vindex, &p_type, &p_num);
  cur_type = *p_type;
  cur_num = *p_num;
  cur_vindex = *p_vindex;
  *p_type = -1;
  *p_num = -1;
  *p_vindex = -1;
  if ((end_type != type) || (end_num != number) || (end_vindex != vindex)) {
    vis5d_get_slice_link(end_vindex, end_type, end_num, &p_vindex, &p_type, &p_num);
    if ((cur_type == end_type) && (cur_num == end_num) && (cur_vindex == end_vindex)) {
      cur_type = cur_num = cur_vindex = -1;
    }
    *p_type = cur_type;
    *p_num = cur_num;
    *p_vindex = cur_vindex;
  }
  return 0;
}
```