user: Converte this assembly snippet into its equivalent C code:

```asm
<ss_listen_on_ipv4_socket_impl>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  mov    %edx,%ebp
  mov    $0xc,%edx
  push   %rbx
  mov    %esi,%ebx
  xor    %esi,%esi
  sub    $0x20,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%r13
  mov    %r13,%rdi
  call   <memset@plt>
  mov    D41(%rip),%r14
  mov    (%r14),%edi
  mov    %edi,0x14(%rsp)
  test   %r12,%r12
  je     L80
  lea    0x10(%rsp),%rdx
  mov    %r12,%rsi
  call   <inet_pton@plt>
  cmp    $0x1,%eax
  jne    L19
L64:
  mov    D78(%rip),%rax
  mov    (%r14),%edi
  xor    %edx,%edx
  mov    (%rax),%esi
  call   <socket@plt>
  mov    %eax,%r12d
  cmp    $0xffffffff,%eax
  je     L74
  mov    D59(%rip),%rax
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <fcntl@plt>
  mov    D37(%rip),%rdx
  mov    %r12d,%edi
  or     (%rdx),%eax
  mov    %eax,%edx
  mov    D51(%rip),%rax
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <fcntl@plt>
  mov    D13(%rip),%rax
  lea    0x8(%rsp),%rcx
  mov    %r12d,%edi
  mov    $0x4,%r8d
  movl   $0x1,0x8(%rsp)
  mov    (%rax),%edx
  mov    D68(%rip),%rax
  mov    (%rax),%esi
  call   <setsockopt@plt>
  movzwl %bx,%edi
  call   <htons@plt>
  mov    $0xc,%edx
  mov    %r13,%rsi
  mov    %r12d,%edi
  mov    %eax,0xc(%rsp)
  call   <bind@plt>
  cmp    $0xffffffff,%eax
  je     L2
  mov    %ebp,%esi
  mov    %r12d,%edi
  call   <listen@plt>
  cmp    $0xffffffff,%eax
  je     L9
L77:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L16
  add    $0x20,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  nopl   (%rax)
L80:
  mov    D18(%rip),%rax
  mov    (%rax),%edi
  call   <htonl@plt>
  mov    %eax,0x10(%rsp)
  jmp    L64
  nop
L19:
  mov    $0xffffffff,%r12d
  jmp    L77
  nopl   0x0(%rax,%rax,1)
L74:
  mov    $0xfffffffe,%r12d
  jmp    L77
L2:
  mov    D43(%rip),%rbx
  mov    %r12d,%edi
  mov    $0xfffffffd,%r12d
  mov    (%rbx),%ebp
  call   <close@plt>
  mov    %ebp,(%rbx)
  jmp    L77
L9:
  mov    D43(%rip),%rbx
  mov    %r12d,%edi
  mov    $0xfffffffc,%r12d
  mov    (%rbx),%ebp
  call   <close@plt>
  mov    %ebp,(%rbx)
  jmp    L77
L16:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int ss_listen_on_ipv4_socket_impl(const char *address, unsigned short port, int backlog) {
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  if (address) {
    if (!(inet_pton(AF_INET, address, &(addr.sin_addr)) == 1))
      return -1;
  } else
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock == -1)
    return -2;
  fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC);
  int optval = 1;
  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
  addr.sin_port = htons(port);
  if ((bind(sock, (struct sockaddr *)&addr, sizeof(addr))) == -1) {
    int saved_errno = errno;
    close(sock);
    errno = saved_errno;
    return -3;
  }
  if ((listen(sock, backlog)) == -1) {
    int saved_errno = errno;
    close(sock);
    errno = saved_errno;
    return -4;
  }
  return sock;
}
```