#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct addrinfo {
  int dummy;
};

/* Variables and functions */
int connect_by_addrinfo(struct addrinfo *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char const *, char const *, int /*<<< orphan*/ *,
                       struct addrinfo **);
int connect_to(const char *remote_addr, const char *remote_port) {
  struct addrinfo *address_info;
  int handle_socket;
  if (getaddrinfo(remote_addr, remote_port, NULL, &address_info) != 0) {
    return -1;
  }
  handle_socket = connect_by_addrinfo(address_info);
  freeaddrinfo(address_info);
  return handle_socket;
}


x86 assembly (clang, -O0):
<connect_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
call   1040 <getaddrinfo@plt>
cmp    $0x0,%rax
je     116b <connect_to+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <connect_to+0x56>
mov    -0x20(%rbp),%rdi
call   1030 <connect_by_addrinfo@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <freeaddrinfo@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_to>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1040 <getaddrinfo@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1161 <connect_to+0x31>
mov    0x8(%rsp),%rdi
call   1030 <connect_by_addrinfo@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1050 <freeaddrinfo@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32 }
define i32 @connect_to(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.addrinfo*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i64 @getaddrinfo(i8* %8, i8* %9, i32* null, %struct.addrinfo** %6)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %19
13: ; preds = %2
%14 = load %struct.addrinfo*, %struct.addrinfo** %6
%15 = call i32 @connect_by_addrinfo(%struct.addrinfo* %14)
store i32 %15, i32* %7
%16 = load %struct.addrinfo*, %struct.addrinfo** %6
%17 = call i32 @freeaddrinfo(%struct.addrinfo* %16)
%18 = load i32, i32* %7
store i32 %18, i32* %3
br label %19
19: ; preds = %13, %12
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
define i32 @connect_to(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo** %3 to i8*
%5 = call i64 @getaddrinfo(i8* %0, i8* %1, i32* null, %struct.addrinfo** %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load %struct.addrinfo*, %struct.addrinfo** %3
%9 = call i32 @connect_by_addrinfo(%struct.addrinfo* %8)
%10 = load %struct.addrinfo*, %struct.addrinfo** %3
%11 = call i32 @freeaddrinfo(%struct.addrinfo* %10)
br label %12
12: ; preds = %2, %7
%13 = phi i32 [ %9, %7 ], [ -1, %2 ]
ret i32 %13
}