user: 请将以下的汇编代码转换成C语言代码:

```asm
<goldensun>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  mov    %esi,%r13d
  push   %r12
  mov    %rdi,%r12
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdx,-0x50(%rbp)
  mov    %ecx,-0x44(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  lea    -0x1000(%rsp),%rax
  cmp    %rax,%rsp
  je     L171
L181:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rax,%rsp
  jne    L181
L171:
  mov    -0x44(%rbp),%eax
  mov    %rsp,%r8
  test   %eax,%eax
  jle    L105
  xor    %ecx,%ecx
  xor    %r14d,%r14d
  xor    %eax,%eax
  xor    %r10d,%r10d
  xor    %r15d,%r15d
  xchg   %ax,%ax
L79:
  cmp    $0x8,%ecx
  je     L135
  add    $0x1,%ecx
L52:
  movslq %ecx,%rdx
  cmpb   $0x0,-0x40(%rbp,%rdx,1)
  je     L89
  lea    0x1(%r10),%edx
  cmp    %r13d,%edx
  jge    L7
  movslq %r10d,%rsi
  movslq %edx,%rdx
  movzbl (%r12,%rsi,1),%r9d
  movzbl (%r12,%rdx,1),%edx
  lea    0x2(%r10),%esi
  mov    %r9d,%edi
  shl    $0x4,%edx
  sar    $0x4,%r9d
  add    %r9d,%edx
  cmp    %r14d,%edx
  jg     L7
  and    $0xf,%edi
  je     L141
  cmp    $0x1,%dil
  je     L59
  lea    0x1000(%rax),%r11d
  movzbl %dil,%edi
  mov    %esi,%r10d
  sub    %edx,%r11d
L209:
  movslq %r15d,%rbx
  xor    %edx,%edx
  add    -0x50(%rbp),%rbx
  xchg   %ax,%ax
L8:
  lea    (%r11,%rdx,1),%esi
  movslq %eax,%r9
  add    $0x1,%eax
  and    $0xfff,%esi
  and    $0xfff,%eax
  movzbl (%r8,%rsi,1),%esi
  mov    %sil,(%rbx,%rdx,1)
  add    $0x1,%rdx
  mov    %sil,(%r8,%r9,1)
  cmp    %edx,%edi
  jg     L8
  xor    %ebx,%ebx
  lea    -0x1(%rdi),%edx
  test   %edi,%edi
  cmovle %ebx,%edx
  add    %edi,%r14d
  lea    0x1(%r15,%rdx,1),%r15d
L95:
  cmp    %r14d,-0x44(%rbp)
  jg     L79
L16:
  cmp    %r10d,%r13d
  jg     L248
  nop
L64:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L206
  lea    -0x28(%rbp),%rsp
  mov    %r15d,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   (%rax)
L89:
  cmp    %r13d,%r10d
  jge    L7
  movslq %r10d,%rdx
  mov    -0x50(%rbp),%rbx
  movslq %r15d,%rsi
  add    $0x1,%r14d
  movzbl (%r12,%rdx,1),%edx
  add    $0x1,%r10d
  add    $0x1,%r15d
  mov    %dl,(%rbx,%rsi,1)
  movslq %eax,%rsi
  add    $0x1,%eax
  mov    %dl,(%r8,%rsi,1)
  and    $0xfff,%eax
  jmp    L95
L135:
  cmp    %r10d,%r13d
  jle    L7
  lea    0x1(%r10),%edi
  movslq %r10d,%r10
  movzbl (%r12,%r10,1),%ecx
  test   %ecx,%ecx
  je     L149
  lea    -0x40(%rbp),%rsi
  nopl   (%rax)
L128:
  mov    %ecx,%r9d
  add    %ecx,%ecx
  and    $0x80,%r9d
  and    $0xff,%ecx
  sete   %dl
  test   %r9d,%r9d
  setle  %r9b
  add    $0x1,%rsi
  or     %r9d,%edx
  mov    %dl,-0x1(%rsi)
  test   %ecx,%ecx
  jne    L128
L149:
  mov    %edi,%r10d
  jmp    L52
  nopw   0x0(%rax,%rax,1)
L59:
  lea    0x3(%r10),%edi
  cmp    %r13d,%edi
  jge    L7
  movslq %esi,%rsi
  movslq %edi,%rdi
  add    $0x4,%r10d
  movzbl (%r12,%rsi,1),%esi
  movzbl (%r12,%rdi,1),%edi
  shl    $0x8,%esi
  lea    0x110(%rsi,%rdi,1),%edi
L252:
  lea    0x1000(%rax),%r11d
  sub    %edx,%r11d
  jmp    L209
  xchg   %ax,%ax
L141:
  cmp    %esi,%r13d
  jle    L7
  movslq %esi,%rsi
  add    $0x3,%r10d
  movzbl (%r12,%rsi,1),%edi
  add    $0x10,%edi
  jmp    L252
L248:
  and    $0xfffffffc,%r10d
  lea    0x4(%r10),%eax
  cmp    %r13d,%eax
  jge    L64
L7:
  mov    $0xffffffff,%r15d
  jmp    L64
L105:
  xor    %r10d,%r10d
  xor    %r15d,%r15d
  jmp    L16
L206:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int goldensun(unsigned char *instream, int inLength, unsigned char *outstream, int decompressedSize) {
  int i, o = 0;
  int readBytes = 0;
  int bufferLength = 0x1000;
  unsigned char buffer[bufferLength];
  int bufferOffset = 0;
  int currentOutSize = 0;
  int currentBlock = 0;
  unsigned char expandedFlags[8];
  while (currentOutSize < decompressedSize) {
    if (currentBlock == 8) {
      if (readBytes >= inLength)
        return (-1);
      int flags = instream[readBytes++];
      if (flags < 0)
        return (-1);
      int b = 0;
      while (flags > 0) {
        int bit = (flags & 0x80) > 0;
        flags = (flags & 0x7F) << 1;
        expandedFlags[b++] = (flags == 0) || !bit;
      }
      currentBlock = 0;
    } else {
      currentBlock++;
    }
    if (expandedFlags[currentBlock]) {
      if (readBytes + 1 >= inLength) {
        return (-1);
      }
      int byte1 = instream[readBytes++];
      int byte2 = instream[readBytes++];
      if (byte2 < 0)
        return (-1);
      int disp, length;
      disp = (byte1 >> 4) + (byte2 << 4);
      if (disp > currentOutSize)
        return (-1);
      switch (byte1 & 0x0F) {
      case 0: {
        if (readBytes >= inLength)
          return (-1);
        int byte3 = instream[readBytes++];
        if (byte3 < 0)
          return (-1);
        length = byte3 + 0x10;
        break;
      }
      case 1: {
        if (readBytes + 1 >= inLength)
          return (-1);
        int byte3 = instream[readBytes++];
        int byte4 = instream[readBytes++];
        if (byte4 < 0)
          return (-1);
        length = ((byte3 << 8) + byte4) + 0x110;
        break;
      }
      default: {
        length = byte1 & 0x0F;
        break;
      }
      }
      int bufIdx = bufferOffset + bufferLength - disp;
      for (i = 0; i < length; i++) {
        unsigned char next = buffer[bufIdx % bufferLength];
        bufIdx++;
        outstream[o++] = next;
        buffer[bufferOffset] = next;
        bufferOffset = (bufferOffset + 1) % bufferLength;
      }
      currentOutSize += length;
    } else {
      if (readBytes >= inLength)
        return (-1);
      int next = instream[readBytes++];
      if (next < 0)
        return (-1);
      currentOutSize++;
      outstream[o++] = next;
      buffer[bufferOffset] = (unsigned char)next;
      bufferOffset = (bufferOffset + 1) % bufferLength;
    }
  }
  if (readBytes < inLength) {
    if ((readBytes ^ (readBytes & 3)) + 4 < inLength)
      return (-1);
  }
  return (o);
}
```