#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;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int fake_connect();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ ignoreSigpipe();
int /*<<< orphan*/ isalnum(char);
scalar_t__ isprint(char);
char *malloc(unsigned int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
unsigned _sys_connect(char *address, unsigned size) {
  ignoreSigpipe();
  int i;
  char *addr = malloc(size + 1), *host, *port;
  struct addrinfo hints, *res;
  int sockfd;
  memcpy(addr, address, size);
  if (size == 0) {
    fprintf(stderr, "Empty connect() string\n");
    free(addr);
    return fake_connect();
  }
  i = size - 1;
  while (1) {
    if (isprint(addr[i]) && addr[i] != '/') {
      addr[i + 1] = 0;
      break;
    }
    if (i <= 0) {
      fprintf(stderr, "Bad connect() string [1]\n");
      free(addr);
      return fake_connect();
    }
    --i;
  }
  while (1) {
    if (addr[i] == ':') {
      addr[i] = 0;
      port = addr + (i + 1);
      --i;
      break;
    }
    if (i <= 0) {
      fprintf(stderr, "Bad connect() string [2]\n");
      free(addr);
      return fake_connect();
    }
    --i;
  }
  if (i < 0) {
    fprintf(stderr, "Bad connect() string [3]\n");
    free(addr);
    return fake_connect();
  }
  while (1) {
    if (!isalnum(addr[i]) && addr[i] != '.' && addr[i] != '-' &&
        addr[i] != '_') {
      host = addr + (i + 1);
      break;
    }
    if (i <= 0) {
      host = addr;
      break;
    }
    --i;
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  i = getaddrinfo(host, port, &hints, &res);
  if (i) {
    fprintf(stderr, "getaddrinfo(%s:%s): %s\n", host, port, gai_strerror(i));
    free(addr);
    return fake_connect();
  }
  sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (sockfd == -1) {
    perror("socket");
    free(addr);
    return fake_connect();
  }
  i = connect(sockfd, res->ai_addr, res->ai_addrlen);
  if (i && errno != EINPROGRESS) {
    perror("connect");
    close(sockfd);
    free(addr);
    return fake_connect();
  }
  free(addr);
  return sockfd;
}


x86 assembly (clang, -O0):
<_sys_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   10d0 <ignoreSigpipe@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10a0 <memcpy@plt>
cmpl   $0x0,-0x14(%rbp)
jne    125e <_sys_connect+0x6e>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10c0 <isprint@plt>
cmp    $0x0,%rax
je     12ad <_sys_connect+0xbd>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     12ad <_sys_connect+0xbd>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12f4 <_sys_connect+0x104>
cmpl   $0x0,-0x18(%rbp)
jg     12e6 <_sys_connect+0xf6>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1267 <_sys_connect+0x77>
jmp    12f9 <_sys_connect+0x109>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    133c <_sys_connect+0x14c>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1383 <_sys_connect+0x193>
cmpl   $0x0,-0x18(%rbp)
jg     1375 <_sys_connect+0x185>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    12f9 <_sys_connect+0x109>
cmpl   $0x0,-0x18(%rbp)
jge    13bc <_sys_connect+0x1cc>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
lea    0xcaf(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
jmp    13c1 <_sys_connect+0x1d1>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    1433 <_sys_connect+0x243>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1433 <_sys_connect+0x243>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     1433 <_sys_connect+0x243>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     1433 <_sys_connect+0x243>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1458 <_sys_connect+0x268>
cmpl   $0x0,-0x18(%rbp)
jg     144a <_sys_connect+0x25a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1458 <_sys_connect+0x268>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    13c1 <_sys_connect+0x1d1>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2b71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2b4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1100 <getaddrinfo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     14fa <_sys_connect+0x30a>
mov    0x2b27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    -0x60(%rbp),%rcx
mov    %rax,%r8
lea    0xb8b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1545 <_sys_connect+0x355>
lea    0xb56(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10f0 <connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     15ad <_sys_connect+0x3bd>
mov    0x2a52(%rip),%rax
mov    (%rax),%rax
mov    0x2a70(%rip),%rcx
cmp    (%rcx),%rax
je     15ad <_sys_connect+0x3bd>
lea    0xafd(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <fake_connect@plt>
mov    %eax,-0x4(%rbp)
jmp    15bc <_sys_connect+0x3cc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sys_connect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   10d0 <ignoreSigpipe@plt>
lea    0x1(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   10a0 <memcpy@plt>
test   %ebp,%ebp
je     1312 <_sys_connect+0x122>
lea    -0x1(%rbp),%eax
movslq %eax,%rbx
jmp    123f <_sys_connect+0x4f>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %ebp,%ebp
jle    1300 <_sys_connect+0x110>
movsbl (%r15,%rbx,1),%edi
call   10c0 <isprint@plt>
test   %rax,%rax
je     1230 <_sys_connect+0x40>
movzbl (%r15,%rbx,1),%eax
cmp    $0x2f,%al
je     1230 <_sys_connect+0x40>
movslq %ebp,%rcx
movb   $0x0,(%r15,%rcx,1)
cmp    $0x3a,%al
jne    1270 <_sys_connect+0x80>
add    $0xffffffff,%ebp
jmp    128b <_sys_connect+0x9b>
nopl   0x0(%rax,%rax,1)
test   %rbx,%rbx
jle    13db <_sys_connect+0x1eb>
lea    -0x1(%rbx),%rbp
cmpb   $0x3a,-0x1(%r15,%rbx,1)
mov    %rbp,%rbx
jne    1270 <_sys_connect+0x80>
mov    %rbp,%rbx
movb   $0x0,(%r15,%rbx,1)
test   %ebp,%ebp
jle    13c6 <_sys_connect+0x1d6>
movslq %ebp,%rax
lea    (%rax,%r15,1),%r14
add    $0x1,%r14
mov    %ebp,%ebx
movabs $0x4000000000003,%rbp
jmp    12d2 <_sys_connect+0xe2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
add    $0xffffffffffffffff,%rax
test   $0xfffffffe,%ebx
mov    %rax,%rbx
je     1344 <_sys_connect+0x154>
movsbl -0x1(%r15,%rbx,1),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
jne    12c0 <_sys_connect+0xd0>
movzbl -0x1(%r15,%rbx,1),%eax
add    $0xd3,%al
cmp    $0x32,%al
ja     12f6 <_sys_connect+0x106>
movzbl %al,%eax
bt     %rax,%rbp
jb     12c0 <_sys_connect+0xd0>
mov    %ebx,%eax
mov    %r15,%rbx
add    %rax,%rbx
jmp    1347 <_sys_connect+0x157>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
jmp    1322 <_sys_connect+0x132>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fake_connect@plt>
mov    %r15,%rbx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2c59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1100 <getaddrinfo@plt>
test   %eax,%eax
je     13f0 <_sys_connect+0x200>
mov    0x2c3f(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xcc5(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <fake_connect@plt>
mov    %eax,%ebx
jmp    143b <_sys_connect+0x24b>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
lea    0xc76(%rip),%rsi
jmp    1322 <_sys_connect+0x132>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
lea    0xc47(%rip),%rsi
jmp    1322 <_sys_connect+0x132>
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     144a <_sys_connect+0x25a>
mov    %eax,%ebx
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebx,%edi
call   10f0 <connect@plt>
test   %eax,%eax
je     1433 <_sys_connect+0x243>
mov    0x2b9c(%rip),%rax
mov    (%rax),%rax
mov    0x2bba(%rip),%rcx
cmp    (%rcx),%rax
jne    145b <_sys_connect+0x26b>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc2d(%rip),%rdi
call   10e0 <perror@plt>
jmp    13b3 <_sys_connect+0x1c3>
lea    0xc23(%rip),%rdi
call   10e0 <perror@plt>
mov    %ebx,%edi
call   1080 <close@plt>
jmp    13b3 <_sys_connect+0x1c3>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Empty connect() string\0A\00"
@.str.1 = [26 x i8] c"Bad connect() string [1]\0A\00"
@.str.2 = [26 x i8] c"Bad connect() string [2]\0A\00"
@.str.3 = [26 x i8] c"Bad connect() string [3]\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [24 x i8] c"getaddrinfo(%s:%s): %s\0A\00"
@.str.5 = [7 x i8] c"socket\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.6 = [8 x i8] c"connect\00"
define i32 @_sys_connect(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = call i32 (...) @ignoreSigpipe()
%14 = load i32, i32* %5
%15 = add i32 %14, 1
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = call i32 @memcpy(i8* %17, i8* %18, i32 %19)
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
%28 = call i32 (...) @fake_connect()
store i32 %28, i32* %3
br label %220
29: ; preds = %2
%30 = load i32, i32* %5
%31 = sub i32 %30, 1
store i32 %31, i32* %6
br label %32
32: ; preds = %29, %63
%33 = load i8*, i8** %7
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i64 @isprint(i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %54
40: ; preds = %32
%41 = load i8*, i8** %7
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 47
br i1 %47, label %48, label %54
48: ; preds = %40
%49 = load i8*, i8** %7
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
store i8 0, i8* %53
br label %66
54: ; preds = %40, %32
%55 = load i32, i32* %6
%56 = icmp sle i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%60 = load i8*, i8** %7
%61 = call i32 @free(i8* %60)
%62 = call i32 (...) @fake_connect()
store i32 %62, i32* %3
br label %220
63: ; preds = %54
%64 = load i32, i32* %6
%65 = add nsw i32 %64, -1
store i32 %65, i32* %6
br label %32
66: ; preds = %48
br label %67
67: ; preds = %66, %96
%68 = load i8*, i8** %7
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 58
br i1 %74, label %75, label %87
75: ; preds = %67
%76 = load i8*, i8** %7
%77 = load i32, i32* %6
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
store i8 0, i8* %79
%80 = load i8*, i8** %7
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %80, i64 %83
store i8* %84, i8** %9
%85 = load i32, i32* %6
%86 = add nsw i32 %85, -1
store i32 %86, i32* %6
br label %99
87: ; preds = %67
%88 = load i32, i32* %6
%89 = icmp sle i32 %88, 0
br i1 %89, label %90, label %96
90: ; preds = %87
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%93 = load i8*, i8** %7
%94 = call i32 @free(i8* %93)
%95 = call i32 (...) @fake_connect()
store i32 %95, i32* %3
br label %220
96: ; preds = %87
%97 = load i32, i32* %6
%98 = add nsw i32 %97, -1
store i32 %98, i32* %6
br label %67
99: ; preds = %75
%100 = load i32, i32* %6
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %108
102: ; preds = %99
%103 = load i32, i32* @stderr
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%105 = load i8*, i8** %7
%106 = call i32 @free(i8* %105)
%107 = call i32 (...) @fake_connect()
store i32 %107, i32* %3
br label %220
108: ; preds = %99
br label %109
109: ; preds = %108, %152
%110 = load i8*, i8** %7
%111 = load i32, i32* %6
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %110, i64 %112
%114 = load i8, i8* %113
%115 = call i32 @isalnum(i8 signext %114)
%116 = icmp ne i32 %115, 0
br i1 %116, label %147, label %117
117: ; preds = %109
%118 = load i8*, i8** %7
%119 = load i32, i32* %6
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8, i8* %118, i64 %120
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp ne i32 %123, 46
br i1 %124, label %125, label %147
125: ; preds = %117
%126 = load i8*, i8** %7
%127 = load i32, i32* %6
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8, i8* %126, i64 %128
%130 = load i8, i8* %129
%131 = sext i8 %130 to i32
%132 = icmp ne i32 %131, 45
br i1 %132, label %133, label %147
133: ; preds = %125
%134 = load i8*, i8** %7
%135 = load i32, i32* %6
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
%138 = load i8, i8* %137
%139 = sext i8 %138 to i32
%140 = icmp ne i32 %139, 95
br i1 %140, label %141, label %147
141: ; preds = %133
%142 = load i8*, i8** %7
%143 = load i32, i32* %6
%144 = add nsw i32 %143, 1
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds i8, i8* %142, i64 %145
store i8* %146, i8** %8
br label %155
147: ; preds = %133, %125, %117, %109
%148 = load i32, i32* %6
%149 = icmp sle i32 %148, 0
br i1 %149, label %150, label %152
150: ; preds = %147
%151 = load i8*, i8** %7
store i8* %151, i8** %8
br label %155
152: ; preds = %147
%153 = load i32, i32* %6
%154 = add nsw i32 %153, -1
store i32 %154, i32* %6
br label %109
155: ; preds = %150, %141
%156 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 20)
%157 = load i32, i32* @AF_UNSPEC
%158 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %157, i32* %158
%159 = load i32, i32* @SOCK_STREAM
%160 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %159, i32* %160
%161 = load i8*, i8** %8
%162 = load i8*, i8** %9
%163 = call i32 @getaddrinfo(i8* %161, i8* %162, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %163, i32* %6
%164 = load i32, i32* %6
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %176
166: ; preds = %155
%167 = load i32, i32* @stderr
%168 = load i8*, i8** %8
%169 = load i8*, i8** %9
%170 = load i32, i32* %6
%171 = call i8* @gai_strerror(i32 %170)
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %168, i8* %169, i8* %171)
%173 = load i8*, i8** %7
%174 = call i32 @free(i8* %173)
%175 = call i32 (...) @fake_connect()
store i32 %175, i32* %3
br label %220
176: ; preds = %155
%177 = load %struct.addrinfo*, %struct.addrinfo** %11
%178 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %177, i32 0, i32 4
%179 = load i32, i32* %178
%180 = load %struct.addrinfo*, %struct.addrinfo** %11
%181 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %180, i32 0, i32 3
%182 = load i32, i32* %181
%183 = load %struct.addrinfo*, %struct.addrinfo** %11
%184 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %183, i32 0, i32 2
%185 = load i32, i32* %184
%186 = call i32 @socket(i32 %179, i32 %182, i32 %185)
store i32 %186, i32* %12
%187 = load i32, i32* %12
%188 = icmp eq i32 %187, -1
br i1 %188, label %189, label %194
189: ; preds = %176
%190 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%191 = load i8*, i8** %7
%192 = call i32 @free(i8* %191)
%193 = call i32 (...) @fake_connect()
store i32 %193, i32* %3
br label %220
194: ; preds = %176
%195 = load i32, i32* %12
%196 = load %struct.addrinfo*, %struct.addrinfo** %11
%197 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %196, i32 0, i32 1
%198 = load i32, i32* %197
%199 = load %struct.addrinfo*, %struct.addrinfo** %11
%200 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %199, i32 0, i32 0
%201 = load i32, i32* %200
%202 = call i32 @connect(i32 %195, i32 %198, i32 %201)
store i32 %202, i32* %6
%203 = load i32, i32* %6
%204 = icmp ne i32 %203, 0
br i1 %204, label %205, label %216
205: ; preds = %194
%206 = load i64, i64* @errno
%207 = load i64, i64* @EINPROGRESS
%208 = icmp ne i64 %206, %207
br i1 %208, label %209, label %216
209: ; preds = %205
%210 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%211 = load i32, i32* %12
%212 = call i32 @close(i32 %211)
%213 = load i8*, i8** %7
%214 = call i32 @free(i8* %213)
%215 = call i32 (...) @fake_connect()
store i32 %215, i32* %3
br label %220
216: ; preds = %205, %194
%217 = load i8*, i8** %7
%218 = call i32 @free(i8* %217)
%219 = load i32, i32* %12
store i32 %219, i32* %3
br label %220
220: ; preds = %216, %209, %189, %166, %102, %90, %57, %23
%221 = load i32, i32* %3
ret i32 %221
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Empty connect() string\0A\00"
@.str.1 = [26 x i8] c"Bad connect() string [1]\0A\00"
@.str.2 = [26 x i8] c"Bad connect() string [2]\0A\00"
@.str.3 = [26 x i8] c"Bad connect() string [3]\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [24 x i8] c"getaddrinfo(%s:%s): %s\0A\00"
@.str.5 = [7 x i8] c"socket\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.6 = [8 x i8] c"connect\00"
define i32 @_sys_connect(i8* %0, i32 %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = tail call i32 (...) @ignoreSigpipe()
%6 = add i32 %1, 1
%7 = tail call i8* @malloc(i32 %6)
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = tail call i32 @memcpy(i8* %7, i8* %0, i32 %1)
%11 = icmp eq i32 %1, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @free(i8* %7)
%16 = tail call i32 (...) @fake_connect()
br label %132
17: ; preds = %2, %32
%18 = phi i32 [ %19, %32 ], [ %1, %2 ]
%19 = add i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %7, i64 %20
%22 = load i8, i8* %21
%23 = tail call i64 @isprint(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %17
%26 = load i8, i8* %21
%27 = icmp eq i8 %26, 47
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = sext i32 %18 to i64
%30 = getelementptr inbounds i8, i8* %7, i64 %29
store i8 0, i8* %30
%31 = icmp eq i8 %26, 58
br i1 %31, label %41, label %51
32: ; preds = %25, %17
%33 = icmp slt i32 %19, 1
br i1 %33, label %34, label %17
34: ; preds = %32
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%37 = tail call i32 @free(i8* %7)
%38 = tail call i32 (...) @fake_connect()
br label %132
39: ; preds = %59
%40 = trunc i64 %60 to i32
br label %41
41: ; preds = %39, %28
%42 = phi i64 [ %20, %28 ], [ %60, %39 ]
%43 = phi i32 [ %19, %28 ], [ %40, %39 ]
%44 = getelementptr inbounds i8, i8* %7, i64 %42
store i8 0, i8* %44
%45 = add nuw nsw i32 %43, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %7, i64 %46
%48 = icmp slt i32 %43, 1
br i1 %48, label %64, label %49
49: ; preds = %41
%50 = zext i32 %43 to i64
br label %69
51: ; preds = %28, %59
%52 = phi i64 [ %60, %59 ], [ %20, %28 ]
%53 = icmp slt i64 %52, 1
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%57 = tail call i32 @free(i8* %7)
%58 = tail call i32 (...) @fake_connect()
br label %132
59: ; preds = %51
%60 = add nsw i64 %52, -1
%61 = getelementptr inbounds i8, i8* %7, i64 %60
%62 = load i8, i8* %61
%63 = icmp eq i8 %62, 58
br i1 %63, label %39, label %51
64: ; preds = %41
%65 = load i32, i32* @stderr
%66 = tail call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%67 = tail call i32 @free(i8* %7)
%68 = tail call i32 (...) @fake_connect()
br label %132
69: ; preds = %49, %81
%70 = phi i64 [ %50, %49 ], [ %71, %81 ]
%71 = add nsw i64 %70, -1
%72 = getelementptr inbounds i8, i8* %7, i64 %71
%73 = load i8, i8* %72
%74 = tail call i32 @isalnum(i8 signext %73)
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %69
%77 = load i8, i8* %72
switch i8 %77, label %78 [
i8 46, label %81
i8 45, label %81
i8 95, label %81
]
78: ; preds = %76
%79 = and i64 %70, 4294967295
%80 = getelementptr inbounds i8, i8* %7, i64 %79
br label %84
81: ; preds = %76, %76, %76, %69
%82 = and i64 %70, 4294967294
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %69
84: ; preds = %81, %78
%85 = phi i8* [ %80, %78 ], [ %7, %81 ]
%86 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%87 = load i32, i32* @AF_UNSPEC
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %87, i32* %88
%89 = load i32, i32* @SOCK_STREAM
%90 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %89, i32* %90
%91 = call i32 @getaddrinfo(i8* %85, i8* %47, %struct.addrinfo* %3, %struct.addrinfo** %4)
%92 = icmp eq i32 %91, 0
br i1 %92, label %99, label %93
93: ; preds = %84
%94 = load i32, i32* @stderr
%95 = call i8* @gai_strerror(i32 %91)
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %85, i8* %47, i8* %95)
%97 = call i32 @free(i8* %7)
%98 = call i32 (...) @fake_connect()
br label %132
99: ; preds = %84
%100 = load %struct.addrinfo*, %struct.addrinfo** %4
%101 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %100, i64 0, i32 4
%102 = load i32, i32* %101
%103 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %100, i64 0, i32 3
%104 = load i32, i32* %103
%105 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %100, i64 0, i32 2
%106 = load i32, i32* %105
%107 = call i32 @socket(i32 %102, i32 %104, i32 %106)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %113
109: ; preds = %99
%110 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%111 = call i32 @free(i8* %7)
%112 = call i32 (...) @fake_connect()
br label %132
113: ; preds = %99
%114 = load %struct.addrinfo*, %struct.addrinfo** %4
%115 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %114, i64 0, i32 1
%116 = load i32, i32* %115
%117 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %114, i64 0, i32 0
%118 = load i32, i32* %117
%119 = call i32 @connect(i32 %107, i32 %116, i32 %118)
%120 = icmp eq i32 %119, 0
br i1 %120, label %130, label %121
121: ; preds = %113
%122 = load i64, i64* @errno
%123 = load i64, i64* @EINPROGRESS
%124 = icmp eq i64 %122, %123
br i1 %124, label %130, label %125
125: ; preds = %121
%126 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%127 = call i32 @close(i32 %107)
%128 = call i32 @free(i8* %7)
%129 = call i32 (...) @fake_connect()
br label %132
130: ; preds = %121, %113
%131 = call i32 @free(i8* %7)
br label %132
132: ; preds = %130, %125, %109, %93, %64, %54, %34, %12
%133 = phi i32 [ %16, %12 ], [ %68, %64 ], [ %98, %93 ], [ %112, %109 ], [ %129, %125 ], [ %107, %130 ], [ %58, %54 ], [ %38, %34 ]
ret i32 %133
}