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

```asm
<tcp_client>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x400000(%rsp),%r11
L6:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L6
  sub    $0x48,%rsp
  lea    D13(%rip),%rdx
  mov    %fs:0x28,%rax
  mov    %rax,0x400038(%rsp)
  movabs $0x736f686c61636f6c,%rax
  lea    0x400028(%rsp),%rbp
  movzwl %si,%ecx
  mov    %rdi,%rbx
  mov    $0x6,%esi
  mov    %rbp,%rdi
  mov    %rax,0x40002e(%rsp)
  mov    $0x74,%eax
  mov    %ax,0x400036(%rsp)
  call   <snprintf@plt>
  lea    0x18(%rsp),%rcx
  xor    %edx,%edx
  mov    %rbp,%rsi
  lea    0x40002e(%rsp),%rdi
  call   <getaddrinfo@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  je     L76
L27:
  mov    0x400038(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L51
  add    $0x400048,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L76:
  mov    0x18(%rsp),%rax
  mov    0x8(%rax),%edx
  mov    0xc(%rax),%esi
  mov    0x10(%rax),%edi
  call   <socket@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  js     L3
  mov    0x18(%rsp),%rax
  mov    %ebp,%edi
  mov    0x4(%rax),%esi
  mov    (%rax),%edx
  call   <connect@plt>
  test   %eax,%eax
  js     L75
  movl   $0x10,0xc(%rsp)
  lea    0x20(%rsp),%r13
  lea    D39(%rip),%r15
  nopw   0x0(%rax,%rax,1)
L13:
  mov    $0x400000,%edx
  mov    %r13,%rsi
  mov    %ebp,%edi
  call   <read@plt>
  test   %rax,%rax
  jle    L0
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <cg_read_long@plt>
  lea    D7(%rip),%rsi
  lea    D25(%rip),%rdx
  mov    %rbx,%rdi
  mov    %rax,%r14
  call   <cg_read_key_long@plt>
  mov    %rax,%rsi
  mov    %r14,%rax
  or     %rsi,%rax
  js     L0
  cmp    %rsi,%r14
  jl     L0
  mov    $0xa,%edx
  mov    %r14,%rdi
  call   <values_close@plt>
  test   %rax,%rax
  jne    L9
  subl   $0x1,0xc(%rsp)
  jne    L13
L0:
  mov    $0x1,%r12d
L9:
  mov    %ebp,%edi
  call   <close@plt>
L3:
  mov    0x18(%rsp),%rdi
  call   <freeaddrinfo@plt>
  jmp    L27
  nopl   (%rax)
L75:
  mov    %eax,%r12d
  jmp    L9
L51:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_label: D13
type: string
name: unpack_data
arguments: data_label: D39
type: string
name: unpack_data
arguments: data_label: D7
type: string
name: unpack_data
arguments: data_label: D25
type: string

tool: D13: %hd

tool: D39: memory.current

tool: D7: memory.stat

tool: D25: sock 

assistant: ```c
int tcp_client(const char *cgroup, unsigned short port) {
  const char server[] = "localhost";
  struct addrinfo *ai;
  char servport[6];
  int retries = 0x10;
  int sk, ret;
  snprintf(servport, sizeof(servport), "%hd", port);
  ret = getaddrinfo(server, servport, NULL, &ai);
  if (ret)
    return ret;
  sk = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
  if (sk < 0)
    goto free_ainfo;
  ret = connect(sk, ai->ai_addr, ai->ai_addrlen);
  if (ret < 0)
    goto close_sk;
  ret = 1;
  while (retries--) {
    uint8_t buf[0x100000];
    long current, sock;
    if (read(sk, buf, sizeof(buf)) <= 0)
      goto close_sk;
    current = cg_read_long(cgroup, "memory.current");
    sock = cg_read_key_long(cgroup, "memory.stat", "sock ");
    if (current < 0 || sock < 0)
      goto close_sk;
    if (current < sock)
      goto close_sk;
    if (values_close(current, sock, 10)) {
      ret = 0;
      break;
    }
  }
close_sk:
  close(sk);
free_ainfo:
  freeaddrinfo(ai);
  return ret;
}
```