user: Translate the below assembly code into C programming language:

```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    L143
  mov    $0x3e8,%ecx
  mov    %r12,%rdx
  mov    $0xd,%esi
  mov    %ebp,%edi
  call   <spaceball_waitchar@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  mov    $0x40,%esi
  mov    %ebp,%edi
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L143
  mov    $0x12,%edx
  mov    %r12,%rsi
  lea    D108(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  mov    $0x40,%esi
  mov    %ebp,%edi
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  lea    D13(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L143
  mov    $0x7,%edx
  mov    %r12,%rsi
  lea    D136(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L18
  movq   $0x3,(%rbx)
L18:
  mov    $0x7,%edx
  mov    %r12,%rsi
  lea    D138(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L94
  movq   $0x4,(%rbx)
L94:
  mov    $0x7,%edx
  mov    %r12,%rsi
  lea    D76(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L177
  movq   $0x7,(%rbx)
L177:
  mov    $0xa,%edx
  mov    %r12,%rsi
  lea    D54(%rip),%rdi
  call   <strncasecmp@plt>
  mov    %r12,%rdx
  test   %eax,%eax
  jne    L160
  lea    D33(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L143
  mov    $0x15,%edx
  mov    %r12,%rsi
  lea    D139(%rip),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  mov    $0x22,%esi
  mov    %ebp,%edi
  call   <spaceball_waitcmd@plt>
  test   %rax,%rax
  jne    L143
  lea    D114(%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    L143
  mov    %r12,%rdx
  lea    D4(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  lea    D99(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  neg    %rax
  sbb    %eax,%eax
  jmp    L100
  nopl   0x0(%rax,%rax,1)
L160:
  lea    D131(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  lea    D105(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  test   %rax,%rax
  jne    L143
  mov    %r12,%rdx
  lea    D71(%rip),%rsi
  mov    %ebp,%edi
  call   <spaceball_cmd@plt>
  neg    %rax
  sbb    %eax,%eax
L100:
  mov    0x48(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L120
  add    $0x50,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L143:
  mov    $0xffffffff,%eax
  jmp    L100
L120:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D108
type_infered: string
name: unpack_data
arguments: label: D13
type_infered: string
name: unpack_data
arguments: label: D136
type_infered: string
name: unpack_data
arguments: label: D138
type_infered: string
name: unpack_data
arguments: label: D76
type_infered: string
name: unpack_data
arguments: label: D54
type_infered: string
name: unpack_data
arguments: label: D33
type_infered: string
name: unpack_data
arguments: label: D139
type_infered: string
name: unpack_data
arguments: label: D114
type_infered: string
name: unpack_data
arguments: label: D4
type_infered: string
name: unpack_data
arguments: label: D99
type_infered: string
name: unpack_data
arguments: label: D131
type_infered: string
name: unpack_data
arguments: label: D105
type_infered: string
name: unpack_data
arguments: label: D71
type_infered: string

tool: D108: @1 Spaceball alive

tool: D13: hm

tool: D136: Hm2003B

tool: D138: Hm2003C

tool: D76: Hm3003C

tool: D54: HvFirmware

tool: D33: "

tool: D139: "1 Spaceball 4000 FLX

tool: D114:  L 

tool: D4: YS

tool: D99: M

tool: D131: P@A@A

tool: D105: FT@

tool: D71: 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;
}
```