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

```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     L182
  mov    %rdx,%r8
  mov    %ecx,%edx
  cmp    $0x1,%ecx
  je     L346
  movslq %esi,%rax
  lea    (%rdi,%rax,4),%r9
  cmp    $0x2,%ecx
  je     L10
  cmp    $0x3,%ecx
  je     L341
  cmp    $0x3c0,%esi
  jg     L145
  movslq %ecx,%rbx
  lea    0x0(,%rbx,4),%rbp
  lea    (%rdi,%rbp,1),%rax
  mov    (%r8),%r10d
  mov    %r10d,%r11d
  shl    $0x8,%r11d
  mov    %r10d,%ecx
  shl    $0x10,%ecx
  or     %ecx,%r11d
  mov    %r10d,%ecx
  shl    $0x18,%ecx
  or     %ecx,%r11d
  mov    $0x1,%r12d
  sub    %edx,%r12d
  movslq %r12d,%r12
  shl    $0x2,%r12
  sub    $0x1,%edx
  jmp    L114
L346:
  mov    %esi,%edx
  mov    (%r8),%esi
  call   <memchr@plt>
  jmp    L48
L10:
  lea    0x8(%rdi),%rax
  mov    (%r8),%esi
  shl    $0x8,%esi
  add    0x4(%r8),%esi
  mov    %esi,%edi
  sar    $0x8,%edi
L68:
  mov    -0x4(%rax),%ecx
  mov    -0x8(%rax),%edx
  shl    $0x8,%edx
  add    %ecx,%edx
  cmp    %esi,%edx
  je     L52
  cmp    %edi,%ecx
  setne  %dl
  movzbl %dl,%edx
  lea    0x4(%rax,%rdx,4),%rax
  cmp    %rax,%r9
  jae    L68
  mov    $0x0,%eax
  jmp    L48
L52:
  sub    $0x2,%rax
  jmp    L48
L341:
  lea    0xc(%rdi),%rax
  mov    (%r8),%ecx
  shl    $0x8,%ecx
  add    0x8(%r8),%ecx
  mov    %ecx,%esi
  sar    $0x8,%esi
  jmp    L82
L112:
  cmp    -0x8(%rax),%esi
  setne  %dl
  movzbl %dl,%edx
  lea    0x4(%rax,%rdx,4),%rax
  cmp    %rax,%r9
  jb     L63
L82:
  mov    -0xc(%rax),%edx
  shl    $0x8,%edx
  add    -0x4(%rax),%edx
  cmp    %ecx,%edx
  jne    L112
  mov    -0x8(%rax),%ebx
  cmp    %ebx,0x4(%r8)
  jne    L112
  sub    $0x3,%rax
  jmp    L48
L265:
  test   %edx,%edx
  je     L364
  lea    (%rax,%r12,1),%r15
  mov    %edx,%edi
  mov    $0x0,%esi
  mov    $0x1,%ecx
  jmp    L306
L253:
  add    $0x4,%rsi
  sub    $0x1,%edi
  je     L364
L306:
  mov    (%r15,%rsi,1),%r13d
  cmp    %r13d,0x4(%r8,%rsi,1)
  jne    L110
  lea    (%rcx,%rdi,1),%r14d
  cmp    %edx,%r14d
  jne    L253
  cmp    %r10d,%r13d
  setne  %r13b
  cmp    $0x1,%r13b
  sbb    $0xffffffff,%ecx
  jmp    L253
L110:
  test   %edi,%edi
  je     L364
L267:
  movslq %ecx,%rcx
  lea    (%rax,%rcx,4),%rax
  cmp    %rax,%r9
  jb     L402
L114:
  mov    %rax,%rcx
  sub    %rbp,%rcx
  mov    (%rcx),%ecx
  cmp    %ecx,%r10d
  je     L265
  mov    %ecx,%esi
  xor    %r11d,%esi
  mov    $0x1,%ecx
  test   $0xff00,%esi
  je     L267
  mov    $0x2,%ecx
  test   $0xff0000,%esi
  je     L267
  and    $0xff000000,%esi
  cmp    $0x1,%esi
  mov    $0x3,%ecx
  sbb    $0xffffffff,%ecx
  jmp    L267
L364:
  sub    %rbx,%rax
  jmp    L48
L145:
  mov    %rsp,%rax
  lea    0x400(%rsp),%rcx
L96:
  mov    %edx,(%rax)
  add    $0x4,%rax
  cmp    %rcx,%rax
  jne    L96
  lea    -0x1(%rdx),%eax
  test   %eax,%eax
  jle    L293
  mov    %r8,%rcx
L409:
  movslq (%rcx),%r9
  mov    %eax,(%rsp,%r9,4)
  add    $0x4,%rcx
  sub    $0x1,%eax
  jne    L409
L293:
  mov    (%r8),%ebx
  sub    %edx,%esi
  mov    %esi,%r10d
  mov    $0x0,%ecx
  jmp    L62
L318:
  test   %esi,%esi
  je     L285
L0:
  lea    (%rdx,%rcx,1),%eax
  cltq
  movslq -0x4(%rdi,%rax,4),%rax
  add    (%rsp,%rax,4),%ecx
  cmp    %r10d,%ecx
  jg     L172
L62:
  movslq %ecx,%r11
  lea    (%rdi,%r11,4),%r9
  cmp    %ebx,(%r9)
  jne    L0
  lea    -0x4(%rdx),%esi
  mov    $0x0,%eax
  test   %esi,%esi
  jle    L318
L49:
  mov    0x10(%r9,%rax,1),%r15d
  cmp    %r15d,0x10(%r8,%rax,1)
  jne    L318
  add    $0x4,%rax
  sub    $0x1,%esi
  jne    L49
L285:
  lea    (%rdi,%r11,1),%rax
  jmp    L48
L172:
  mov    $0x0,%eax
  jmp    L48
L182:
  mov    $0x0,%eax
L48:
  mov    0x408(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L279
  add    $0x418,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L63:
  mov    $0x0,%eax
  jmp    L48
L402:
  mov    $0x0,%eax
  jmp    L48
L279:
  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;
  }
}
```