#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 timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int SOCK_NONBLOCK;
int SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char *argv[]) {
  int fd, rtn, socerr, socerrlen;
  struct sockaddr_in sa;
  fd_set wset;
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 1;
  socerrlen = sizeof(int);
  sa.sin_port = htons(80);
  sa.sin_family = AF_INET;
  if (inet_aton("157.166.226.26", &(sa.sin_addr)) == 0) {
    fprintf(stderr, "cannot connect to host\n");
    return -1;
  }
  fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
  FD_ZERO(&wset);
  FD_SET(fd, &wset);
  rtn = connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));
  if (rtn == 0) {
    fprintf(stderr, "connect returned imidiately\n");
  } else if (rtn < 0) {
    fprintf(stderr, "there was a connect error: %s\n", strerror(errno));
    if (errno == EINPROGRESS) {
      for (;;) {
        rtn = select(fd + 1, NULL, &wset, NULL, &tv);
        if (rtn == 0) {
          fprintf(stderr, ".");
          FD_ZERO(&wset);
          FD_SET(fd, &wset);
        } else if (rtn < 0) {
          fprintf(stderr, "select error: %s\n", strerror(errno));
          return 0;
        } else if (rtn > 0) {
          fprintf(stderr, "socket in write set is writable\n");
          rtn = getsockopt(fd, SOL_SOCKET, SO_ERROR, &socerr, &socerrlen);
          fprintf(stderr, "getsockopt rtn: %d\n", rtn);
          if (socerr > 0) {
            fprintf(stderr, "error connecting: %s\n", strerror(socerr));
            return -1;
          } else {
            fprintf(stderr, "CONNECTED %s\n", strerror(socerr));
            break;
          }
        }
      }
    }
  }
  close(fd);
  fprintf(stderr, "Exiting program\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x1,-0x48(%rbp)
movl   $0x4,-0x20(%rbp)
mov    $0x50,%edi
call   1030 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1090 <inet_aton@plt>
cmp    $0x0,%rax
jne    1232 <main+0x82>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ae <main+0x2fe>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
mov    0x2d7d(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x34(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12a6 <main+0xf6>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1488 <main+0x2d8>
cmpl   $0x0,-0x18(%rbp)
jge    1483 <main+0x2d3>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%rax
mov    0x2ce6(%rip),%rcx
cmp    (%rcx),%rax
jne    147e <main+0x2ce>
jmp    1300 <main+0x150>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x34(%rbp),%rdx
lea    -0x48(%rbp),%r8
mov    %rcx,%rsi
call   1080 <select@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1358 <main+0x1a8>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x34(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   10c0 <FD_SET@plt>
jmp    1474 <main+0x2c4>
cmpl   $0x0,-0x18(%rbp)
jge    139f <main+0x1ef>
mov    0x2c57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c3b(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edi
call   10b0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xcd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14ae <main+0x2fe>
cmpl   $0x0,-0x18(%rbp)
jle    146a <main+0x2ba>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
lea    0xcbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
mov    0x2bd5(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <getsockopt@plt>
mov    %eax,-0x18(%rbp)
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xca0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    143d <main+0x28d>
mov    0x2bb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x1c(%rbp),%edi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xc82(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ae <main+0x2fe>
mov    0x2b7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x1c(%rbp),%edi
call   10b0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xc64(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1479 <main+0x2c9>
jmp    146f <main+0x2bf>
jmp    1474 <main+0x2c4>
jmp    1300 <main+0x150>
jmp    147e <main+0x2ce>
jmp    1483 <main+0x2d3>
jmp    1488 <main+0x2d8>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
lea    0xc30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,0x30(%rsp)
movl   $0x1,0x28(%rsp)
movl   $0x4,0x10(%rsp)
mov    $0x50,%edi
call   1030 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2df4(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
lea    0xe07(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1090 <inet_aton@plt>
test   %rax,%rax
je     13a2 <main+0x1f2>
mov    (%rbx),%edi
mov    0x2da3(%rip),%rax
mov    0x2dac(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %eax,%eax
je     13c0 <main+0x210>
jns    13d7 <main+0x227>
mov    0x2d5a(%rip),%r13
mov    0x0(%r13),%ebp
mov    0x2d3f(%rip),%r14
mov    (%r14),%edi
call   10b0 <strerror@plt>
lea    0xdc4(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%rax
mov    0x2d42(%rip),%rcx
cmp    (%rcx),%rax
jne    13d7 <main+0x227>
mov    %ebx,%r15d
add    $0x1,%r15d
lea    0xc(%rsp),%rdx
lea    0x28(%rsp),%r8
mov    %r15d,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1080 <select@plt>
test   %eax,%eax
jne    131d <main+0x16d>
lea    0xd9c(%rip),%r14
lea    0xc(%rsp),%rbp
lea    0x28(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1070 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
call   1080 <select@plt>
test   %eax,%eax
je     12e0 <main+0x130>
mov    0x2c93(%rip),%r14
mov    0x0(%r13),%ebp
test   %eax,%eax
js     1408 <main+0x258>
lea    0xd47(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%esi
mov    0x2c5f(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
call   1050 <getsockopt@plt>
mov    0x0(%r13),%edi
lea    0xd31(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x14(%rsp),%ebp
mov    0x0(%r13),%r14d
mov    %ebp,%edi
call   10b0 <strerror@plt>
test   %ebp,%ebp
jle    1427 <main+0x277>
lea    0xd1e(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    13f7 <main+0x247>
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
lea    0xc5d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    13f7 <main+0x247>
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
lea    0xc57(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
lea    0xce2(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%edi
call   10b0 <strerror@plt>
lea    0xc4e(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13f7 <main+0x247>
lea    0xc94(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13d7 <main+0x227>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [15 x i8] c"157.166.226.26\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"cannot connect to host\0A\00"
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str.2 = [29 x i8] c"connect returned imidiately\0A\00"
@.str.3 = [31 x i8] c"there was a connect error: %s\0A\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.4 = [2 x i8] c".\00"
@.str.5 = [18 x i8] c"select error: %s\0A\00"
@.str.6 = [33 x i8] c"socket in write set is writable\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.7 = [20 x i8] c"getsockopt rtn: %d\0A\00"
@.str.8 = [22 x i8] c"error connecting: %s\0A\00"
@.str.9 = [14 x i8] c"CONNECTED %s\0A\00"
@.str.10 = [17 x i8] c"Exiting program\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 1, i32* %14
store i32 4, i32* %9
%15 = call i32 @htons(i32 80)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%20 = call i64 @inet_aton(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %112
25: ; preds = %2
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = load i32, i32* @SOCK_NONBLOCK
%29 = or i32 %27, %28
%30 = call i32 @socket(i32 %26, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = call i32 @FD_ZERO(i32* %11)
%32 = load i32, i32* %6
%33 = call i32 @FD_SET(i32 %32, i32* %11)
%34 = load i32, i32* %6
%35 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%36 = call i32 @connect(i32 %34, %struct.sockaddr* %35, i32 12)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %25
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %107
42: ; preds = %25
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %106
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i64, i64* @errno
%48 = trunc i64 %47 to i32
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%51 = load i64, i64* @errno
%52 = load i64, i64* @EINPROGRESS
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %105
54: ; preds = %45
br label %55
55: ; preds = %103, %54
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
%58 = call i32 @select(i32 %57, i32* null, i32* %11, i32* null, %struct.timeval* %12)
store i32 %58, i32* %7
%59 = load i32, i32* %7
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @FD_ZERO(i32* %11)
%65 = load i32, i32* %6
%66 = call i32 @FD_SET(i32 %65, i32* %11)
br label %103
67: ; preds = %55
%68 = load i32, i32* %7
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %76
70: ; preds = %67
%71 = load i32, i32* @stderr
%72 = load i64, i64* @errno
%73 = trunc i64 %72 to i32
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %74)
store i32 0, i32* %3
br label %112
76: ; preds = %67
%77 = load i32, i32* %7
%78 = icmp sgt i32 %77, 0
br i1 %78, label %79, label %101
79: ; preds = %76
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%82 = load i32, i32* %6
%83 = load i32, i32* @SOL_SOCKET
%84 = load i32, i32* @SO_ERROR
%85 = call i32 @getsockopt(i32 %82, i32 %83, i32 %84, i32* %8, i32* %9)
store i32 %85, i32* %7
%86 = load i32, i32* @stderr
%87 = load i32, i32* %7
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %8
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %79
%92 = load i32, i32* @stderr
%93 = load i32, i32* %8
%94 = call i8* @strerror(i32 %93)
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %94)
store i32 -1, i32* %3
br label %112
96: ; preds = %79
%97 = load i32, i32* @stderr
%98 = load i32, i32* %8
%99 = call i8* @strerror(i32 %98)
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %99)
br label %104
101: ; preds = %76
br label %102
102: ; preds = %101
br label %103
103: ; preds = %102, %61
br label %55
104: ; preds = %96
br label %105
105: ; preds = %104, %45
br label %106
106: ; preds = %105, %42
br label %107
107: ; preds = %106, %39
%108 = load i32, i32* %6
%109 = call i32 @close(i32 %108)
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %3
br label %112
112: ; preds = %107, %91, %70, %22
%113 = load i32, i32* %3
ret i32 %113
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [15 x i8] c"157.166.226.26\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"cannot connect to host\0A\00"
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str.2 = [29 x i8] c"connect returned imidiately\0A\00"
@.str.3 = [31 x i8] c"there was a connect error: %s\0A\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.4 = [2 x i8] c".\00"
@.str.5 = [18 x i8] c"select error: %s\0A\00"
@.str.6 = [33 x i8] c"socket in write set is writable\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.7 = [20 x i8] c"getsockopt rtn: %d\0A\00"
@.str.8 = [22 x i8] c"error connecting: %s\0A\00"
@.str.9 = [14 x i8] c"CONNECTED %s\0A\00"
@.str.10 = [17 x i8] c"Exiting program\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast %struct.timeval* %7 to i8*
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 1, i32* %14
store i32 4, i32* %4
%15 = tail call i32 @htons(i32 80)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%20 = call i64 @inet_aton(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %89
25: ; preds = %2
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = load i32, i32* @SOCK_NONBLOCK
%29 = or i32 %28, %27
%30 = call i32 @socket(i32 %26, i32 %29, i32 0)
%31 = call i32 @FD_ZERO(i32* %6)
%32 = call i32 @FD_SET(i32 %30, i32* %6)
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%34 = call i32 @connect(i32 %30, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %85
39: ; preds = %25
%40 = icmp slt i32 %34, 0
br i1 %40, label %41, label %85
41: ; preds = %39
%42 = load i32, i32* @stderr
%43 = load i64, i64* @errno
%44 = trunc i64 %43 to i32
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i64, i64* @errno
%48 = load i64, i64* @EINPROGRESS
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %85
50: ; preds = %41
%51 = add nsw i32 %30, 1
%52 = call i32 @select(i32 %51, i32* null, i32* %6, i32* null, %struct.timeval* %7)
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %50, %54
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 @FD_ZERO(i32* %6)
%58 = call i32 @FD_SET(i32 %30, i32* %6)
%59 = call i32 @select(i32 %51, i32* null, i32* %6, i32* null, %struct.timeval* %7)
%60 = icmp eq i32 %59, 0
br i1 %60, label %54, label %61
61: ; preds = %54, %50
%62 = phi i32 [ %52, %50 ], [ %59, %54 ]
%63 = icmp slt i32 %62, 0
%64 = load i32, i32* @stderr
br i1 %63, label %65, label %70
65: ; preds = %61
%66 = load i64, i64* @errno
%67 = trunc i64 %66 to i32
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %68)
br label %89
70: ; preds = %61
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%72 = load i32, i32* @SOL_SOCKET
%73 = load i32, i32* @SO_ERROR
%74 = call i32 @getsockopt(i32 %30, i32 %72, i32 %73, i32* %3, i32* %4)
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %74)
%77 = load i32, i32* %3
%78 = icmp sgt i32 %77, 0
%79 = load i32, i32* @stderr
%80 = call i8* @strerror(i32 %77)
br i1 %78, label %81, label %83
81: ; preds = %70
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %80)
br label %89
83: ; preds = %70
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %80)
br label %85
85: ; preds = %39, %83, %41, %36
%86 = call i32 @close(i32 %30)
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %89
89: ; preds = %85, %81, %65, %22
%90 = phi i32 [ -1, %22 ], [ 0, %85 ], [ 0, %65 ], [ -1, %81 ]
ret i32 %90
}