user: Converte this assembly snippet into its equivalent C code:

```asm
<Railgun7a>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x418,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x408(%rsp)
  xor    %eax,%eax
  cmp    %ecx,%esi
  jl     L50
  mov    %rdx,%r9
  mov    %esi,%r11d
  mov    %ecx,%edx
  mov    (%r9),%r8d
  cmp    $0x1,%ecx
  je     L330
  movslq %esi,%rax
  lea    (%rdi,%rax,4),%r10
  cmp    $0x2,%ecx
  je     L24
  cmp    $0x3,%ecx
  je     L197
  cmp    $0x3c0,%esi
  jg     L108
  mov    %r8d,%ebx
  mov    %r8d,%esi
  movslq %ecx,%r11
  mov    $0x1,%ebp
  shl    $0x10,%esi
  shl    $0x8,%ebx
  lea    0x0(,%r11,4),%rcx
  sub    %edx,%ebp
  or     %esi,%ebx
  mov    %r8d,%esi
  lea    (%rdi,%rcx,1),%rax
  movslq %ebp,%rbp
  shl    $0x18,%esi
  mov    %rcx,%rdi
  lea    -0x1(%rdx),%r12d
  shl    $0x2,%rbp
  or     %esi,%ebx
  neg    %rdi
  mov    %r12,%rdx
  jmp    L56
  nopl   0x0(%rax,%rax,1)
L239:
  mov    %ecx,%esi
  mov    $0x4,%ecx
  xor    %ebx,%esi
  test   $0xff00,%esi
  je     L59
  mov    $0x8,%ecx
  test   $0xff0000,%esi
  je     L59
  and    $0xff000000,%esi
  cmp    $0x1,%esi
  sbb    %rcx,%rcx
  and    $0xfffffffffffffffc,%rcx
  add    $0x10,%rcx
L59:
  add    %rcx,%rax
  cmp    %rax,%r10
  jb     L50
L56:
  mov    (%rax,%rdi,1),%ecx
  cmp    %r8d,%ecx
  jne    L239
  test   %edx,%edx
  je     L83
  lea    (%rax,%rbp,1),%r15
  xor    %ecx,%ecx
  mov    $0x1,%esi
  jmp    L133
  nopw   0x0(%rax,%rax,1)
L36:
  add    %esi,%r13d
  cmp    %edx,%r13d
  jne    L313
  cmp    %r8d,%r14d
  setne  %r13b
  cmp    $0x1,%r13b
  sbb    $0xffffffff,%esi
L313:
  add    $0x1,%rcx
  cmp    %rcx,%r12
  je     L83
L133:
  mov    %edx,%r13d
  mov    (%r15,%rcx,4),%r14d
  sub    %ecx,%r13d
  cmp    %r14d,0x4(%r9,%rcx,4)
  je     L36
  movslq %esi,%rcx
  shl    $0x2,%rcx
  add    %rcx,%rax
  cmp    %rax,%r10
  jae    L56
  nopl   0x0(%rax,%rax,1)
L50:
  xor    %eax,%eax
L161:
  mov    0x408(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L248
  add    $0x418,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L24:
  shl    $0x8,%r8d
  add    0x4(%r9),%r8d
  lea    0x8(%rdi),%rax
  mov    %r8d,%esi
  sar    $0x8,%esi
  jmp    L196
  nopl   0x0(%rax)
L7:
  xor    %edx,%edx
  cmp    %esi,%ecx
  setne  %dl
  lea    0x4(%rax,%rdx,4),%rax
  cmp    %rax,%r10
  jb     L50
L196:
  mov    -0x8(%rax),%edx
  mov    -0x4(%rax),%ecx
  shl    $0x8,%edx
  add    %ecx,%edx
  cmp    %r8d,%edx
  jne    L7
  sub    $0x2,%rax
  jmp    L161
L108:
  mov    %rsp,%rax
  lea    0x400(%rsp),%rcx
  nopw   0x0(%rax,%rax,1)
L70:
  mov    %edx,(%rax)
  add    $0x4,%rax
  cmp    %rax,%rcx
  jne    L70
  lea    -0x1(%rdx),%eax
  mov    %r9,%rcx
  test   %eax,%eax
  jle    L286
  nopl   (%rax)
L296:
  movslq (%rcx),%rsi
  add    $0x4,%rcx
  mov    %eax,(%rsp,%rsi,4)
  sub    $0x1,%eax
  jne    L296
L286:
  movslq %edx,%r12
  sub    %edx,%r11d
  xor    %ecx,%ecx
  neg    %r12
  shl    $0x2,%r12
  jmp    L319
L229:
  movslq -0x4(%rdi,%r10,4),%rax
  add    (%rsp,%rax,4),%ecx
  cmp    %r11d,%ecx
  jg     L50
L319:
  lea    (%rdx,%rcx,1),%r10d
  movslq %ecx,%rbx
  movslq %r10d,%r10
  cmp    %r8d,(%rdi,%rbx,4)
  jne    L229
  lea    -0x4(%rdx),%esi
  test   %esi,%esi
  jle    L54
  lea    (%r12,%r10,4),%rbp
  xor    %eax,%eax
  add    %rdi,%rbp
  nopl   0x0(%rax)
L282:
  mov    0x10(%rbp,%rax,1),%r15d
  cmp    %r15d,0x10(%r9,%rax,1)
  jne    L229
  add    $0x4,%rax
  sub    $0x1,%esi
  jne    L282
L71:
  lea    (%rdi,%rbx,1),%rax
  jmp    L161
L54:
  jne    L229
  jmp    L71
  nopw   0x0(%rax,%rax,1)
L197:
  shl    $0x8,%r8d
  add    0x8(%r9),%r8d
  lea    0xc(%rdi),%rax
  mov    %r8d,%esi
  sar    $0x8,%esi
  jmp    L205
  nopl   0x0(%rax)
L153:
  xor    %edx,%edx
  cmp    %ecx,%esi
  setne  %dl
  lea    0x4(%rax,%rdx,4),%rax
  cmp    %rax,%r10
  jb     L50
L205:
  mov    -0xc(%rax),%edx
  mov    -0x8(%rax),%ecx
  shl    $0x8,%edx
  add    -0x4(%rax),%edx
  cmp    %r8d,%edx
  jne    L153
  cmp    %ecx,0x4(%r9)
  jne    L153
  sub    $0x3,%rax
  jmp    L161
L330:
  mov    0x408(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L248
  add    $0x418,%rsp
  mov    %esi,%edx
  mov    %r8d,%esi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1070 <memchr@plt>
  nopl   0x0(%rax,%rax,1)
L83:
  sub    %r11,%rax
  jmp    L161
L248:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
char *Railgun7a(char *target, int tgtlen, char *pattern, int patlen) {
  uint8_t *tgt = (uint8_t *)target, *pat = (uint8_t *)pattern;
  uint8_t *tgtMax = tgt + tgtlen;
  uint32_t patwin, tgtwin;
  int skip, count;
  int bm_bc[256];
  if (patlen > tgtlen)
    return NULL;
  if (patlen == 1)
    return memchr(tgt, *pat, tgtlen);
  if (patlen == 2) {
    tgt += 2;
    patwin = (pat[0] << 8) + pat[1];
    while (1) {
      if (patwin == ((uint32_t)tgt[-2] << 8) + tgt[-1])
        return (char *)tgt - 2;
      tgt += (uint8_t)(patwin >> 8) == tgt[-1] ? 1 : 2;
      if (tgt > tgtMax)
        return NULL;
    }
  } else if (patlen == 3) {
    tgt += 3;
    patwin = (pat[0] << 8) + pat[2];
    while (1) {
      if (patwin == ((uint32_t)tgt[-3] << 8) + tgt[-1]) {
        if (pat[1] == tgt[-2])
          return (char *)tgt - 3;
      }
      tgt += (uint8_t)(patwin >> 8) == tgt[-2] ? 1 : 2;
      if (tgt > tgtMax)
        return NULL;
    }
  } else if (tgtlen < 961) {
    tgt = tgt + patlen;
    patwin = *(uint32_t *)pat;
    uint8_t pat0 = (uint8_t)patwin;
    uint32_t ppp0 = (pat0 << 8) | (pat0 << 16) | (pat0 << 24);
    while (1) {
      tgtwin = *(uint32_t *)(tgt - patlen);
      if (patwin == tgtwin) {
        skip = 1;
        for (count = patlen - 1; count && pat[patlen - count] == tgt[-count]; count--) {
          if (patlen - 1 == skip + count && pat0 != tgt[-count])
            skip++;
        }
        if (count == 0)
          return (char *)tgt - patlen;
      } else {
        uint32_t diff = tgtwin ^ ppp0;
        skip = !(diff & 0x0000FF00) ? 1 : !(diff & 0x00FF0000) ? 2 : !(diff & 0xFF000000) ? 3 : 4;
      }
      tgt = tgt + skip;
      if (tgt > tgtMax)
        return NULL;
    }
  } else {
    int i;
    for (i = 0; i < 256; i++)
      bm_bc[i] = patlen;
    for (i = 0; i < patlen - 1; i++)
      bm_bc[pat[i]] = patlen - i - 1;
    patwin = *(uint32_t *)pat;
    for (i = 0; i <= tgtlen - patlen; i = i + bm_bc[tgt[i + patlen - 1]]) {
      if (*(uint32_t *)&tgt[i] == patwin) {
        count = patlen - 4;
        while (count > 0 && pat[patlen - count] == tgt[i + patlen - count])
          count--;
        if (count == 0)
          return (char *)tgt + i;
      }
    }
    return NULL;
  }
}
```