#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 /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  scalar_t__ ai_flags;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, ...);
int create_prx2srv_con(const char **argv) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int ret;
  int srv_sockfd = -1;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  ret = getaddrinfo(argv[2], argv[3], &hints, &result);
  if (0 != ret) {
    syslog(LOG_ERR,
           "[%d]Please input an appropriate service port!\n\r (%s)\r\n", 272,
           gai_strerror(ret));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    srv_sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (-1 == srv_sockfd) {
      continue;
    }
    if (0 == connect(srv_sockfd, rp->ai_addr, rp->ai_addrlen)) {
      break;
    } else {
      close(srv_sockfd);
      syslog(LOG_ERR, "[%d] failed to connect --srv_sockfd:%d (%m)!\r\n", 288,
             srv_sockfd);
      continue;
    }
  }
  freeaddrinfo(result);
  if (NULL == rp) {
    syslog(LOG_ERR, "[%d] failed to connect to server!\r\n", 295);
    return -1;
  }
  return srv_sockfd;
}


x86 assembly (clang, -O0):
<create_prx2srv_con>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x50(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x4c(%rbp)
xor    %eax,%eax
cmp    -0x4c(%rbp),%eax
je     1240 <create_prx2srv_con+0xb0>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x4c(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x54(%rbp),%edi
mov    %eax,%ecx
lea    0xdda(%rip),%rsi
mov    $0x110,%edx
mov    $0x0,%al
call   1060 <syslog@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12e4 <create_prx2srv_con+0x154>
mov    -0x48(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdx
call   10b0 <socket@plt>
mov    %eax,-0x50(%rbp)
mov    $0xffffffff,%eax
cmp    -0x50(%rbp),%eax
jne    1284 <create_prx2srv_con+0xf4>
jmp    12d3 <create_prx2srv_con+0x143>
mov    -0x50(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   1080 <connect@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12ac <create_prx2srv_con+0x11c>
jmp    12e4 <create_prx2srv_con+0x154>
mov    -0x50(%rbp),%edi
call   1050 <close@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%ecx
lea    0xd70(%rip),%rsi
mov    $0x120,%edx
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1248 <create_prx2srv_con+0xb8>
mov    -0x40(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
xor    %eax,%eax
cmp    -0x48(%rbp),%rax
jne    1321 <create_prx2srv_con+0x191>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    $0x127,%edx
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1327 <create_prx2srv_con+0x197>
mov    -0x50(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_prx2srv_con>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x10(%rbx),%rdi
mov    0x18(%rbx),%rsi
lea    0x8(%rsp),%rcx
mov    %rbp,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    12b5 <create_prx2srv_con+0x125>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1274 <create_prx2srv_con+0xe4>
mov    0x2db5(%rip),%r15
lea    0xe25(%rip),%r14
jmp    1229 <create_prx2srv_con+0x99>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     126d <create_prx2srv_con+0xdd>
mov    0x14(%rbx),%edi
mov    0x10(%rbx),%esi
mov    0x8(%rbx),%rdx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1220 <create_prx2srv_con+0x90>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1080 <connect@plt>
test   %rax,%rax
je     129e <create_prx2srv_con+0x10e>
mov    %ebp,%edi
call   1050 <close@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x120,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
jmp    1220 <create_prx2srv_con+0x90>
mov    0x8(%rsp),%rdi
jmp    1276 <create_prx2srv_con+0xe6>
xor    %edi,%edi
call   10a0 <freeaddrinfo@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
mov    $0x127,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xffffffff,%ebp
jmp    12a8 <create_prx2srv_con+0x118>
mov    0x8(%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d04(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xd34(%rip),%rsi
mov    %ebx,%edi
mov    $0x110,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i64, i32, i32, %struct.addrinfo*, i64 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [55 x i8] c"[%d]Please input an appropriate service port!\0A\0D (%s)\0D\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [47 x i8] c"[%d] failed to connect --srv_sockfd:%d (%m)!\0D\0A\00"
@.str.2 = [36 x i8] c"[%d] failed to connect to server!\0D\0A\00"
define i32 @create_prx2srv_con(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %3
store i32 -1, i32* %8
%9 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 40)
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 3
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 6
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 2
store i64 0, i64* %15
%16 = load i8**, i8*** %3
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %3
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @getaddrinfo(i8* %18, i8* %21, %struct.addrinfo* %4, %struct.addrinfo** %5)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp ne i32 0, %23
br i1 %24, label %25, label %32
25: ; preds = %1
%26 = load i32, i32* @LOG_ERR
%27 = load i32, i32* %7
%28 = call i32 @gai_strerror(i32 %27)
%29 = call i32 (i32, i8*, i32, ...) @syslog(i32 %26, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 272, i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %1
%33 = load %struct.addrinfo*, %struct.addrinfo** %5
store %struct.addrinfo* %33, %struct.addrinfo** %6
br label %34
34: ; preds = %68, %32
%35 = load %struct.addrinfo*, %struct.addrinfo** %6
%36 = icmp ne %struct.addrinfo* %35, null
br i1 %36, label %37, label %72
37: ; preds = %34
%38 = load %struct.addrinfo*, %struct.addrinfo** %6
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 4
%40 = load i32, i32* %39
%41 = load %struct.addrinfo*, %struct.addrinfo** %6
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 3
%43 = load i32, i32* %42
%44 = load %struct.addrinfo*, %struct.addrinfo** %6
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 2
%46 = load i64, i64* %45
%47 = call i32 @socket(i32 %40, i32 %43, i64 %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp eq i32 -1, %48
br i1 %49, label %50, label %51
50: ; preds = %37
br label %68
51: ; preds = %37
%52 = load i32, i32* %8
%53 = load %struct.addrinfo*, %struct.addrinfo** %6
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %6
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i64 @connect(i32 %52, i32 %55, i32 %58)
%60 = icmp eq i64 0, %59
br i1 %60, label %61, label %62
61: ; preds = %51
br label %72
62: ; preds = %51
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* @LOG_ERR
%66 = load i32, i32* %8
%67 = call i32 (i32, i8*, i32, ...) @syslog(i32 %65, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 288, i32 %66)
br label %68
68: ; preds = %62, %50
%69 = load %struct.addrinfo*, %struct.addrinfo** %6
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 5
%71 = load %struct.addrinfo*, %struct.addrinfo** %70
store %struct.addrinfo* %71, %struct.addrinfo** %6
br label %34
72: ; preds = %61, %34
%73 = load %struct.addrinfo*, %struct.addrinfo** %5
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %73)
%75 = load %struct.addrinfo*, %struct.addrinfo** %6
%76 = icmp eq %struct.addrinfo* null, %75
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* @LOG_ERR
%79 = call i32 (i32, i8*, i32, ...) @syslog(i32 %78, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 295)
store i32 -1, i32* %2
br label %82
80: ; preds = %72
%81 = load i32, i32* %8
store i32 %81, i32* %2
br label %82
82: ; preds = %80, %77
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, %struct.addrinfo*, i64 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [55 x i8] c"[%d]Please input an appropriate service port!\0A\0D (%s)\0D\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [47 x i8] c"[%d] failed to connect --srv_sockfd:%d (%m)!\0D\0A\00"
@.str.2 = [36 x i8] c"[%d] failed to connect to server!\0D\0A\00"
define i32 @create_prx2srv_con(i8** nocapture %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo* %2 to i8*
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 40)
%7 = load i32, i32* @AF_UNSPEC
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 4
store i32 %7, i32* %8
%9 = load i32, i32* @SOCK_STREAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 3
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 6
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 2
store i64 0, i64* %12
%13 = getelementptr inbounds i8*, i8** %0, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %0, i64 3
%16 = load i8*, i8** %15
%17 = call i32 @getaddrinfo(i8* %14, i8* %16, %struct.addrinfo* %2, %struct.addrinfo** %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %1
%20 = load %struct.addrinfo*, %struct.addrinfo** %3
%21 = icmp eq %struct.addrinfo* %20, null
br i1 %21, label %58, label %28
22: ; preds = %1
%23 = load i32, i32* @LOG_ERR
%24 = call i32 @gai_strerror(i32 %17)
%25 = call i32 (i32, i8*, i32, ...) @syslog(i32 %23, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 272, i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19, %49
%29 = phi %struct.addrinfo* [ %51, %49 ], [ %20, %19 ]
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 3
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 2
%35 = load i64, i64* %34
%36 = call i32 @socket(i32 %31, i32 %33, i64 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %49, label %38
38: ; preds = %28
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @connect(i32 %36, i32 %40, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %53, label %45
45: ; preds = %38
%46 = call i32 @close(i32 %36)
%47 = load i32, i32* @LOG_ERR
%48 = call i32 (i32, i8*, i32, ...) @syslog(i32 %47, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 288, i32 %36)
br label %49
49: ; preds = %28, %45
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 5
%51 = load %struct.addrinfo*, %struct.addrinfo** %50
%52 = icmp eq %struct.addrinfo* %51, null
br i1 %52, label %56, label %28
53: ; preds = %38
%54 = load %struct.addrinfo*, %struct.addrinfo** %3
%55 = call i32 @freeaddrinfo(%struct.addrinfo* %54)
br label %63
56: ; preds = %49
%57 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %58
58: ; preds = %56, %19
%59 = phi %struct.addrinfo* [ %57, %56 ], [ null, %19 ]
%60 = call i32 @freeaddrinfo(%struct.addrinfo* %59)
%61 = load i32, i32* @LOG_ERR
%62 = call i32 (i32, i8*, i32, ...) @syslog(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 295)
br label %63
63: ; preds = %53, %58
%64 = phi i32 [ -1, %58 ], [ %36, %53 ]
ret i32 %64
}