user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<spaceball_init>:
  endbr64
  push   %r12
  mov    $0xfa0,%ecx
  push   %rbp
  mov    %edi,%ebp
  push   %rbx
  mov    %rsi,%rbx
  mov    $0x11,%esi
  sub    $0x50,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  mov    %rsp,%r12
  mov    %r12,%rdx
  call   <spaceball_waitchar@plt>
  test   %rax,%rax
  jne    L169
  mov    $0x3e8,%ecx
  mov    %r12,%rdx
  mov    $0xd,%esi
  mov    %ebp,%edi
  call   <spaceball_waitchar@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  mov    $0x40,%esi
  mov    %ebp,%edi
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L169
  mov    $0x12,%edx
  mov    %r12,%rsi
  lea    D108(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  mov    $0x40,%esi
  mov    %ebp,%edi
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  lea    D86(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L169
  mov    $0x7,%edx
  mov    %r12,%rsi
  lea    D30(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L143
  movq   $0x3,(%rbx)
L143:
  mov    $0x7,%edx
  mov    %r12,%rsi
  lea    D124(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L106
  movq   $0x4,(%rbx)
L106:
  mov    $0x7,%edx
  mov    %r12,%rsi
  lea    D1(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L181
  movq   $0x7,(%rbx)
L181:
  mov    $0xa,%edx
  mov    %r12,%rsi
  lea    D126(%rip),%rdi
  call   <strncasecmp@plt>
  mov    %r12,%rdx
  test   %eax,%eax
  jne    L33
  lea    D78(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L169
  mov    $0x15,%edx
  mov    %r12,%rsi
  lea    D119(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  mov    $0x22,%esi
  mov    %ebp,%edi
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L169
  lea    D138(%rip),%rsi
  mov    %r12,%rdi
  call   <strstr@plt>
  mov    %r12,%rdx
  mov    $0x22,%esi
  mov    %ebp,%edi
  cmp    $0x1,%rax
  mov    $0x8,%eax
  sbb    $0xffffffffffffffff,%rax
  mov    %rax,(%rbx)
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  lea    D65(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  lea    D19(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  neg    %rax
  sbb    %eax,%eax
  jmp    L112
  nopl   0x0(%rax,%rax,1)
L33:
  lea    D26(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  lea    D83(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L169
  mov    %r12,%rdx
  lea    D103(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  neg    %rax
  sbb    %eax,%eax
L112:
  mov    0x48(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L75
  add    $0x50,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L169:
  mov    $0xffffffff,%eax
  jmp    L112
L75:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: tag: D108
type: string
name: retrieve_data
arguments: tag: D86
type: string
name: retrieve_data
arguments: tag: D30
type: string
name: retrieve_data
arguments: tag: D124
type: string
name: retrieve_data
arguments: tag: D1
type: string
name: retrieve_data
arguments: tag: D126
type: string
name: retrieve_data
arguments: tag: D78
type: string
name: retrieve_data
arguments: tag: D119
type: string
name: retrieve_data
arguments: tag: D138
type: string
name: retrieve_data
arguments: tag: D65
type: string
name: retrieve_data
arguments: tag: D19
type: string
name: retrieve_data
arguments: tag: D26
type: string
name: retrieve_data
arguments: tag: D83
type: string
name: retrieve_data
arguments: tag: D103
type: string

tool: D108: @1 Spaceball alive

tool: D86: hm

tool: D30: Hm2003B

tool: D124: Hm2003C

tool: D1: Hm3003C

tool: D126: HvFirmware

tool: D78: "

tool: D119: "1 Spaceball 4000 FLX

tool: D138:  L 

tool: D65: YS

tool: D19: M

tool: D26: P@A@A

tool: D83: FT@

tool: D103: MSS

assistant: ```c
int spaceball_init(int fd, unsigned long *id, unsigned long *extra) {
  char r[64];
  if (spaceball_waitchar(fd, 0x11, r, 4000) || spaceball_waitchar(fd, 0x0d, r, 1000))
    return -1;
  if (spaceball_waitcmd(fd, '@', r))
    return -1;
  if (strncmp("@1 Spaceball alive", r, 18))
    return -1;
  if (spaceball_waitcmd(fd, '@', r))
    return -1;
  if (spaceball_cmd(fd, "hm", r))
    return -1;
  if (!strncmp("Hm2003B", r, 7))
    *id = 3;
  if (!strncmp("Hm2003C", r, 7))
    *id = 4;
  if (!strncmp("Hm3003C", r, 7))
    *id = 7;
  if (!strncasecmp("HvFirmware", r, 10)) {
    if (spaceball_cmd(fd, "\"", r))
      return -1;
    if (strncmp("\"1 Spaceball 4000 FLX", r, 21))
      return -1;
    if (spaceball_waitcmd(fd, '"', r))
      return -1;
    if (strstr(r, " L "))
      *id = 9;
    else
      *id = 8;
    if (spaceball_waitcmd(fd, '"', r))
      return -1;
    if (spaceball_cmd(fd, "YS", r))
      return -1;
    if (spaceball_cmd(fd, "M", r))
      return -1;
    return 0;
  }
  if (spaceball_cmd(fd, "P@A@A", r) || spaceball_cmd(fd, "FT@", r) || spaceball_cmd(fd, "MSS", r))
    return -1;
  return 0;
}
```