user: 请将以下的汇编代码转换成C语言代码：

```asm
<sg_mode_page_offset>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %esi,-0x1c(%rbp)
  mov    %edx,-0x20(%rbp)
  mov    %rcx,-0x28(%rbp)
  mov    %r8d,-0x2c(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  je     L50
  cmpl   $0x3,-0x1c(%rbp)
  jle    L50
  cmpl   $0x0,-0x20(%rbp)
  jne    L7
  cmpl   $0x7,-0x1c(%rbp)
  jg     L7
L50:
  mov    -0x1c(%rbp),%edx
  mov    -0x2c(%rbp),%esi
  mov    -0x28(%rbp),%rax
  mov    %edx,%ecx
  lea    D27(%rip),%rdx
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  mov    $0xffffffff,%eax
  jmp    L64
L7:
  cmpl   $0x0,-0x20(%rbp)
  je     L45
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  add    $0x1,%eax
  mov    %eax,-0x8(%rbp)
  mov    -0x18(%rbp),%rax
  add    $0x3,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  mov    %eax,-0xc(%rbp)
  mov    -0xc(%rbp),%eax
  add    $0x4,%eax
  mov    %eax,-0x4(%rbp)
  jmp    L63
L45:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  mov    %eax,%edx
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  add    %edx,%eax
  add    $0x2,%eax
  mov    %eax,-0x8(%rbp)
  mov    -0x18(%rbp),%rax
  add    $0x6,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  mov    %eax,%edx
  mov    -0x18(%rbp),%rax
  add    $0x7,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  add    %edx,%eax
  mov    %eax,-0xc(%rbp)
  mov    -0xc(%rbp),%eax
  add    $0x8,%eax
  mov    %eax,-0x4(%rbp)
L63:
  mov    -0x4(%rbp),%eax
  add    $0x1,%eax
  cmp    %eax,-0x1c(%rbp)
  jg     L24
  mov    -0xc(%rbp),%edi
  mov    -0x1c(%rbp),%ecx
  mov    -0x4(%rbp),%edx
  mov    -0x2c(%rbp),%esi
  mov    -0x28(%rbp),%rax
  mov    %edi,%r9d
  mov    %ecx,%r8d
  mov    %edx,%ecx
  lea    D19(%rip),%rdx
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  movl   $0xffffffff,-0x4(%rbp)
  jmp    L91
L24:
  mov    -0x4(%rbp),%eax
  add    $0x1,%eax
  cmp    %eax,-0x8(%rbp)
  jg     L91
  mov    -0xc(%rbp),%edi
  mov    -0x8(%rbp),%ecx
  mov    -0x4(%rbp),%edx
  mov    -0x2c(%rbp),%esi
  mov    -0x28(%rbp),%rax
  mov    %edi,%r9d
  mov    %ecx,%r8d
  mov    %edx,%ecx
  lea    D24(%rip),%rdx
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  movl   $0xffffffff,-0x4(%rbp)
L91:
  mov    -0x4(%rbp),%eax
L64:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: tag: D27
type: string
name: unpack_data
arguments: tag: D19
type: string
name: unpack_data
arguments: tag: D24
type: string

tool: D27: given response length too short: %d


tool: D19: given response length too small, offset=%d given_len=%d bd_len=%d


tool: D24: calculated response length too small, offset=%d calc_len=%d bd_len=%d


assistant: ```c
int sg_mode_page_offset(const unsigned char *resp, int resp_len, int mode_sense_6, char *err_buff, int err_buff_len) {
  int bd_len;
  int calc_len;
  int offset;
  if ((NULL == resp) || (resp_len < 4) || ((!mode_sense_6) && (resp_len < 8))) {
    snprintf(err_buff, err_buff_len,
             "given response length too short: "
             "%d\n",
             resp_len);
    return -1;
  }
  if (mode_sense_6) {
    calc_len = resp[0] + 1;
    bd_len = resp[3];
    offset = bd_len + 4;
  } else {
    calc_len = (resp[0] << 8) + resp[1] + 2;
    bd_len = (resp[6] << 8) + resp[7];
    offset = bd_len + 8;
  }
  if ((offset + 2) > resp_len) {
    snprintf(err_buff, err_buff_len,
             "given response length "
             "too small, offset=%d given_len=%d bd_len=%d\n",
             offset, resp_len, bd_len);
    offset = -1;
  } else if ((offset + 2) > calc_len) {
    snprintf(err_buff, err_buff_len,
             "calculated response "
             "length too small, offset=%d calc_len=%d bd_len=%d\n",
             offset, calc_len, bd_len);
    offset = -1;
  }
  return offset;
}
```