user: Translate the below assembly code into C programming language:

```asm
<goldensun>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,%r12
  mov    %esi,%r13d
  mov    %rdx,-0x50(%rbp)
  mov    %ecx,-0x44(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  lea    -0x1000(%rsp),%rax
L231:
  cmp    %rax,%rsp
  je     L70
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L231
L70:
  mov    %rsp,%r8
  cmpl   $0x0,-0x44(%rbp)
  jle    L90
  mov    $0x0,%ebx
  mov    $0x0,%r14d
  mov    $0x0,%eax
  mov    $0x0,%r9d
  mov    $0x0,%r15d
  jmp    L151
L229:
  cmp    %r9d,%r13d
  jle    L291
  lea    0x1(%r9),%esi
  movslq %r9d,%r9
  movzbl (%r12,%r9,1),%edx
  test   %edx,%edx
  jle    L20
  lea    -0x40(%rbp),%rdi
L236:
  mov    %edx,%r9d
  and    $0x80,%r9d
  add    %edx,%edx
  and    $0xff,%edx
  sete   %cl
  test   %r9d,%r9d
  setle  %r9b
  or     %r9d,%ecx
  mov    %cl,(%rdi)
  add    $0x1,%rdi
  test   %edx,%edx
  jg     L236
  mov    %esi,%r9d
  mov    $0x0,%ebx
  jmp    L188
L20:
  mov    %esi,%r9d
  mov    $0x0,%ebx
  jmp    L188
L228:
  cmp    %ecx,%r13d
  jle    L95
  add    $0x3,%r9d
  movslq %ecx,%rcx
  movzbl (%r12,%rcx,1),%edi
  add    $0x10,%edi
L40:
  lea    0x1000(%rax),%r10d
  sub    %edx,%r10d
L309:
  mov    $0x0,%ecx
  movslq %r15d,%r11
  add    -0x50(%rbp),%r11
L36:
  lea    (%r10,%rcx,1),%edx
  mov    %edx,%esi
  sar    $0x1f,%esi
  shr    $0x14,%esi
  add    %esi,%edx
  and    $0xfff,%edx
  sub    %esi,%edx
  movslq %edx,%rdx
  movzbl (%r8,%rdx,1),%edx
  mov    %dl,(%r11,%rcx,1)
  movslq %eax,%rsi
  mov    %dl,(%r8,%rsi,1)
  add    $0x1,%eax
  cltd
  shr    $0x14,%edx
  add    %edx,%eax
  and    $0xfff,%eax
  sub    %edx,%eax
  add    $0x1,%rcx
  cmp    %ecx,%edi
  jg     L36
  lea    -0x1(%rdi),%edx
  test   %edi,%edi
  mov    $0x0,%ecx
  cmovle %ecx,%edx
  lea    0x1(%r15,%rdx,1),%r15d
  add    %edi,%r14d
  jmp    L216
L92:
  lea    0x3(%r9),%esi
  cmp    %r13d,%esi
  jge    L293
  add    $0x4,%r9d
  movslq %ecx,%rcx
  movzbl (%r12,%rcx,1),%ecx
  shl    $0x8,%ecx
  movslq %esi,%rsi
  movzbl (%r12,%rsi,1),%esi
  lea    0x110(%rcx,%rsi,1),%edi
  jmp    L40
L220:
  cmp    %r13d,%r9d
  jge    L262
  movslq %r9d,%rdx
  movzbl (%r12,%rdx,1),%edx
  add    $0x1,%r14d
  movslq %r15d,%rcx
  mov    -0x50(%rbp),%rdi
  mov    %dl,(%rdi,%rcx,1)
  movslq %eax,%rcx
  mov    %dl,(%r8,%rcx,1)
  add    $0x1,%eax
  cltd
  shr    $0x14,%edx
  add    %edx,%eax
  and    $0xfff,%eax
  sub    %edx,%eax
  lea    0x1(%r9),%r9d
  lea    0x1(%r15),%r15d
L216:
  cmp    -0x44(%rbp),%r14d
  jge    L89
L151:
  cmp    $0x8,%ebx
  je     L229
  add    $0x1,%ebx
L188:
  movslq %ebx,%rdx
  cmpb   $0x0,-0x40(%rbp,%rdx,1)
  je     L220
  lea    0x1(%r9),%edx
  cmp    %r13d,%edx
  jge    L24
  movslq %r9d,%rcx
  movzbl (%r12,%rcx,1),%edi
  lea    0x2(%r9),%ecx
  movslq %edx,%rdx
  movzbl (%r12,%rdx,1),%edx
  shl    $0x4,%edx
  movzbl %dil,%esi
  sar    $0x4,%esi
  add    %esi,%edx
  cmp    %r14d,%edx
  jg     L199
  and    $0xf,%edi
  je     L228
  cmp    $0x1,%dil
  je     L92
  movzbl %dil,%edi
  lea    0x1000(%rax),%r10d
  sub    %edx,%r10d
  mov    %ecx,%r9d
  jmp    L309
L90:
  mov    $0x0,%r9d
  mov    $0x0,%r15d
L89:
  cmp    %r9d,%r13d
  jle    L271
  and    $0xfffffffc,%r9d
  lea    0x4(%r9),%eax
  cmp    %r13d,%eax
  mov    $0xffffffff,%eax
  cmovl  %eax,%r15d
L271:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L227
  mov    %r15d,%eax
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L291:
  mov    $0xffffffff,%r15d
  jmp    L271
L24:
  mov    $0xffffffff,%r15d
  jmp    L271
L199:
  mov    $0xffffffff,%r15d
  jmp    L271
L95:
  mov    $0xffffffff,%r15d
  jmp    L271
L293:
  mov    $0xffffffff,%r15d
  jmp    L271
L262:
  mov    $0xffffffff,%r15d
  jmp    L271
L227:
  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);
}
```