#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 */
typedef int /*<<< orphan*/ ushort;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int create_client_socket(char *host, int port) {
  int sockfd, len, result;
  struct sockaddr_in address;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = inet_addr(host);
  address.sin_port = htons((ushort)port);
  len = sizeof(address);
  result = connect(sockfd, (struct sockaddr *)&address, len);
  if (result == -1)
    return -1;
  return sockfd;
}


x86 assembly (clang, -O0):
<create_client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11bd <create_client_socket+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <create_client_socket+0x83>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_client_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e91(%rip),%r15
mov    (%r15),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1050 <connect@plt>
cmp    $0xffffffff,%eax
cmovne %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @create_client_socket(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i8*, i8** %4
%16 = call i32 @inet_addr(i8* %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* %5
%20 = call i32 @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %20, i32* %21
store i32 12, i32* %7
%22 = load i32, i32* %6
%23 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%24 = load i32, i32* %7
%25 = call i32 @connect(i32 %22, %struct.sockaddr* %23, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %2
store i32 -1, i32* %3
br label %31
29: ; preds = %2
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %28
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @create_client_socket(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @inet_addr(i8* %0)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 %1)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %12, i32* %13
%14 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%15 = call i32 @connect(i32 %7, %struct.sockaddr* %14, i32 12)
%16 = icmp eq i32 %15, -1
%17 = select i1 %16, i32 -1, i32 %7
ret i32 %17
}