#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int configure_client_socket(char *IP_ADDRESS) {
  int sockfd;
  struct sockaddr_in address;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Client: Unable to create a socket.");
    return -1;
  }
  address.sin_family = AF_INET;
  address.sin_port = htons(4070);
  int check_IP;
  if ((check_IP = inet_aton(IP_ADDRESS, &address.sin_addr)) == 0) {
    fprintf(stderr, "Client: Invalid IP Address.\n");
    return -1;
  } else if (check_IP == -1) {
    fprintf(stderr, "Client: Unable to convert IP Address.\n");
    return -1;
  } else {
  }
  if (connect(sockfd, (struct sockaddr *)&address, sizeof(address)) == -1) {
    perror("Client: Unable to connect to server");
    return -1;
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<configure_client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11a9 <configure_client_socket+0x49>
lea    0xe68(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <configure_client_socket+0x109>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xfe6,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <inet_aton@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    11fc <configure_client_socket+0x9c>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <configure_client_socket+0x109>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1227 <configure_client_socket+0xc7>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <configure_client_socket+0x109>
jmp    122c <configure_client_socket+0xcc>
jmp    1231 <configure_client_socket+0xd1>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    1263 <configure_client_socket+0x103>
lea    0xe15(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <configure_client_socket+0x109>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configure_client_socket>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e75(%rip),%r15
mov    (%r15),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     1204 <configure_client_socket+0xa4>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0xfe6,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <inet_aton@plt>
cmp    $0xffffffff,%eax
je     11c8 <configure_client_socket+0x68>
test   %eax,%eax
jne    11e4 <configure_client_socket+0x84>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
jmp    11d8 <configure_client_socket+0x78>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11f8 <configure_client_socket+0x98>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
je     120d <configure_client_socket+0xad>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf5(%rip),%rdi
jmp    1214 <configure_client_socket+0xb4>
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
jmp    11dd <configure_client_socket+0x7d>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [35 x i8] c"Client: Unable to create a socket.\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Client: Invalid IP Address.\0A\00"
@.str.2 = [39 x i8] c"Client: Unable to convert IP Address.\0A\00"
@.str.3 = [36 x i8] c"Client: Unable to connect to server\00"
define i32 @configure_client_socket(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
13: ; preds = %1
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 4070)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i8*, i8** %3
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%20 = call i32 @inet_aton(i8* %18, i32* %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
25: ; preds = %13
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
31: ; preds = %25
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%36 = call i32 @connect(i32 %34, %struct.sockaddr* %35, i32 12)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
40: ; preds = %33
%41 = load i32, i32* %4
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %38, %28, %22, %11
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [35 x i8] c"Client: Unable to create a socket.\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Client: Invalid IP Address.\0A\00"
@.str.2 = [39 x i8] c"Client: Unable to convert IP Address.\0A\00"
@.str.3 = [36 x i8] c"Client: Unable to connect to server\00"
define i32 @configure_client_socket(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %29
10: ; preds = %1
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 4070)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%16 = call i32 @inet_aton(i8* %0, i32* %15)
switch i32 %16, label %23 [
i32 0, label %17
i32 -1, label %20
]
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %29
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %29
23: ; preds = %10
%24 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%25 = call i32 @connect(i32 %6, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %17, %20, %27, %23, %8
%30 = phi i32 [ -1, %8 ], [ -1, %17 ], [ -1, %20 ], [ -1, %27 ], [ %6, %23 ]
ret i32 %30
}