#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int portScan(char *hostname, int start, int end, int timeout) {
  int i = 0;
  int sock = 0;
  fd_set fdset;
  int so_error = 0;
  struct timeval tv;
  struct hostent *host;
  struct sockaddr_in sa;
  strncpy((char *)&sa, "", sizeof sa);
  sa.sin_family = AF_INET;
  if (isdigit(hostname[0])) {
    sa.sin_addr.s_addr = inet_addr(hostname);
  } else if ((host = gethostbyname(hostname)) != 0) {
    strncpy((char *)&sa.sin_addr, (char *)host->h_addr, sizeof sa.sin_addr);
  } else {
    printf("snetool: unknown host %s\n", hostname);
    return EXIT_FAILURE;
  }
  for (i = start; i <= end; i++) {
    sa.sin_port = htons(i);
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0) {
      printf("snetool: cannot create socket\n");
      return EXIT_FAILURE;
    }
    fcntl(sock, F_SETFL, O_NONBLOCK);
    connect(sock, (struct sockaddr *)&sa, sizeof sa);
    FD_ZERO(&fdset);
    FD_SET(sock, &fdset);
    tv.tv_sec = 0;
    tv.tv_usec = timeout * 1000;
    if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1) {
      socklen_t len = sizeof so_error;
      getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
      if (so_error == 0) {
        printf("%d is open\n", i);
      }
    } else {
      printf("%d is closed\n", i);
    }
    close(sock);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<portScan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x58(%rbp),%rdi
