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

```asm
<search_next_message>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    -0x18(%rbp),%rax
  mov    $0x4,%edx
  lea    D6(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L195
  jmp    L40
L47:
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  cmp    $0x47,%eax
  jne    L73
  movl   $0x0,-0x4(%rbp)
  jmp    L123
L14:
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x1(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    -0x4(%rbp),%edx
  movslq %edx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  movzbl (%rax),%eax
  mov    %al,(%rdx)
  addl   $0x1,-0x4(%rbp)
L123:
  cmpl   $0x2,-0x4(%rbp)
  jle    L14
  mov    -0x18(%rbp),%rax
  lea    0x3(%rax),%rdx
  mov    -0x20(%rbp),%rax
  mov    $0x1,%esi
  mov    %rdx,%rdi
  call   *%rax
  test   %eax,%eax
  jne    L40
  mov    $0xffffffff,%eax
  jmp    L199
L73:
  mov    -0x18(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  cmp    $0x47,%eax
  jne    L82
  movl   $0x0,-0x4(%rbp)
  jmp    L164
L165:
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x2(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    -0x4(%rbp),%edx
  movslq %edx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  movzbl (%rax),%eax
  mov    %al,(%rdx)
  addl   $0x1,-0x4(%rbp)
L164:
  cmpl   $0x1,-0x4(%rbp)
  jle    L165
  mov    -0x18(%rbp),%rax
  lea    0x2(%rax),%rdx
  mov    -0x20(%rbp),%rax
  mov    $0x2,%esi
  mov    %rdx,%rdi
  call   *%rax
  test   %eax,%eax
  jne    L25
  mov    $0xffffffff,%eax
  jmp    L199
L82:
  mov    -0x18(%rbp),%rax
  add    $0x3,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  cmp    $0x47,%eax
  jne    L65
  mov    -0x18(%rbp),%rax
  movzbl 0x3(%rax),%edx
  mov    -0x18(%rbp),%rax
  mov    %dl,(%rax)
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    -0x20(%rbp),%rax
  mov    $0x3,%esi
  mov    %rdx,%rdi
  call   *%rax
  test   %eax,%eax
  jne    L205
  mov    $0xffffffff,%eax
  jmp    L199
L65:
  mov    -0x18(%rbp),%rax
  mov    -0x20(%rbp),%rdx
  mov    $0x4,%esi
  mov    %rax,%rdi
  call   *%rdx
  test   %eax,%eax
  jne    L147
  mov    $0xffffffff,%eax
  jmp    L199
L205:
  nop
  jmp    L187
L147:
  nop
  jmp    L187
L25:
  nop
L187:
  nop
L40:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x47,%al
  jne    L47
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x52,%al
  jne    L47
  mov    -0x18(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  cmp    $0x49,%al
  jne    L47
  mov    -0x18(%rbp),%rax
  add    $0x3,%rax
  movzbl (%rax),%eax
  cmp    $0x42,%al
  jne    L47
L195:
  mov    $0x0,%eax
L199:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: label: D6
datatype: string

tool: D6: GRIB

assistant: ```c
int search_next_message(unsigned char *temp, int (*read_func)(void *buf, unsigned int len)) {
  int n;
  if (strncmp((char *)temp, "GRIB", 4) != 0) {
    while (temp[0] != 0x47 || temp[1] != 0x52 || temp[2] != 0x49 || temp[3] != 0x42) {
      switch (temp[1]) {
      case 0x47:
        for (n = 0; n < 3; n++) {
          temp[n] = temp[n + 1];
        }
        if (read_func(&temp[3], 1) == 0) {
          return -1;
        }
        break;
      default:
        switch (temp[2]) {
        case 0x47:
          for (n = 0; n < 2; n++) {
            temp[n] = temp[n + 2];
          }
          if (read_func(&temp[2], 2) == 0) {
            return -1;
          }
          break;
        default:
          switch (temp[3]) {
          case 0x47:
            temp[0] = temp[3];
            if (read_func(&temp[1], 3) == 0) {
              return -1;
            }
            break;
          default:
            if (read_func(temp, 4) == 0) {
              return -1;
            }
            break;
          }
          break;
        }
        break;
      }
    }
  }
  return 0;
}
```