#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__ {
  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*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char const *);
int /*<<< orphan*/ raiseerr(int);
int /*<<< orphan*/ send_repl(int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int make_client_connection(int sock_fd, int client_port,
                           const char *client_addr) {
  if (client_port < 1) {
    send_repl(sock_fd, "425 Can't open data connection.\r\n");
    return -1;
  }
  int sock = -1;
  struct sockaddr_in servaddr;
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr(client_addr);
  servaddr.sin_port = htons(client_port);
  if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    send_repl(sock, "425 Can't open data connection.\r\n");
    raiseerr(15);
    return -1;
  }
  int status = connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr));
  if (status != 0) {
    send_repl(sock, "425 Can't open data connection.\r\n");
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<make_client_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    1197 <make_client_connection+0x37>
mov    -0x8(%rbp),%edi
lea    0xe7a(%rip),%rsi
call   1060 <send_repl@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <make_client_connection+0xf1>
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1212 <make_client_connection+0xb2>
mov    -0x1c(%rbp),%edi
lea    0xe09(%rip),%rsi
call   1060 <send_repl@plt>
mov    $0xf,%edi
call   1030 <raiseerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <make_client_connection+0xf1>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     124b <make_client_connection+0xeb>
mov    -0x1c(%rbp),%edi
lea    0xdc6(%rip),%rsi
call   1060 <send_repl@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <make_client_connection+0xf1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_client_connection>:
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11d2 <make_client_connection+0x72>
mov    %esi,%ebx
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %rdx,%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11e0 <make_client_connection+0x80>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <connect@plt>
test   %eax,%eax
je     11fd <make_client_connection+0x9d>
lea    0xe32(%rip),%rsi
mov    %ebx,%edi
jmp    11d9 <make_client_connection+0x79>
lea    0xe27(%rip),%rsi
call   1060 <send_repl@plt>
jmp    11f8 <make_client_connection+0x98>
lea    0xe19(%rip),%rsi
mov    %ebx,%edi
call   1060 <send_repl@plt>
mov    $0xf,%edi
call   1030 <raiseerr@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [34 x i8] c"425 Can't open data connection.\0D\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
define i32 @make_client_connection(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32, i32* %5
%15 = call i32 @send_repl(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %46
16: ; preds = %3
store i32 -1, i32* %8
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i8*, i8** %7
%20 = call i32 @inet_addr(i8* %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %6
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @PF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = load i32, i32* @IPPROTO_TCP
%29 = call i32 @socket(i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %16
%32 = load i32, i32* %8
%33 = call i32 @send_repl(i32 %32, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @raiseerr(i32 15)
store i32 -1, i32* %4
br label %46
35: ; preds = %16
%36 = load i32, i32* %8
%37 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%38 = call i32 @connect(i32 %36, %struct.sockaddr* %37, i32 12)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* %8
%43 = call i32 @send_repl(i32 %42, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %46
44: ; preds = %35
%45 = load i32, i32* %8
store i32 %45, i32* %4
br label %46
46: ; preds = %44, %41, %31, %13
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [34 x i8] c"425 Can't open data connection.\0D\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
define i32 @make_client_connection(i32 %0, i32 %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = icmp slt i32 %1, 1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @send_repl(i32 %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %32
8: ; preds = %3
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @inet_addr(i8* %2)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 %1)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @PF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = load i32, i32* @IPPROTO_TCP
%19 = tail call i32 @socket(i32 %16, i32 %17, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %8
%22 = tail call i32 @send_repl(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @raiseerr(i32 15)
br label %30
24: ; preds = %8
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i32 @connect(i32 %19, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @send_repl(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24, %21
%31 = phi i32 [ -1, %21 ], [ -1, %28 ], [ %19, %24 ]
br label %32
32: ; preds = %30, %6
%33 = phi i32 [ -1, %6 ], [ %31, %30 ]
ret i32 %33
}