user: 请从给定的汇编指令推导出C源代码：

```asm
<pack_seg>:
  endbr64
  mov    %edx,%r8d
  mov    $0x0,%eax
  lea    0x8(%rsi),%r9
  mov    %ecx,%r11d
  sub    $0x1,%r8d
  mov    (%rdi),%rcx
  cmovns %rsi,%rax
  mov    %rax,%r10
  test   %rcx,%rcx
  je     L114
  test   %r8d,%r8d
  jle    L302
  mov    %rcx,0x8(%rsi)
  lea    -0x2(%rdx),%r8d
  mov    0x8(%rdi),%rdx
  lea    0x10(%rsi),%r9
  mov    $0x1,%eax
  mov    $0x1,%ecx
  test   %rdx,%rdx
  je     L0
  add    $0x1,%eax
  or     $0x2,%rcx
  test   %r8d,%r8d
  jle    L85
L252:
  mov    %rdx,(%r9)
  sub    $0x1,%r8d
  add    $0x8,%r9
L0:
  mov    0x10(%rdi),%rdx
  test   %rdx,%rdx
  je     L140
L48:
  add    $0x1,%eax
  or     $0x4,%rcx
  test   %r8d,%r8d
  jle    L120
  mov    %rdx,(%r9)
  sub    $0x1,%r8d
  add    $0x8,%r9
L140:
  mov    0x18(%rdi),%rdx
  test   %rdx,%rdx
  je     L206
  add    $0x1,%eax
  or     $0x8,%rcx
  test   %r8d,%r8d
  jle    L184
  mov    %rdx,(%r9)
  sub    $0x1,%r8d
  add    $0x8,%r9
L206:
  mov    0x20(%rdi),%rdx
  test   %rdx,%rdx
  je     L58
  add    $0x1,%eax
  or     $0x10,%rcx
  test   %r8d,%r8d
  jle    L119
  mov    %rdx,(%r9)
  sub    $0x1,%r8d
  add    $0x8,%r9
L58:
  mov    0x28(%rdi),%rdx
  test   %rdx,%rdx
  je     L235
  add    $0x1,%eax
  or     $0x20,%rcx
  test   %r8d,%r8d
  jle    L113
  mov    %rdx,(%r9)
  sub    $0x1,%r8d
  add    $0x8,%r9
L235:
  mov    0x30(%rdi),%rdx
  test   %rdx,%rdx
  je     L64
  add    $0x1,%eax
  or     $0x40,%rcx
  test   %r8d,%r8d
  jle    L166
  mov    %rdx,(%r9)
  sub    $0x1,%r8d
  add    $0x8,%r9
L64:
  mov    0x38(%rdi),%rdx
  test   %rdx,%rdx
  je     L111
  add    $0x1,%eax
  or     $0x80,%cl
  test   %r8d,%r8d
  jle    L324
  mov    %rdx,(%r9)
L324:
  lea    -0x6(%rax),%edx
  cmp    $0x1,%edx
  jbe    L311
L318:
  cmp    $0x8,%eax
  jne    L207
  test   %r11d,%r11d
  mov    $0xa,%edx
  cmovle %edx,%eax
  ret
  nopl   (%rax)
L114:
  mov    0x8(%rdi),%rdx
  xor    %eax,%eax
  test   %rdx,%rdx
  je     L0
  add    $0x1,%eax
  or     $0x2,%rcx
  test   %r8d,%r8d
  jg     L252
L85:
  cmpq   $0x0,0x10(%rdi)
  je     L140
L73:
  add    $0x1,%eax
  or     $0x4,%rcx
L120:
  cmpq   $0x0,0x18(%rdi)
  je     L206
  add    $0x1,%eax
  or     $0x8,%rcx
L184:
  cmpq   $0x0,0x20(%rdi)
  je     L58
  add    $0x1,%eax
  or     $0x10,%rcx
L119:
  cmpq   $0x0,0x28(%rdi)
  je     L235
  add    $0x1,%eax
  or     $0x20,%rcx
L113:
  cmpq   $0x0,0x30(%rdi)
  je     L64
  add    $0x1,%eax
  or     $0x40,%rcx
L166:
  cmpq   $0x0,0x38(%rdi)
  je     L111
  add    $0x1,%eax
  or     $0x80,%cl
  lea    -0x6(%rax),%edx
  cmp    $0x1,%edx
  ja     L318
  nopw   0x0(%rax,%rax,1)
L311:
  test   %r11d,%r11d
  jle    L207
  mov    $0x8,%eax
  ret
  nopl   0x0(%rax,%rax,1)
L111:
  lea    -0x6(%rax),%edx
  cmp    $0x1,%edx
  jbe    L311
L207:
  test   %r10,%r10
  je     L281
  mov    %rcx,(%r10)
L281:
  add    $0x1,%eax
  ret
  nopl   0x0(%rax)
L302:
  cmpq   $0x0,0x8(%rdi)
  je     L315
  cmpq   $0x0,0x10(%rdi)
  mov    $0x3,%ecx
  mov    $0x2,%eax
  jne    L73
  jmp    L140
  nopl   0x0(%rax)
L315:
  mov    0x10(%rdi),%rdx
  mov    $0x1,%eax
  mov    $0x1,%ecx
  test   %rdx,%rdx
  je     L140
  jmp    L48
```

assistant: ```c
int pack_seg(const uint8_t *src, uint8_t *buffer, int sz, int n) {
  uint8_t header = 0;
  int notzero = 0;
  int i;
  uint8_t *obuffer = buffer;
  ++buffer;
  --sz;
  if (sz < 0)
    obuffer = NULL;
  for (i = 0; i < 8; i++) {
    if (src[i] != 0) {
      notzero++;
      header |= 1 << i;
      if (sz > 0) {
        *buffer = src[i];
        ++buffer;
        --sz;
      }
    }
  }
  if ((notzero == 7 || notzero == 6) && n > 0) {
    notzero = 8;
  }
  if (notzero == 8) {
    if (n > 0) {
      return 8;
    } else {
      return 10;
    }
  }
  if (obuffer) {
    *obuffer = header;
  }
  return notzero + 1;
}
```