#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  long s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
  int /*<<< orphan*/ h_addrtype;
};
typedef int /*<<< orphan*/ myaddress;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int Make_Connection(int port, char *buf) {
  struct hostent *host;
  static struct sockaddr_in myaddress;
  int v;
  host = gethostbyname(buf);
  if (host == NULL) {
    return (-1);
  }
  myaddress.sin_family = host->h_addrtype;
  myaddress.sin_addr.s_addr = *((long *)host->h_addr);
  myaddress.sin_port = htons(port);
  v = socket(AF_INET, SOCK_STREAM, 0);
  if (v == -1) {
    return (-1);
  }
  if (connect(v, (struct sockaddr *)&myaddress, sizeof(myaddress)) < 0) {
    close(v);
    return (-1);
  }
  return (v);
}


x86 assembly (clang, -O0):
<Make_Connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <Make_Connection+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <Make_Connection+0xc9>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,0x2ed0(%rip)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,0x2eb7(%rip)
mov    -0x8(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,0x2ea1(%rip)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e1 <Make_Connection+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <Make_Connection+0xc9>
mov    -0x1c(%rbp),%edi
lea    0x2e65(%rip),%rsi
mov    $0x18,%edx
call   1060 <connect@plt>
cmp    $0x0,%rax
jge    1213 <Make_Connection+0xc3>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <Make_Connection+0xc9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Make_Connection>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <gethostbyname@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11cd <Make_Connection+0x7d>
mov    0x8(%rax),%ecx
mov    %ecx,0x2ef0(%rip)
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,0x2edb(%rip)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x2ec6(%rip)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     11cd <Make_Connection+0x7d>
mov    %eax,%ebp
lea    0x2e9f(%rip),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1060 <connect@plt>
test   %rax,%rax
js     11c6 <Make_Connection+0x76>
mov    %ebp,%ebx
jmp    11cd <Make_Connection+0x7d>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i64, i32 }
%struct.sockaddr = type { i32 }
@Make_Connection.myaddress = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @Make_Connection(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.hostent*
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call %struct.hostent* @gethostbyname(i8* %8)
store %struct.hostent* %9, %struct.hostent** %6
%10 = load %struct.hostent*, %struct.hostent** %6
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %39
13: ; preds = %2
%14 = load %struct.hostent*, %struct.hostent** %6
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @Make_Connection.myaddress, i32 0, i32 2)
%17 = load %struct.hostent*, %struct.hostent** %6
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i64*
%21 = load i64, i64* %20
store i64 %21, i64* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @Make_Connection.myaddress, i32 0, i32 1, i32 0)
%22 = load i32, i32* %4
%23 = call i32 @htons(i32 %22)
store i32 %23, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @Make_Connection.myaddress, i32 0, i32 0)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %13
store i32 -1, i32* %3
br label %39
30: ; preds = %13
%31 = load i32, i32* %7
%32 = call i64 @connect(i32 %31, %struct.sockaddr* bitcast (%struct.sockaddr_in* @Make_Connection.myaddress to %struct.sockaddr*), i32 24)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
store i32 -1, i32* %3
br label %39
37: ; preds = %30
%38 = load i32, i32* %7
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %34, %29, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i64, i32 }
%struct.sockaddr = type { i32 }
@Make_Connection.myaddress = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @Make_Connection(i32 %0, i8* %1) {
%3 = tail call %struct.hostent* @gethostbyname(i8* %1)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%7 = load i32, i32* %6
store i32 %7, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @Make_Connection.myaddress, i64 0, i32 2)
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i64*
%11 = load i64, i64* %10
store i64 %11, i64* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @Make_Connection.myaddress, i64 0, i32 1, i32 0)
%12 = tail call i32 @htons(i32 %0)
store i32 %12, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @Make_Connection.myaddress, i64 0, i32 0)
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %22, label %17
17: ; preds = %5
%18 = tail call i64 @connect(i32 %15, %struct.sockaddr* bitcast (%struct.sockaddr_in* @Make_Connection.myaddress to %struct.sockaddr*), i32 24)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @close(i32 %15)
br label %22
22: ; preds = %17, %5, %2, %20
%23 = phi i32 [ -1, %20 ], [ -1, %2 ], [ -1, %5 ], [ %15, %17 ]
ret i32 %23
}