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

```asm
<verify_hash>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    $0x4,%eax
  cmpb   $0x24,(%rsi)
  je     L63
L32:
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  jne    L111
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L63:
  lea    0x1(%rsi),%rdi
  mov    $0x24,%esi
  call   <strchr@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L135
  movb   $0x0,(%rax)
  lea    0x1(%rax),%r12
  mov    $0x24,%esi
  mov    %r12,%rdi
  call   <strchr@plt>
  mov    %rax,-0x58(%rbp)
  test   %rax,%rax
  je     L64
  movb   $0x0,(%rax)
  lea    0x1(%rax),%r13
  mov    D9(%rip),%rax
  movslq (%rax),%rdx
  lea    0xf(%rdx),%rax
  mov    %rax,%rsi
  and    $0xfffffffffffffff0,%rsi
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rcx
  sub    %rax,%rcx
L160:
  cmp    %rcx,%rsp
  je     L89
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L160
L89:
  mov    %rsi,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L197
  orq    $0x0,-0x8(%rsp,%rax,1)
L197:
  mov    %rsp,-0x50(%rbp)
  lea    0xf(%rdx),%rax
  mov    %rax,%rsi
  and    $0xfffffffffffffff0,%rsi
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rcx
  sub    %rax,%rcx
L110:
  cmp    %rcx,%rsp
  je     L75
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L110
L75:
  mov    %rsi,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L12
  orq    $0x0,-0x8(%rsp,%rax,1)
L12:
  mov    %rsp,-0x68(%rbp)
  add    $0xf,%rdx
  mov    %rdx,%rcx
  and    $0xfffffffffffffff0,%rcx
  and    $0xfffffffffffff000,%rdx
  mov    %rsp,%rax
  sub    %rdx,%rax
L31:
  cmp    %rax,%rsp
  je     L150
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L31
L150:
  mov    %rcx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L58
  orq    $0x0,-0x8(%rsp,%rax,1)
L58:
  mov    %rsp,-0x60(%rbp)
  movzbl 0x1(%rbx),%edi
  test   %dil,%dil
  je     L124
  mov    -0x50(%rbp),%r15
L26:
  movzbl 0x1(%r12),%r14d
  movzbl %dil,%edi
  call   <__get_raw@plt>
  mov    %eax,%ebx
  movzbl %r14b,%edi
  call   <__get_raw@plt>
  shl    $0x4,%ebx
  or     %eax,%ebx
  mov    %bl,(%r15)
  add    $0x2,%r12
  movzbl (%r12),%edi
  add    $0x1,%r15
  test   %dil,%dil
  jne    L26
L124:
  mov    -0x58(%rbp),%rax
  movzbl 0x1(%rax),%edi
  test   %dil,%dil
  je     L103
  mov    -0x60(%rbp),%r14
L94:
  movzbl 0x1(%r13),%r12d
  movzbl %dil,%edi
  call   <__get_raw@plt>
  mov    %eax,%ebx
  movzbl %r12b,%edi
  call   <__get_raw@plt>
  shl    $0x4,%ebx
  or     %eax,%ebx
  mov    %bl,(%r14)
  add    $0x2,%r13
  movzbl 0x0(%r13),%edi
  add    $0x1,%r14
  test   %dil,%dil
  jne    L94
L103:
  mov    D9(%rip),%rbx
  mov    (%rbx),%ecx
  mov    -0x48(%rbp),%rdx
  mov    -0x50(%rbp),%rsi
  mov    -0x68(%rbp),%r15
  mov    %r15,%rdi
  call   <generate_hash@plt>
  mov    (%rbx),%edx
  mov    -0x60(%rbp),%rsi
  mov    %r15,%rdi
  call   <memcmp@plt>
  test   %eax,%eax
  mov    $0x3,%edx
  cmovne %edx,%eax
  jmp    L32
L135:
  mov    $0x4,%eax
  jmp    L32
L64:
  mov    $0x4,%eax
  jmp    L32
L111:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int verify_hash(char *given_password, char *stored_password) {
  char *stored_salt, *stored_hash, *algorithm;
  if (*stored_password != '$')
    return 4;
  stored_password++;
  algorithm = stored_password;
  stored_salt = strchr(algorithm, '$');
  if (!stored_salt)
    return 4;
  *stored_salt = 0;
  stored_salt++;
  stored_hash = strchr(stored_salt, '$');
  if (!stored_hash)
    return 4;
  *stored_hash = 0;
  stored_hash++;
  unsigned char salt[SHA512_DIGEST_LENGTH];
  unsigned char hash[SHA512_DIGEST_LENGTH];
  unsigned char compare_hash[SHA512_DIGEST_LENGTH];
  int i = 0;
  while (*stored_salt) {
    unsigned char v1, v2;
    v1 = *stored_salt;
    v2 = *(stored_salt + 1);
    v1 = __get_raw(v1);
    v2 = __get_raw(v2);
    salt[i] = (v1 << 4) | v2;
    stored_salt += 2;
    i++;
  }
  i = 0;
  while (*stored_hash) {
    unsigned char v1, v2;
    v1 = *stored_hash;
    v2 = *(stored_hash + 1);
    v1 = __get_raw(v1);
    v2 = __get_raw(v2);
    compare_hash[i] = (v1 << 4) | v2;
    stored_hash += 2;
    i++;
  }
  generate_hash(hash, salt, given_password, SHA512_DIGEST_LENGTH);
  if (!memcmp(hash, compare_hash, SHA512_DIGEST_LENGTH))
    return 0;
  return 3;
}
```