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

```asm
<tcp_client>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  lea    -0x400000(%rsp),%r11
L82:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L82
  sub    $0x60,%rsp
  mov    %rdi,-0x400058(%rbp)
  mov    %esi,%eax
  mov    %ax,-0x40005c(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movabs $0x736f686c61636f6c,%rax
  mov    %rax,-0x12(%rbp)
  movw   $0x74,-0xa(%rbp)
  movl   $0x10,-0x400044(%rbp)
  movzwl -0x40005c(%rbp),%edx
  lea    -0x18(%rbp),%rax
  mov    %edx,%ecx
  lea    D20(%rip),%rdx
  mov    $0x6,%esi
  mov    %rax,%rdi
  call   <snprintf@plt>
  lea    -0x400038(%rbp),%rdx
  lea    -0x18(%rbp),%rsi
  lea    -0x12(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x0,%edx
  mov    %rax,%rdi
  call   <getaddrinfo@plt>
  mov    %eax,-0x400040(%rbp)
  cmpl   $0x0,-0x400040(%rbp)
  je     L121
  mov    -0x400040(%rbp),%eax
  jmp    L63
L121:
  mov    -0x400038(%rbp),%rax
  mov    0x8(%rax),%edx
  mov    -0x400038(%rbp),%rax
  mov    0xc(%rax),%ecx
  mov    -0x400038(%rbp),%rax
  mov    0x10(%rax),%eax
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <socket@plt>
  mov    %eax,-0x40003c(%rbp)
  cmpl   $0x0,-0x40003c(%rbp)
  js     L85
  mov    -0x400038(%rbp),%rax
  mov    (%rax),%edx
  mov    -0x400038(%rbp),%rax
  mov    0x4(%rax),%ecx
  mov    -0x40003c(%rbp),%eax
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <connect@plt>
  mov    %eax,-0x400040(%rbp)
  cmpl   $0x0,-0x400040(%rbp)
  js     L142
  movl   $0x1,-0x400040(%rbp)
  jmp    L10
L186:
  lea    -0x400020(%rbp),%rcx
  mov    -0x40003c(%rbp),%eax
  mov    $0x400000,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  test   %rax,%rax
  jle    L40
  mov    -0x400058(%rbp),%rax
  lea    D0(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <cg_read_long@plt>
  mov    %rax,-0x400030(%rbp)
  mov    -0x400058(%rbp),%rax
  lea    D4(%rip),%rdx
  lea    D17(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <cg_read_key_long@plt>
  mov    %rax,-0x400028(%rbp)
  cmpq   $0x0,-0x400030(%rbp)
  js     L72
  cmpq   $0x0,-0x400028(%rbp)
  js     L72
  mov    -0x400030(%rbp),%rax
  cmp    -0x400028(%rbp),%rax
  jl     L0
  mov    -0x400028(%rbp),%rcx
  mov    -0x400030(%rbp),%rax
  mov    $0xa,%edx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <values_close@plt>
  test   %rax,%rax
  je     L10
  movl   $0x0,-0x400040(%rbp)
  jmp    L8
L10:
  mov    -0x400044(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x400044(%rbp)
  test   %eax,%eax
  jne    L186
  jmp    L8
L142:
  nop
  jmp    L8
L40:
  nop
  jmp    L8
L72:
  nop
  jmp    L8
L0:
  nop
L8:
  mov    -0x40003c(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  jmp    L162
L85:
  nop
L162:
  mov    -0x400038(%rbp),%rax
  mov    %rax,%rdi
  call   <freeaddrinfo@plt>
  mov    -0x400040(%rbp),%eax
L63:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L176
  call   <__stack_chk_fail@plt>
L176:
  leave
  ret
```

tool_calls: name: read_data
arguments: data_label: D20
datatype: string
name: read_data
arguments: data_label: D0
datatype: string
name: read_data
arguments: data_label: D4
datatype: string
name: read_data
arguments: data_label: D17
datatype: string

tool: D20: %hd

tool: D0: memory.current

tool: D4: sock 

tool: D17: memory.stat

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;
}
```