#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 uint16_t;
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ TCP_NODELAY;
scalar_t__ bind(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char const *, char *, struct addrinfo *, struct addrinfo **);
scalar_t__ htonl(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ printf(char *, char const *, int, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int TCPCreate(const char *serv, uint16_t port, int isbind) {
  int sockfd = -1;
  char portstr[32];
  struct addrinfo hints, *res, *ressave;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if (isbind) {
    hints.ai_flags = AI_PASSIVE;
  } else {
    if (!serv || !serv[0]) {
      printf("SockAPI_Create	param error for %s:%d bind:%d\n",
             serv ? serv : "NULL", port, isbind);
      return -1;
    }
  }
  sprintf(portstr, "%d", port);
  int ret = getaddrinfo(serv, portstr, &hints, &res);
  if (ret != 0) {
    printf("SockAPI_Create getaddr fail for %s:%d bind:%d\n",
           serv ? serv : "NULL", port, isbind);
    return -1;
  }
  ressave = res;
  do {
    struct sockaddr_in *paddr = (struct sockaddr_in *)res->ai_addr;
    if (isbind) {
      if (paddr->sin_addr.s_addr == htonl(0x7f000001))
        continue;
    } else {
      if (paddr->sin_addr.s_addr == 0)
        continue;
    }
    sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (sockfd < 0) {
      printf("SockAPI_Create getsock fail for %s:%d bind:%d\n",
             serv ? serv : "NULL", port, isbind);
      continue;
    }
    int on = 1;
    if (isbind) {
      if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) {
        printf("SockAPI_Create reuse port fail for %s:%d bind:%d\n",
               serv ? serv : "NULL", port, isbind);
      }
      if (bind(sockfd, res->ai_addr, res->ai_addrlen) == 0 &&
          listen(sockfd, 15) == 0) {
        break;
      }
    } else {
      if (connect(sockfd, res->ai_addr, res->ai_addrlen) == 0) {
        break;
      }
      setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
    }
    close(sockfd);
    sockfd = -1;
    printf("SockAPI_Create init sock fail for %s:%d bind:%d\n",
           serv ? serv : "NULL", port, isbind);
  } while ((res = res->ai_next) != NULL);
  freeaddrinfo(ressave);
  if (sockfd >= 0)
    return sockfd;
  printf("SockAPI_Create fatal create fail for %s:%d bind:%d\n",
         serv ? serv : "NULL", port, isbind);
  return -1;
}


x86 assembly (clang, -O0):
<TCPCreate>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x30,%esi
call   1090 <bzero@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     121d <TCPCreate+0x5d>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
jmp    128d <TCPCreate+0xcd>
cmpq   $0x0,-0x10(%rbp)
je     1235 <TCPCreate+0x75>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1288 <TCPCreate+0xc8>
cmpq   $0x0,-0x10(%rbp)
je     1250 <TCPCreate+0x90>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
jmp    1263 <TCPCreate+0xa3>
lea    0xdd7(%rip),%rax
mov    %rax,-0xa0(%rbp)
jmp    1263 <TCPCreate+0xa3>
mov    -0xa0(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd89(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f3 <TCPCreate+0x433>
jmp    128d <TCPCreate+0xcd>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd98(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x78(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     131b <TCPCreate+0x15b>
cmpq   $0x0,-0x10(%rbp)
je     12e3 <TCPCreate+0x123>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
jmp    12f6 <TCPCreate+0x136>
lea    0xd44(%rip),%rax
mov    %rax,-0xa8(%rbp)
jmp    12f6 <TCPCreate+0x136>
mov    -0xa8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd2c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f3 <TCPCreate+0x433>
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x90(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1374 <TCPCreate+0x1b4>
mov    -0x90(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xb0(%rbp)
mov    $0x7f000001,%edi
call   1050 <htonl@plt>
mov    %rax,%rcx
mov    -0xb0(%rbp),%rax
cmp    %rcx,%rax
jne    136f <TCPCreate+0x1af>
jmp    1571 <TCPCreate+0x3b1>
jmp    138f <TCPCreate+0x1cf>
mov    -0x90(%rbp),%rax
cmpq   $0x0,(%rax)
jne    138a <TCPCreate+0x1ca>
jmp    1571 <TCPCreate+0x3b1>
jmp    138f <TCPCreate+0x1cf>
mov    -0x78(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x78(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x78(%rbp),%rax
mov    0x10(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1402 <TCPCreate+0x242>
cmpq   $0x0,-0x10(%rbp)
je     13d1 <TCPCreate+0x211>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
jmp    13e4 <TCPCreate+0x224>
lea    0xc56(%rip),%rax
mov    %rax,-0xb8(%rbp)
jmp    13e4 <TCPCreate+0x224>
mov    -0xb8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xc6d(%rip),%rdi
call   1040 <printf@plt>
jmp    1571 <TCPCreate+0x3b1>
movl   $0x1,-0x94(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     14cf <TCPCreate+0x30f>
mov    -0x1c(%rbp),%edi
mov    0x2bc8(%rip),%rax
mov    (%rax),%esi
mov    0x2b87(%rip),%rax
mov    (%rax),%edx
lea    -0x94(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     148e <TCPCreate+0x2ce>
cmpq   $0x0,-0x10(%rbp)
je     1462 <TCPCreate+0x2a2>
mov    -0x10(%rbp),%rax
mov    %rax,-0xc0(%rbp)
jmp    1475 <TCPCreate+0x2b5>
lea    0xbc5(%rip),%rax
mov    %rax,-0xc0(%rbp)
jmp    1475 <TCPCreate+0x2b5>
mov    -0xc0(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xc0b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x78(%rbp),%rax
mov    (%rax),%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jne    14ca <TCPCreate+0x30a>
mov    -0x1c(%rbp),%edi
mov    $0xf,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jne    14ca <TCPCreate+0x30a>
jmp    1587 <TCPCreate+0x3c7>
jmp    151b <TCPCreate+0x35b>
mov    -0x1c(%rbp),%edi
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x78(%rbp),%rax
mov    (%rax),%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jne    14f4 <TCPCreate+0x334>
jmp    1587 <TCPCreate+0x3c7>
mov    -0x1c(%rbp),%edi
mov    0x2aca(%rip),%rax
mov    (%rax),%esi
mov    0x2ad1(%rip),%rax
mov    (%rax),%edx
lea    -0x94(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1545 <TCPCreate+0x385>
mov    -0x10(%rbp),%rax
mov    %rax,-0xc8(%rbp)
jmp    1558 <TCPCreate+0x398>
lea    0xae2(%rip),%rax
mov    %rax,-0xc8(%rbp)
jmp    1558 <TCPCreate+0x398>
mov    -0xc8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xb5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x78(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    1323 <TCPCreate+0x163>
mov    -0x80(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
cmpl   $0x0,-0x1c(%rbp)
jl     15a5 <TCPCreate+0x3e5>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15f3 <TCPCreate+0x433>
cmpq   $0x0,-0x10(%rbp)
je     15c0 <TCPCreate+0x400>
mov    -0x10(%rbp),%rax
mov    %rax,-0xd0(%rbp)
jmp    15d3 <TCPCreate+0x413>
lea    0xa67(%rip),%rax
mov    %rax,-0xd0(%rbp)
jmp    15d3 <TCPCreate+0x413>
mov    -0xd0(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xb10(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TCPCreate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x20(%rsp),%rdi
mov    $0x30,%esi
call   1090 <bzero@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
test   %ebp,%ebp
je     125f <TCPCreate+0x9f>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
lea    0xe1c(%rip),%rsi
lea    0x50(%rsp),%r15
mov    %r15,%rdi
mov    %r14d,%edx
call   10a0 <sprintf@plt>
lea    0x20(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     1272 <TCPCreate+0xb2>
test   %rbx,%rbx
lea    0xde4(%rip),%rsi
cmovne %rbx,%rsi
lea    0xde1(%rip),%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
jmp    142c <TCPCreate+0x26c>
test   %rbx,%rbx
je     1416 <TCPCreate+0x256>
cmpb   $0x0,(%rbx)
jne    1210 <TCPCreate+0x50>
jmp    141d <TCPCreate+0x25d>
mov    0x8(%rsp),%rax
test   %rbx,%rbx
lea    0xdad(%rip),%r12
cmovne %rbx,%r12
mov    $0xffffffff,%ebx
lea    0xe35(%rip),%r13
mov    %rax,0x18(%rsp)
jmp    12d3 <TCPCreate+0x113>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    0x8(%rsp),%rax
mov    0x20(%rax),%rax
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     13f9 <TCPCreate+0x239>
mov    0x8(%rax),%rcx
mov    (%rcx),%r15
test   %ebp,%ebp
je     1300 <TCPCreate+0x140>
mov    $0x7f000001,%edi
call   1050 <htonl@plt>
cmp    %rax,%r15
je     12bc <TCPCreate+0xfc>
mov    0x8(%rsp),%rax
jmp    1305 <TCPCreate+0x145>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r15,%r15
je     12bc <TCPCreate+0xfc>
mov    0x18(%rax),%edi
mov    0x10(%rax),%edx
mov    0x14(%rax),%esi
call   10e0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     13a0 <TCPCreate+0x1e0>
movl   $0x1,0x14(%rsp)
test   %ebp,%ebp
je     13b9 <TCPCreate+0x1f9>
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
mov    0x2c73(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     136a <TCPCreate+0x1aa>
lea    0xd37(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %ebx,%edi
call   1080 <bind@plt>
test   %rax,%rax
jne    12a0 <TCPCreate+0xe0>
mov    %ebx,%edi
mov    $0xf,%esi
call   1070 <listen@plt>
test   %rax,%rax
jne    12a0 <TCPCreate+0xe0>
jmp    1447 <TCPCreate+0x287>
nop
lea    0xcbe(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1040 <printf@plt>
jmp    12bc <TCPCreate+0xfc>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %ebx,%edi
call   10b0 <connect@plt>
test   %rax,%rax
je     1447 <TCPCreate+0x287>
mov    0x2bf1(%rip),%rax
mov    (%rax),%esi
mov    0x2bf8(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
jmp    12a0 <TCPCreate+0xe0>
mov    0x18(%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
test   %ebx,%ebx
jns    1436 <TCPCreate+0x276>
lea    0xce9(%rip),%rdi
mov    %r12,%rsi
jmp    1255 <TCPCreate+0x95>
lea    0xc11(%rip),%rbx
lea    0xbdc(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
jmp    1436 <TCPCreate+0x276>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [46 x i8] c"SockAPI_Create\09param error for %s:%d bind:%d\0A\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [47 x i8] c"SockAPI_Create getaddr fail for %s:%d bind:%d\0A\00"
@.str.4 = [47 x i8] c"SockAPI_Create getsock fail for %s:%d bind:%d\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [50 x i8] c"SockAPI_Create reuse port fail for %s:%d bind:%d\0A\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.6 = [49 x i8] c"SockAPI_Create init sock fail for %s:%d bind:%d\0A\00"
@.str.7 = [52 x i8] c"SockAPI_Create fatal create fail for %s:%d bind:%d\0A\00"
define i32 @TCPCreate(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca %struct.addrinfo*
%13 = alloca i32
%14 = alloca %struct.sockaddr_in*
%15 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 -1, i32* %8
%16 = call i32 @bzero(%struct.addrinfo* %10, i32 48)
%17 = load i32, i32* @PF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %17, i32* %18
%19 = load i32, i32* @SOCK_STREAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %19, i32* %20
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = load i32, i32* @AI_PASSIVE
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 6
store i32 %24, i32* %25
br label %46
26: ; preds = %3
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %45, label %34
34: ; preds = %29, %26
%35 = load i8*, i8** %5
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load i8*, i8** %5
br label %40
39: ; preds = %34
br label %40
40: ; preds = %39, %37
%41 = phi i8* [ %38, %37 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %39 ]
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %41, i32 %42, i32 %43)
store i32 -1, i32* %4
br label %206
45: ; preds = %29
br label %46
46: ; preds = %45, %23
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* %6
%49 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i8*, i8** %5
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%52 = call i32 @getaddrinfo(i8* %50, i8* %51, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %52, i32* %13
%53 = load i32, i32* %13
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %46
%56 = load i8*, i8** %5
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = load i8*, i8** %5
br label %61
60: ; preds = %55
br label %61
61: ; preds = %60, %58
%62 = phi i8* [ %59, %58 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %60 ]
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %62, i32 %63, i32 %64)
store i32 -1, i32* %4
br label %206
66: ; preds = %46
%67 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %67, %struct.addrinfo** %12
br label %68
68: ; preds = %183, %66
%69 = load %struct.addrinfo*, %struct.addrinfo** %11
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load i64, i64* %70
%72 = inttoptr i64 %71 to %struct.sockaddr_in*
store %struct.sockaddr_in* %72, %struct.sockaddr_in** %14
%73 = load i32, i32* %7
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %84
75: ; preds = %68
%76 = load %struct.sockaddr_in*, %struct.sockaddr_in** %14
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %76, i32 0, i32 0
%78 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %77, i32 0, i32 0
%79 = load i64, i64* %78
%80 = call i64 @htonl(i32 2130706433)
%81 = icmp eq i64 %79, %80
br i1 %81, label %82, label %83
82: ; preds = %75
br label %183
83: ; preds = %75
br label %92
84: ; preds = %68
%85 = load %struct.sockaddr_in*, %struct.sockaddr_in** %14
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %85, i32 0, i32 0
%87 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %86, i32 0, i32 0
%88 = load i64, i64* %87
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %84
br label %183
91: ; preds = %84
br label %92
92: ; preds = %91, %83
%93 = load %struct.addrinfo*, %struct.addrinfo** %11
%94 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %93, i32 0, i32 4
%95 = load i32, i32* %94
%96 = load %struct.addrinfo*, %struct.addrinfo** %11
%97 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %96, i32 0, i32 3
%98 = load i32, i32* %97
%99 = load %struct.addrinfo*, %struct.addrinfo** %11
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 2
%101 = load i32, i32* %100
%102 = call i32 @socket(i32 %95, i32 %98, i32 %101)
store i32 %102, i32* %8
%103 = load i32, i32* %8
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %116
105: ; preds = %92
%106 = load i8*, i8** %5
%107 = icmp ne i8* %106, null
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = load i8*, i8** %5
br label %111
110: ; preds = %105
br label %111
111: ; preds = %110, %108
%112 = phi i8* [ %109, %108 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %110 ]
%113 = load i32, i32* %6
%114 = load i32, i32* %7
%115 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %112, i32 %113, i32 %114)
br label %183
116: ; preds = %92
store i32 1, i32* %15
%117 = load i32, i32* %7
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %153
119: ; preds = %116
%120 = load i32, i32* %8
%121 = load i32, i32* @SOL_SOCKET
%122 = load i32, i32* @SO_REUSEADDR
%123 = bitcast i32* %15 to i8*
%124 = call i64 @setsockopt(i32 %120, i32 %121, i32 %122, i8* %123, i32 4)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %137
126: ; preds = %119
%127 = load i8*, i8** %5
%128 = icmp ne i8* %127, null
br i1 %128, label %129, label %131
129: ; preds = %126
%130 = load i8*, i8** %5
br label %132
131: ; preds = %126
br label %132
132: ; preds = %131, %129
%133 = phi i8* [ %130, %129 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %131 ]
%134 = load i32, i32* %6
%135 = load i32, i32* %7
%136 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %133, i32 %134, i32 %135)
br label %137
137: ; preds = %132, %119
%138 = load i32, i32* %8
%139 = load %struct.addrinfo*, %struct.addrinfo** %11
%140 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %139, i32 0, i32 1
%141 = load i64, i64* %140
%142 = load %struct.addrinfo*, %struct.addrinfo** %11
%143 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %142, i32 0, i32 0
%144 = load i32, i32* %143
%145 = call i64 @bind(i32 %138, i64 %141, i32 %144)
%146 = icmp eq i64 %145, 0
br i1 %146, label %147, label %152
147: ; preds = %137
%148 = load i32, i32* %8
%149 = call i64 @listen(i32 %148, i32 15)
%150 = icmp eq i64 %149, 0
br i1 %150, label %151, label %152
151: ; preds = %147
br label %188
152: ; preds = %147, %137
br label %170
153: ; preds = %116
%154 = load i32, i32* %8
%155 = load %struct.addrinfo*, %struct.addrinfo** %11
%156 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %155, i32 0, i32 1
%157 = load i64, i64* %156
%158 = load %struct.addrinfo*, %struct.addrinfo** %11
%159 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %158, i32 0, i32 0
%160 = load i32, i32* %159
%161 = call i64 @connect(i32 %154, i64 %157, i32 %160)
%162 = icmp eq i64 %161, 0
br i1 %162, label %163, label %164
163: ; preds = %153
br label %188
164: ; preds = %153
%165 = load i32, i32* %8
%166 = load i32, i32* @IPPROTO_TCP
%167 = load i32, i32* @TCP_NODELAY
%168 = bitcast i32* %15 to i8*
%169 = call i64 @setsockopt(i32 %165, i32 %166, i32 %167, i8* %168, i32 4)
br label %170
170: ; preds = %164, %152
%171 = load i32, i32* %8
%172 = call i32 @close(i32 %171)
store i32 -1, i32* %8
%173 = load i8*, i8** %5
%174 = icmp ne i8* %173, null
br i1 %174, label %175, label %177
175: ; preds = %170
%176 = load i8*, i8** %5
br label %178
177: ; preds = %170
br label %178
178: ; preds = %177, %175
%179 = phi i8* [ %176, %175 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %177 ]
%180 = load i32, i32* %6
%181 = load i32, i32* %7
%182 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %179, i32 %180, i32 %181)
br label %183
183: ; preds = %178, %111, %90, %82
%184 = load %struct.addrinfo*, %struct.addrinfo** %11
%185 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %184, i32 0, i32 5
%186 = load %struct.addrinfo*, %struct.addrinfo** %185
store %struct.addrinfo* %186, %struct.addrinfo** %11
%187 = icmp ne %struct.addrinfo* %186, null
br i1 %187, label %68, label %188
188: ; preds = %183, %163, %151
%189 = load %struct.addrinfo*, %struct.addrinfo** %12
%190 = call i32 @freeaddrinfo(%struct.addrinfo* %189)
%191 = load i32, i32* %8
%192 = icmp sge i32 %191, 0
br i1 %192, label %193, label %195
193: ; preds = %188
%194 = load i32, i32* %8
store i32 %194, i32* %4
br label %206
195: ; preds = %188
%196 = load i8*, i8** %5
%197 = icmp ne i8* %196, null
br i1 %197, label %198, label %200
198: ; preds = %195
%199 = load i8*, i8** %5
br label %201
200: ; preds = %195
br label %201
201: ; preds = %200, %198
%202 = phi i8* [ %199, %198 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %200 ]
%203 = load i32, i32* %6
%204 = load i32, i32* %7
%205 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i8* %202, i32 %203, i32 %204)
store i32 -1, i32* %4
br label %206
206: ; preds = %201, %193, %61, %40
%207 = load i32, i32* %4
ret i32 %207
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [46 x i8] c"SockAPI_Create\09param error for %s:%d bind:%d\0A\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [47 x i8] c"SockAPI_Create getaddr fail for %s:%d bind:%d\0A\00"
@.str.4 = [47 x i8] c"SockAPI_Create getsock fail for %s:%d bind:%d\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [50 x i8] c"SockAPI_Create reuse port fail for %s:%d bind:%d\0A\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.6 = [49 x i8] c"SockAPI_Create init sock fail for %s:%d bind:%d\0A\00"
@.str.7 = [52 x i8] c"SockAPI_Create fatal create fail for %s:%d bind:%d\0A\00"
define i32 @TCPCreate(i8* %0, i32 %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.addrinfo* %5 to i8*
%10 = bitcast %struct.addrinfo** %6 to i8*
%11 = call i32 @bzero(%struct.addrinfo* %5, i32 48)
%12 = load i32, i32* @PF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %14, i32* %15
%16 = icmp eq i32 %2, 0
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i32, i32* @AI_PASSIVE
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 6
store i32 %18, i32* %19
br label %28
20: ; preds = %3
%21 = icmp eq i8* %0, null
br i1 %21, label %25, label %22
22: ; preds = %20
%23 = load i8, i8* %0
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22, %20
%26 = phi i8* [ %0, %22 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %20 ]
%27 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %1, i32 0)
br label %115
28: ; preds = %22, %17
%29 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%30 = call i32 @getaddrinfo(i8* %0, i8* %8, %struct.addrinfo* %5, %struct.addrinfo** %6)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = icmp eq i8* %0, null
%34 = select i1 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0
%35 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32 %1, i32 %2)
br label %115
36: ; preds = %28
%37 = load %struct.addrinfo*, %struct.addrinfo** %6
%38 = bitcast i32* %7 to i8*
%39 = icmp eq i8* %0, null
%40 = select i1 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0
br label %41
41: ; preds = %104, %36
%42 = phi %struct.addrinfo* [ %37, %36 ], [ %108, %104 ]
%43 = phi i32 [ -1, %36 ], [ %105, %104 ]
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i64 0, i32 1
%45 = load i64, i64* %44
%46 = inttoptr i64 %45 to %struct.sockaddr_in*
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %46, i64 0, i32 0, i32 0
%48 = load i64, i64* %47
br i1 %16, label %54, label %49
49: ; preds = %41
%50 = call i64 @htonl(i32 2130706433)
%51 = icmp eq i64 %48, %50
br i1 %51, label %104, label %52
52: ; preds = %49
%53 = load %struct.addrinfo*, %struct.addrinfo** %6
br label %56
54: ; preds = %41
%55 = icmp eq i64 %48, 0
br i1 %55, label %104, label %56
56: ; preds = %52, %54
%57 = phi %struct.addrinfo* [ %53, %52 ], [ %42, %54 ]
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 4
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 3
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 2
%63 = load i32, i32* %62
%64 = call i32 @socket(i32 %59, i32 %61, i32 %63)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %40, i32 %1, i32 %2)
br label %104
68: ; preds = %56
store i32 1, i32* %7
br i1 %16, label %87, label %69
69: ; preds = %68
%70 = load i32, i32* @SOL_SOCKET
%71 = load i32, i32* @SO_REUSEADDR
%72 = call i64 @setsockopt(i32 %64, i32 %70, i32 %71, i8* %38, i32 4)
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %69
%75 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %40, i32 %1, i32 %2)
br label %76
76: ; preds = %74, %69
%77 = load %struct.addrinfo*, %struct.addrinfo** %6
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i64 0, i32 1
%79 = load i64, i64* %78
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i64 0, i32 0
%81 = load i32, i32* %80
%82 = call i64 @bind(i32 %64, i64 %79, i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %101
84: ; preds = %76
%85 = call i64 @listen(i32 %64, i32 15)
%86 = icmp eq i64 %85, 0
br i1 %86, label %99, label %101
87: ; preds = %68
%88 = load %struct.addrinfo*, %struct.addrinfo** %6
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %88, i64 0, i32 1
%90 = load i64, i64* %89
%91 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %88, i64 0, i32 0
%92 = load i32, i32* %91
%93 = call i64 @connect(i32 %64, i64 %90, i32 %92)
%94 = icmp eq i64 %93, 0
br i1 %94, label %99, label %95
95: ; preds = %87
%96 = load i32, i32* @IPPROTO_TCP
%97 = load i32, i32* @TCP_NODELAY
%98 = call i64 @setsockopt(i32 %64, i32 %96, i32 %97, i8* %38, i32 4)
br label %101
99: ; preds = %87, %84
%100 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
br label %115
101: ; preds = %95, %84, %76
%102 = call i32 @close(i32 %64)
%103 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %40, i32 %1, i32 %2)
br label %104
104: ; preds = %54, %49, %66, %101
%105 = phi i32 [ -1, %101 ], [ %43, %54 ], [ %43, %49 ], [ %64, %66 ]
%106 = load %struct.addrinfo*, %struct.addrinfo** %6
%107 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %106, i64 0, i32 5
%108 = load %struct.addrinfo*, %struct.addrinfo** %107
store %struct.addrinfo* %108, %struct.addrinfo** %6
%109 = icmp eq %struct.addrinfo* %108, null
br i1 %109, label %110, label %41
110: ; preds = %104
%111 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
%112 = icmp sgt i32 %105, -1
br i1 %112, label %115, label %113
113: ; preds = %110
%114 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i8* %40, i32 %1, i32 %2)
br label %115
115: ; preds = %99, %32, %113, %110, %25
%116 = phi i32 [ -1, %25 ], [ -1, %32 ], [ -1, %113 ], [ %105, %110 ], [ %64, %99 ]
ret i32 %116
}