// File: halfflat[P]tinyopt/test/googletest/googletest/src/gtest.cc
// Function: testing::internal::StreamingListener::SocketWriter::MakeConnection()
void StreamingListener::SocketWriter::MakeConnection() {
  GTEST_CHECK_(sockfd_ == -1)
      << "MakeConnection() can't be called when there is already a connection.";

  addrinfo hints;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;  // To allow both IPv4 and IPv6 addresses.
  hints.ai_socktype = SOCK_STREAM;
  addrinfo* servinfo = nullptr;

  // Use the getaddrinfo() to get a linked list of IP addresses for
  // the given host name.
  const int error_num =
      getaddrinfo(host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
  if (error_num != 0) {
    GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: "
                        << gai_strerror(error_num);
  }

  // Loop through all the results and connect to the first we can.
  for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != nullptr;
       cur_addr = cur_addr->ai_next) {
    sockfd_ = socket(cur_addr->ai_family, cur_addr->ai_socktype,
                     cur_addr->ai_protocol);
    if (sockfd_ != -1) {
      // Connect the client socket to the server socket.
      if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
        close(sockfd_);
        sockfd_ = -1;
      }
    }
  }

  freeaddrinfo(servinfo);  // all done with this structure

  if (sockfd_ == -1) {
    GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to "
                        << host_name_ << ":" << port_num_;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpl $-0x1, 0x8(%rax)
sete %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x78790
testb $0x1, %al
jne 0x9971f
jmp 0x99724
jmp 0x997aa
leaq 0x34990(%rip), %rdx     # 0xce0bb
leaq -0xc(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movl $0x3, %esi
movl $0x1351, %ecx           # imm = 0x1351
callq 0x7d880
movq -0x88(%rbp), %rdi
callq 0x1f280
movq %rax, -0x80(%rbp)
jmp 0x99757
movq -0x80(%rbp), %rdi
leaq 0x35987(%rip), %rsi     # 0xcf0e9
callq 0x10720
movq %rax, -0x90(%rbp)
jmp 0x99770
movq -0x90(%rbp), %rdi
leaq 0x3598c(%rip), %rsi     # 0xcf10a
callq 0x10720
jmp 0x99785
leaq -0xc(%rbp), %rdi
callq 0x7d9c0
jmp 0x997aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x7d9c0
jmp 0x99a31
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x103f0
movq -0x78(%rbp), %rdi
movl $0x0, -0x4c(%rbp)
movl $0x1, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
addq $0x10, %rdi
callq 0x102c0
movq -0x78(%rbp), %rdi
movq %rax, -0x98(%rbp)
addq $0x30, %rdi
callq 0x102c0
movq -0x98(%rbp), %rdi
movq %rax, %rsi
leaq -0x50(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x10a30
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x998a5
leaq 0x3489f(%rip), %rdx     # 0xce0bb
leaq -0x60(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
movl $0x1, %esi
movl $0x135f, %ecx           # imm = 0x135F
callq 0x7d880
movq -0xa8(%rbp), %rdi
callq 0x1f280
movq %rax, -0xa0(%rbp)
jmp 0x9984b
movq -0xa0(%rbp), %rdi
leaq 0x358f6(%rip), %rsi     # 0xcf14f
callq 0x10720
movq %rax, -0xb0(%rbp)
jmp 0x99867
movl -0x5c(%rbp), %edi
callq 0x10b70
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x10720
jmp 0x99880
leaq -0x60(%rbp), %rdi
callq 0x7d9c0
jmp 0x998a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x7d9c0
jmp 0x99a31
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rcx
xorl %eax, %eax
cmpl $-0x1, 0x8(%rcx)
movb %al, -0xb1(%rbp)
jne 0x998cd
cmpq $0x0, -0x68(%rbp)
setne %al
movb %al, -0xb1(%rbp)
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x998d9
jmp 0x9994e
movq -0x68(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x68(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x101a0
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpl $-0x1, 0x8(%rax)
je 0x9993b
movq -0x78(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x68(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x105f0
cmpl $-0x1, %eax
jne 0x99939
movq -0x78(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x10f60
movq -0x78(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
jmp 0x9993b
jmp 0x9993d
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x998ad
movq -0x58(%rbp), %rdi
callq 0x10aa0
movq -0x78(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
jne 0x99a28
leaq 0x3474f(%rip), %rdx     # 0xce0bb
leaq -0x6c(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
movl $0x1, %esi
movl $0x1374, %ecx           # imm = 0x1374
callq 0x7d880
movq -0xc8(%rbp), %rdi
callq 0x1f280
movq %rax, -0xc0(%rbp)
jmp 0x9999b
movq -0xc0(%rbp), %rdi
leaq 0x357cf(%rip), %rsi     # 0xcf178
callq 0x10720
movq %rax, -0xd0(%rbp)
jmp 0x999b7
movq -0xd0(%rbp), %rdi
movq -0x78(%rbp), %rsi
addq $0x10, %rsi
callq 0x10680
movq %rax, -0xd8(%rbp)
jmp 0x999d4
movq -0xd8(%rbp), %rdi
leaq 0x305a5(%rip), %rsi     # 0xc9f87
callq 0x10720
movq %rax, -0xe0(%rbp)
jmp 0x999f0
movq -0xe0(%rbp), %rdi
movq -0x78(%rbp), %rsi
addq $0x30, %rsi
callq 0x10680
jmp 0x99a06
leaq -0x6c(%rbp), %rdi
callq 0x7d9c0
jmp 0x99a28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x6c(%rbp), %rdi
callq 0x7d9c0
jmp 0x99a31
addq $0xe0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x10e00
nopw (%rax,%rax)