lea    0xe3d(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncpy@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1252 <portScan+0x72>
mov    -0x10(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x54(%rbp)
jmp    12af <portScan+0xcf>
mov    -0x10(%rbp),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     1287 <portScan+0xa7>
lea    -0x58(%rbp),%rdi
add    $0x4,%rdi
mov    -0x48(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
jmp    12aa <portScan+0xca>
mov    -0x10(%rbp),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1402 <portScan+0x222>
jmp    12af <portScan+0xcf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     13f6 <portScan+0x216>
mov    -0x20(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1311 <portScan+0x131>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1402 <portScan+0x222>
mov    -0x24(%rbp),%edi
mov    0x2cad(%rip),%rax
mov    (%rax),%esi
mov    0x2cb4(%rip),%rax
mov    (%rax),%edx
call   1050 <fcntl@plt>
mov    -0x24(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
lea    -0x28(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10f0 <FD_SET@plt>
movq   $0x0,-0x38(%rbp)
imul   $0x3e8,-0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%rdx
lea    -0x40(%rbp),%r8
mov    %rcx,%rsi
call   10d0 <select@plt>
cmp    $0x1,%eax
jne    13cf <portScan+0x1ef>
movl   $0x4,-0x5c(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2c51(%rip),%rax
mov    (%rax),%esi
mov    0x2c18(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
lea    -0x5c(%rbp),%r8
call   1090 <getsockopt@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    13ca <portScan+0x1ea>
mov    -0x20(%rbp),%esi
lea    0xc76(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13e0 <portScan+0x200>
mov    -0x20(%rbp),%esi
lea    0xc6c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12b5 <portScan+0xd5>
mov    0x2bab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<portScan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xe1b(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0xc,%edx
call   1030 <strncpy@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     124f <portScan+0x5f>
mov    %rbx,%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
jmp    1272 <portScan+0x82>
mov    %rbx,%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     13b8 <portScan+0x1c8>
lea    0x14(%rsp),%rdi
mov    (%rax),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x2d2f(%rip),%rax
cmp    %r15d,%ebp
jg     13d0 <portScan+0x1e0>
imul   $0x3e8,%r14d,%r14d
add    $0x1,%r15d
lea    0x24(%rsp),%rbx
lea    0x28(%rsp),%r12
jmp    12c4 <portScan+0xd4>
nopl   0x0(%rax)
lea    0xd7f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r13d,%edi
call   1090 <close@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
je     13a1 <portScan+0x1b1>
mov    %ebp,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
mov    0x2ce1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     13aa <portScan+0x1ba>
mov    %eax,%r13d
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
mov    0x2cd5(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
call   1060 <fcntl@plt>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
mov    %rbx,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1100 <FD_SET@plt>
movq   $0x0,0x30(%rsp)
mov    %r14d,0x28(%rsp)
mov    %r13d,%edi
add    $0x1,%edi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
call   10e0 <select@plt>
cmp    $0x1,%eax
jne    12a0 <portScan+0xb0>
movl   $0x4,0x20(%rsp)
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
mov    0x2c42(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
lea    0xc(%rsp),%rcx
lea    0x20(%rsp),%r8
call   10a0 <getsockopt@plt>
cmpl   $0x0,0xc(%rsp)
jne    12b0 <portScan+0xc0>
lea    0xc7e(%rip),%rdi
jmp    12a7 <portScan+0xb7>
mov    0x2c00(%rip),%rax
jmp    13d0 <portScan+0x1e0>
lea    0xc83(%rip),%rdi
call   1050 <puts@plt>
jmp    13c9 <portScan+0x1d9>
lea    0xc41(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2be0(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@AF_INET = global i32 0
@.str.1 = [26 x i8] c"snetool: unknown host %s\0A\00"
@EXIT_FAILURE = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [31 x i8] c"snetool: cannot create socket\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.3 = [12 x i8] c"%d is open\0A\00"
@.str.4 = [14 x i8] c"%d is closed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @portScan(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca %struct.hostent*
%16 = alloca %struct.sockaddr_in
%17 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %13
%18 = bitcast %struct.sockaddr_in* %16 to i8*
%19 = call i32 @strncpy(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %20, i32* %21
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %4
%28 = load i8*, i8** %6
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
br label %49
32: ; preds = %4
%33 = load i8*, i8** %6
%34 = call %struct.hostent* @gethostbyname(i8* %33)
store %struct.hostent* %34, %struct.hostent** %15
%35 = icmp ne %struct.hostent* %34, null
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%38 = bitcast %struct.TYPE_2__* %37 to i8*
%39 = load %struct.hostent*, %struct.hostent** %15
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 0
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to i8*
%43 = call i32 @strncpy(i8* %38, i8* %42, i32 4)
br label %48
44: ; preds = %32
%45 = load i8*, i8** %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %5
br label %108
48: ; preds = %36
br label %49
49: ; preds = %48, %27
%50 = load i32, i32* %7
store i32 %50, i32* %10
br label %51
51: ; preds = %103, %49
%52 = load i32, i32* %10
%53 = load i32, i32* %8
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %106
55: ; preds = %51
%56 = load i32, i32* %10
%57 = call i32 @htons(i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
store i32 %57, i32* %58
%59 = load i32, i32* @AF_INET
%60 = load i32, i32* @SOCK_STREAM
%61 = call i32 @socket(i32 %59, i32 %60, i32 0)
store i32 %61, i32* %11
%62 = load i32, i32* %11
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %55
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %5
br label %108
67: ; preds = %55
%68 = load i32, i32* %11
%69 = load i32, i32* @F_SETFL
%70 = load i32, i32* @O_NONBLOCK
%71 = call i32 @fcntl(i32 %68, i32 %69, i32 %70)
%72 = load i32, i32* %11
%73 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%74 = call i32 @connect(i32 %72, %struct.sockaddr* %73, i32 12)
%75 = call i32 @FD_ZERO(i32* %12)
%76 = load i32, i32* %11
%77 = call i32 @FD_SET(i32 %76, i32* %12)
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
store i64 0, i64* %78
%79 = load i32, i32* %9
%80 = mul nsw i32 %79, 1000
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i32 %80, i32* %81
%82 = load i32, i32* %11
%83 = add nsw i32 %82, 1
%84 = call i32 @select(i32 %83, i32* null, i32* %12, i32* null, %struct.timeval* %14)
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %97
86: ; preds = %67
store i32 4, i32* %17
%87 = load i32, i32* %11
%88 = load i32, i32* @SOL_SOCKET
%89 = load i32, i32* @SO_ERROR
%90 = call i32 @getsockopt(i32 %87, i32 %88, i32 %89, i32* %13, i32* %17)
%91 = load i32, i32* %13
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %86
%94 = load i32, i32* %10
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %94)
br label %96
96: ; preds = %93, %86
br label %100
97: ; preds = %67
%98 = load i32, i32* %10
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %98)
br label %100
100: ; preds = %97, %96
%101 = load i32, i32* %11
%102 = call i32 @close(i32 %101)
br label %103
103: ; preds = %100
%104 = load i32, i32* %10
%105 = add nsw i32 %104, 1
store i32 %105, i32* %10
br label %51
106: ; preds = %51
%107 = load i32, i32* @EXIT_SUCCESS
store i32 %107, i32* %5
br label %108
108: ; preds = %106, %64, %44
%109 = load i32, i32* %5
ret i32 %109
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@AF_INET = global i32 0
@.str.1 = [26 x i8] c"snetool: unknown host %s\0A\00"
@EXIT_FAILURE = global i32 0
@SOCK_STREAM = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.3 = [12 x i8] c"%d is open\0A\00"
@.str.4 = [14 x i8] c"%d is closed\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [30 x i8] c"snetool: cannot create socket\00"
define i32 @portScan(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%12 = bitcast %struct.timeval* %7 to i8*
%13 = bitcast %struct.sockaddr_in* %8 to i8*
%14 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i32 %15, i32* %16
%17 = load i8, i8* %0
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = call i32 @inet_addr(i8* %0)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1, i32 0
store i32 %21, i32* %22
br label %35
23: ; preds = %4
%24 = call %struct.hostent* @gethostbyname(i8* %0)
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1
%28 = bitcast %struct.TYPE_2__* %27 to i8*
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 0
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i8*
%32 = call i32 @strncpy(i8* %28, i8* %31, i32 4)
br label %35
33: ; preds = %23
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %78
35: ; preds = %26, %20
%36 = icmp sgt i32 %1, %2
br i1 %36, label %78, label %37
37: ; preds = %35
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
%39 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%41 = mul nsw i32 %3, 1000
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%43 = bitcast i32* %9 to i8*
br label %44
44: ; preds = %37, %74
%45 = phi i32 [ %1, %37 ], [ %76, %74 ]
%46 = call i32 @htons(i32 %45)
store i32 %46, i32* %38
%47 = load i32, i32* @AF_INET
%48 = load i32, i32* @SOCK_STREAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %78
53: ; preds = %44
%54 = load i32, i32* @F_SETFL
%55 = load i32, i32* @O_NONBLOCK
%56 = call i32 @fcntl(i32 %49, i32 %54, i32 %55)
%57 = call i32 @connect(i32 %49, %struct.sockaddr* %39, i32 12)
%58 = call i32 @FD_ZERO(i32* %5)
%59 = call i32 @FD_SET(i32 %49, i32* %5)
store i64 0, i64* %40
store i32 %41, i32* %42
%60 = add nuw nsw i32 %49, 1
%61 = call i32 @select(i32 %60, i32* null, i32* %5, i32* null, %struct.timeval* %7)
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %72
63: ; preds = %53
store i32 4, i32* %9
%64 = load i32, i32* @SOL_SOCKET
%65 = load i32, i32* @SO_ERROR
%66 = call i32 @getsockopt(i32 %49, i32 %64, i32 %65, i32* %6, i32* %9)
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %71
71: ; preds = %69, %63
br label %74
72: ; preds = %53
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %74
74: ; preds = %72, %71
%75 = call i32 @close(i32 %49)
%76 = add i32 %45, 1
%77 = icmp eq i32 %45, %2
br i1 %77, label %78, label %44
78: ; preds = %74, %35, %51, %33
%79 = phi i32* [ @EXIT_FAILURE, %51 ], [ @EXIT_FAILURE, %33 ], [ @EXIT_SUCCESS, %35 ], [ @EXIT_SUCCESS, %74 ]
%80 = load i32, i32* %79
ret i32 %80
}