#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 {
  long long tv_sec;
  int tv_usec;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ sock_opts;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EAGAIN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int client_count_tcp(char *server_ip, char *server_port, char *number_input) {
  int sockfd, rc;
  struct addrinfo hints, *server;
  int number_try, counter = 0, re_counter, dropped = 0, successes = 0;
  struct timeval tval_start, tval_end, sock_opts;
  long long int diff, min = -1LL, max = -1LL;
  long double avg = 0.0L;
  number_try = atoi(number_input);
  if (number_try < 1) {
    printf("Invalid number input, number of connections resets to 100\n");
    number_try = 100;
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  if ((rc = getaddrinfo(server_ip, server_port, &hints, &server)) != 0) {
    perror(gai_strerror(rc));
    exit(-1);
  }
  sockfd = socket(server->ai_family, server->ai_socktype, server->ai_protocol);
  if (sockfd == -1) {
    perror("ERROR opening socket");
    exit(-1);
  }
  sock_opts.tv_sec = 0;
  sock_opts.tv_usec = 500000;
  if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &sock_opts,
                 sizeof(sock_opts)) < 0) {
    perror("ERROR on setsockopt");
    exit(-1);
  }
  rc = connect(sockfd, server->ai_addr, server->ai_addrlen);
  if (rc == -1) {
    perror("ERROR on connect");
    close(sockfd);
    exit(-1);
  }
  while (counter < number_try) {
    int skip = 0;
    gettimeofday(&tval_start, NULL);
    rc = send(sockfd, (char *)&counter, sizeof counter, 0);
    if (rc < 0) {
      perror("ERROR on send");
      exit(-1);
    }
    counter++;
    do {
      rc = recv(sockfd, (char *)&re_counter, sizeof re_counter, 0);
      if (rc < 0) {
        if (errno == EAGAIN) {
          skip = -1;
        } else {
          perror("ERROR on recv");
          exit(-1);
        }
      }
    } while (re_counter != counter - 1 || skip);
    if (skip) {
      dropped++;
      continue;
    }
    successes++;
    gettimeofday(&tval_end, NULL);
    diff = (tval_end.tv_sec - tval_start.tv_sec) * 1000000LL +
           tval_end.tv_usec - tval_start.tv_usec;
    if (min == -1LL || diff < min)
      min = diff;
    if (max == -1LL || diff > max)
      max = diff;
    avg = avg * (successes - 1) / successes + (long double)diff / successes;
  }
  printf("Result:\n");
  printf("        The total number of loops   : %d\n", number_try);
  printf("        The min time of latency     : %lld us\n", min);
  printf("        The max time of latency     : %lld us\n", max);
  printf("        The average time of latency : %Lf us\n", avg);
  printf("        Number of Packets Dropped   : %d\n", dropped);
  freeaddrinfo(server);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<client_count_tcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movq   $0xffffffffffffffff,-0x98(%rbp)
ff ff ff ff
movq   $0xffffffffffffffff,-0xa0(%rbp)
ff ff ff ff
fldz
fstpt  -0xb0(%rbp)
mov    -0x18(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
jge    1265 <client_count_tcp+0x75>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x64,-0x44(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1090 <memset@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     12c8 <client_count_tcp+0xd8>
mov    -0x20(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1305 <client_count_tcp+0x115>
lea    0xd45(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
movq   $0x0,-0x88(%rbp)
movl   $0x7a120,-0x80(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
mov    0x2ca6(%rip),%rax
mov    (%rax),%edx
lea    -0x88(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    135e <client_count_tcp+0x16e>
lea    0xd01(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10e0 <connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    139e <client_count_tcp+0x1ae>
lea    0xcdd(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    13a3 <client_count_tcp+0x1b3>
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    15a7 <client_count_tcp+0x3b7>
movl   $0x0,-0xb4(%rbp)
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x1c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    13fc <client_count_tcp+0x20c>
lea    0xc88(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1469 <client_count_tcp+0x279>
mov    0x2b94(%rip),%rax
mov    (%rax),%rax
mov    0x2b7a(%rip),%rcx
cmp    (%rcx),%rax
jne    144e <client_count_tcp+0x25e>
movl   $0xffffffff,-0xb4(%rbp)
ff ff ff
jmp    1464 <client_count_tcp+0x274>
lea    0xc2e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    1469 <client_count_tcp+0x279>
jmp    146e <client_count_tcp+0x27e>
mov    -0x4c(%rbp),%ecx
mov    -0x48(%rbp),%edx
sub    $0x1,%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0xc5(%rbp)
jne    1497 <client_count_tcp+0x2a7>
cmpl   $0x0,-0xb4(%rbp)
setne  %al
mov    %al,-0xc5(%rbp)
mov    -0xc5(%rbp),%al
test   $0x1,%al
jne    1405 <client_count_tcp+0x215>
cmpl   $0x0,-0xb4(%rbp)
je     14c0 <client_count_tcp+0x2d0>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    13a3 <client_count_tcp+0x1b3>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
lea    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x78(%rbp),%rax
sub    -0x68(%rbp),%rax
imul   $0xf4240,%rax,%rax
movslq -0x70(%rbp),%rcx
add    %rcx,%rax
movslq -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x90(%rbp)
cmpq   $0xffffffffffffffff,-0x98(%rbp)
ff
je     151c <client_count_tcp+0x32c>
mov    -0x90(%rbp),%rax
cmp    -0x98(%rbp),%rax
jge    152a <client_count_tcp+0x33a>
mov    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
cmpq   $0xffffffffffffffff,-0xa0(%rbp)
ff
je     154c <client_count_tcp+0x35c>
mov    -0x90(%rbp),%rax
cmp    -0xa0(%rbp),%rax
jle    155a <client_count_tcp+0x36a>
mov    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
fldt   -0xb0(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xb8(%rbp)
fildl  -0xb8(%rbp)
fmulp  %st,%st(1)
mov    %eax,-0xc4(%rbp)
fildl  -0xc4(%rbp)
fdivr  %st,%st(1)
mov    -0x90(%rbp),%rax
mov    %rax,-0xc0(%rbp)
fildll -0xc0(%rbp)
fdivp  %st,%st(1)
faddp  %st,%st(1)
fstpt  -0xb0(%rbp)
jmp    13a3 <client_count_tcp+0x1b3>
lea    0xae3(%rip),%rdi
xor    %eax,%eax
mov    %al,-0xc6(%rbp)
call   1060 <printf@plt>
mov    -0xc6(%rbp),%al
mov    -0x44(%rbp),%esi
lea    0xacf(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc6(%rbp),%al
mov    -0x98(%rbp),%rsi
lea    0xae0(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc6(%rbp),%al
mov    -0xa0(%rbp),%rsi
lea    0xaf6(%rip),%rdi
call   1060 <printf@plt>
fldt   -0xb0(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x50(%rbp),%esi
lea    0xb2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_count_tcp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%r15
mov    %rdi,%rbp
movl   $0x0,0x18(%rsp)
mov    %rdx,%rdi
call   10d0 <atoi@plt>
mov    %eax,0x1c(%rsp)
test   %eax,%eax
jg     1243 <client_count_tcp+0x43>
lea    0xf08(%rip),%rdi
call   1040 <puts@plt>
movl   $0x64,0x1c(%rsp)
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   10a0 <memset@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x90(%rsp)
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8c(%rsp)
lea    0x20(%rsp),%rcx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1100 <getaddrinfo@plt>
test   %eax,%eax
jne    14fc <client_count_tcp+0x2fc>
mov    0x20(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1508 <client_count_tcp+0x308>
mov    %eax,%r13d
movq   $0x0,0x50(%rsp)
movl   $0x7a120,0x58(%rsp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
mov    0x2cfb(%rip),%rax
mov    (%rax),%edx
lea    0x50(%rsp),%rcx
mov    %r13d,%edi
mov    $0x10,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     1511 <client_count_tcp+0x311>
mov    0x20(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r13d,%edi
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
je     151a <client_count_tcp+0x31a>
xor    %eax,%eax
mov    %rax,0x40(%rsp)
mov    $0xffffffffffffffff,%r15
fldz
fstpt  0x34(%rsp)
lea    0x30(%rsp),%r12
mov    0x2c92(%rip),%rbp
mov    $0xffffffffffffffff,%r14
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x70(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
mov    %r13d,%edi
lea    0x18(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     14f3 <client_count_tcp+0x2f3>
addl   $0x1,0x18(%rsp)
xor    %ebx,%ebx
nop
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    139f <client_count_tcp+0x19f>
mov    0x0(%rbp),%rax
mov    $0xffffffff,%ebx
mov    0x2c1a(%rip),%rcx
cmp    (%rcx),%rax
jne    14dd <client_count_tcp+0x2dd>
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,0x30(%rsp)
jne    1370 <client_count_tcp+0x170>
test   %ebx,%ebx
jne    1370 <client_count_tcp+0x170>
mov    0x40(%rsp),%rbx
lea    0x1(%rbx),%ebp
lea    0x60(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
mov    0x60(%rsp),%rax
sub    0x70(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x68(%rsp),%rcx
add    %rax,%rcx
movslq 0x78(%rsp),%rax
sub    %rax,%rcx
cmp    %r14,%rcx
mov    %r14,%rax
cmovl  %rcx,%rax
cmp    $0xffffffffffffffff,%r14
mov    %rax,%r14
cmove  %rcx,%r14
cmp    %r15,%rcx
mov    %r15,%rax
cmovg  %rcx,%rax
cmp    $0xffffffffffffffff,%r15
mov    %rax,%r15
cmove  %rcx,%r15
mov    %ebp,0x2c(%rsp)
fildl  0x2c(%rsp)
mov    %ebx,0x28(%rsp)
fldt   0x34(%rsp)
fimull 0x28(%rsp)
fdiv   %st(1),%st
mov    %rcx,0x48(%rsp)
fildll 0x48(%rsp)
fdivp  %st,%st(2)
faddp  %st,%st(1)
fstpt  0x34(%rsp)
mov    %ebp,%eax
mov    %rax,0x40(%rsp)
mov    0x2b7c(%rip),%rbp
mov    0x1c(%rsp),%eax
cmp    %eax,0x18(%rsp)
jl     1340 <client_count_tcp+0x140>
lea    0xcdd(%rip),%rdi
call   1040 <puts@plt>
lea    0xbf1(%rip),%rdi
mov    0x1c(%rsp),%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc09(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc27(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
fldt   0x34(%rsp)
fstpt  (%rsp)
lea    0xc3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc5e(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x20(%rsp),%rdi
call   1110 <freeaddrinfo@plt>
mov    %r13d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb64(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xb40(%rip),%rdi
jmp    14e4 <client_count_tcp+0x2e4>
mov    %eax,%edi
call   1080 <gai_strerror@plt>
mov    %rax,%rdi
jmp    14e4 <client_count_tcp+0x2e4>
lea    0xaf1(%rip),%rdi
jmp    14e4 <client_count_tcp+0x2e4>
lea    0xafd(%rip),%rdi
jmp    14e4 <client_count_tcp+0x2e4>
lea    0xb08(%rip),%rdi
call   10c0 <perror@plt>
mov    %r13d,%edi
call   10b0 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
%struct.timeval = type { i64, i32 }
@.str = [59 x i8] c"Invalid number input, number of connections resets to 100\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.2 = [20 x i8] c"ERROR on setsockopt\00"
@.str.3 = [17 x i8] c"ERROR on connect\00"
@.str.4 = [14 x i8] c"ERROR on send\00"
@errno = global i64 0
@EAGAIN = global i64 0
@.str.5 = [14 x i8] c"ERROR on recv\00"
@.str.6 = [9 x i8] c"Result:\0A\00"
@.str.7 = [42 x i8] c" The total number of loops : %d\0A\00"
@.str.8 = [47 x i8] c" The min time of latency : %lld us\0A\00"
@.str.9 = [47 x i8] c" The max time of latency : %lld us\0A\00"
@.str.10 = [46 x i8] c" The average time of latency : %Lf us\0A\00"
@.str.11 = [42 x i8] c" Number of Packets Dropped : %d\0A\00"
define i32 @client_count_tcp(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.timeval
%17 = alloca %struct.timeval
%18 = alloca %struct.timeval
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca x86_fp80
%23 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %12
store i32 0, i32* %14
store i32 0, i32* %15
store i64 -1, i64* %20
store i64 -1, i64* %21
store x86_fp80 0xK00000000000000000000, x86_fp80* %22
%24 = load i8*, i8** %6
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
store i32 100, i32* %11
br label %30
30: ; preds = %28, %3
%31 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 20)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %32, i32* %33
%34 = load i32, i32* @SOCK_STREAM
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32 %34, i32* %35
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = call i32 @getaddrinfo(i8* %36, i8* %37, %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %38, i32* %8
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %30
%41 = load i32, i32* %8
%42 = call i8* @gai_strerror(i32 %41)
%43 = call i32 @perror(i8* %42)
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %30
%46 = load %struct.addrinfo*, %struct.addrinfo** %10
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 4
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %10
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 3
%51 = load i32, i32* %50
%52 = load %struct.addrinfo*, %struct.addrinfo** %10
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 2
%54 = load i32, i32* %53
%55 = call i32 @socket(i32 %48, i32 %51, i32 %54)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %45
%59 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %45
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
store i64 0, i64* %62
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
store i32 500000, i32* %63
%64 = load i32, i32* %7
%65 = load i32, i32* @SOL_SOCKET
%66 = load i32, i32* @SO_RCVTIMEO
%67 = call i64 @setsockopt(i32 %64, i32 %65, i32 %66, %struct.timeval* %18, i32 16)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %61
%70 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%71 = call i32 @exit(i32 -1)
unreachable
72: ; preds = %61
%73 = load i32, i32* %7
%74 = load %struct.addrinfo*, %struct.addrinfo** %10
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 1
%76 = load i32, i32* %75
%77 = load %struct.addrinfo*, %struct.addrinfo** %10
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @connect(i32 %73, i32 %76, i32 %79)
store i32 %80, i32* %8
%81 = load i32, i32* %8
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %88
83: ; preds = %72
%84 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%85 = load i32, i32* %7
%86 = call i32 @close(i32 %85)
%87 = call i32 @exit(i32 -1)
unreachable
88: ; preds = %72
br label %89
89: ; preds = %173, %135, %88
%90 = load i32, i32* %12
%91 = load i32, i32* %11
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %188
93: ; preds = %89
store i32 0, i32* %23
%94 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%95 = load i32, i32* %7
%96 = bitcast i32* %12 to i8*
%97 = call i32 @send(i32 %95, i8* %96, i32 4, i32 0)
store i32 %97, i32* %8
%98 = load i32, i32* %8
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %93
%101 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%102 = call i32 @exit(i32 -1)
unreachable
103: ; preds = %93
%104 = load i32, i32* %12
%105 = add nsw i32 %104, 1
store i32 %105, i32* %12
br label %106
106: ; preds = %130, %103
%107 = load i32, i32* %7
%108 = bitcast i32* %13 to i8*
%109 = call i32 @recv(i32 %107, i8* %108, i32 4, i32 0)
store i32 %109, i32* %8
%110 = load i32, i32* %8
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %121
112: ; preds = %106
%113 = load i64, i64* @errno
%114 = load i64, i64* @EAGAIN
%115 = icmp eq i64 %113, %114
br i1 %115, label %116, label %117
116: ; preds = %112
store i32 -1, i32* %23
br label %120
117: ; preds = %112
%118 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%119 = call i32 @exit(i32 -1)
unreachable
120: ; preds = %116
br label %121
121: ; preds = %120, %106
br label %122
122: ; preds = %121
%123 = load i32, i32* %13
%124 = load i32, i32* %12
%125 = sub nsw i32 %124, 1
%126 = icmp ne i32 %123, %125
br i1 %126, label %130, label %127
127: ; preds = %122
%128 = load i32, i32* %23
%129 = icmp ne i32 %128, 0
br label %130
130: ; preds = %127, %122
%131 = phi i1 [ true, %122 ], [ %129, %127 ]
br i1 %131, label %106, label %132
132: ; preds = %130
%133 = load i32, i32* %23
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %138
135: ; preds = %132
%136 = load i32, i32* %14
%137 = add nsw i32 %136, 1
store i32 %137, i32* %14
br label %89
138: ; preds = %132
%139 = load i32, i32* %15
%140 = add nsw i32 %139, 1
store i32 %140, i32* %15
%141 = call i32 @gettimeofday(%struct.timeval* %17, i32* null)
%142 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%143 = load i64, i64* %142
%144 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%145 = load i64, i64* %144
%146 = sub nsw i64 %143, %145
%147 = mul nsw i64 %146, 1000000
%148 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%149 = load i32, i32* %148
%150 = sext i32 %149 to i64
%151 = add nsw i64 %147, %150
%152 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%153 = load i32, i32* %152
%154 = sext i32 %153 to i64
%155 = sub nsw i64 %151, %154
store i64 %155, i64* %19
%156 = load i64, i64* %20
%157 = icmp eq i64 %156, -1
br i1 %157, label %162, label %158
158: ; preds = %138
%159 = load i64, i64* %19
%160 = load i64, i64* %20
%161 = icmp slt i64 %159, %160
br i1 %161, label %162, label %164
162: ; preds = %158, %138
%163 = load i64, i64* %19
store i64 %163, i64* %20
br label %164
164: ; preds = %162, %158
%165 = load i64, i64* %21
%166 = icmp eq i64 %165, -1
br i1 %166, label %171, label %167
167: ; preds = %164
%168 = load i64, i64* %19
%169 = load i64, i64* %21
%170 = icmp sgt i64 %168, %169
br i1 %170, label %171, label %173
171: ; preds = %167, %164
%172 = load i64, i64* %19
store i64 %172, i64* %21
br label %173
173: ; preds = %171, %167
%174 = load x86_fp80, x86_fp80* %22
%175 = load i32, i32* %15
%176 = sub nsw i32 %175, 1
%177 = sitofp i32 %176 to x86_fp80
%178 = fmul x86_fp80 %174, %177
%179 = load i32, i32* %15
%180 = sitofp i32 %179 to x86_fp80
%181 = fdiv x86_fp80 %178, %180
%182 = load i64, i64* %19
%183 = sitofp i64 %182 to x86_fp80
%184 = load i32, i32* %15
%185 = sitofp i32 %184 to x86_fp80
%186 = fdiv x86_fp80 %183, %185
%187 = fadd x86_fp80 %181, %186
store x86_fp80 %187, x86_fp80* %22
br label %89
188: ; preds = %89
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%190 = load i32, i32* %11
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %190)
%192 = load i64, i64* %20
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i64 %192)
%194 = load i64, i64* %21
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0), i64 %194)
%196 = load x86_fp80, x86_fp80* %22
%197 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), x86_fp80 %196)
%198 = load i32, i32* %14
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 %198)
%200 = load %struct.addrinfo*, %struct.addrinfo** %10
%201 = call i32 @freeaddrinfo(%struct.addrinfo* %200)
%202 = load i32, i32* %7
%203 = call i32 @close(i32 %202)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
%struct.timeval = type { i64, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.2 = [20 x i8] c"ERROR on setsockopt\00"
@.str.3 = [17 x i8] c"ERROR on connect\00"
@.str.4 = [14 x i8] c"ERROR on send\00"
@errno = global i64 0
@EAGAIN = global i64 0
@.str.5 = [14 x i8] c"ERROR on recv\00"
@.str.7 = [42 x i8] c" The total number of loops : %d\0A\00"
@.str.8 = [47 x i8] c" The min time of latency : %lld us\0A\00"
@.str.9 = [47 x i8] c" The max time of latency : %lld us\0A\00"
@.str.10 = [46 x i8] c" The average time of latency : %Lf us\0A\00"
@.str.11 = [42 x i8] c" Number of Packets Dropped : %d\0A\00"
@str = [8 x i8] c"Result:\00"
@str.12 = [58 x i8] c"Invalid number input, number of connections resets to 100\00"
define i32 @client_count_tcp(i8* %0, i8* %1, i8* nocapture %2) {
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = bitcast %struct.addrinfo* %4 to i8*
%12 = bitcast %struct.addrinfo** %5 to i8*
%13 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%14 = bitcast i32* %7 to i8*
%15 = bitcast %struct.timeval* %8 to i8*
%16 = bitcast %struct.timeval* %9 to i8*
%17 = bitcast %struct.timeval* %10 to i8*
%18 = tail call i32 @atoi(i8* %2)
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.12, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = phi i32 [ 100, %20 ], [ %18, %3 ]
%24 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 20)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %25, i32* %26
%27 = load i32, i32* @SOCK_STREAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %27, i32* %28
%29 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %4, %struct.addrinfo** %5)
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %22
%32 = call i8* @gai_strerror(i32 %29)
%33 = call i32 @perror(i8* %32)
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %22
%36 = load %struct.addrinfo*, %struct.addrinfo** %5
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 4
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 3
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 2
%42 = load i32, i32* %41
%43 = call i32 @socket(i32 %38, i32 %40, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %35
%46 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %35
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
store i64 0, i64* %49
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
store i32 500000, i32* %50
%51 = load i32, i32* @SOL_SOCKET
%52 = load i32, i32* @SO_RCVTIMEO
%53 = call i64 @setsockopt(i32 %43, i32 %51, i32 %52, %struct.timeval* %10, i32 16)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %48
%59 = load %struct.addrinfo*, %struct.addrinfo** %5
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i64 0, i32 1
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i64 0, i32 0
%63 = load i32, i32* %62
%64 = call i32 @connect(i32 %43, i32 %61, i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %71, label %66
66: ; preds = %58
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
br label %75
71: ; preds = %58
%72 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 @close(i32 %43)
%74 = call i32 @exit(i32 -1)
unreachable
75: ; preds = %66, %108
%76 = phi x86_fp80 [ 0xK00000000000000000000, %66 ], [ %135, %108 ]
%77 = phi i64 [ -1, %66 ], [ %128, %108 ]
%78 = phi i64 [ -1, %66 ], [ %124, %108 ]
%79 = phi i32 [ 0, %66 ], [ %109, %108 ]
%80 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%81 = call i32 @send(i32 %43, i8* %13, i32 4, i32 0)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %75
%84 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%85 = call i32 @exit(i32 -1)
unreachable
86: ; preds = %75
%87 = load i32, i32* %6
%88 = add nsw i32 %87, 1
store i32 %88, i32* %6
br label %89
89: ; preds = %100, %86
%90 = phi i32 [ 0, %86 ], [ %101, %100 ]
%91 = call i32 @recv(i32 %43, i8* %14, i32 4, i32 0)
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %100
93: ; preds = %89
%94 = load i64, i64* @errno
%95 = load i64, i64* @EAGAIN
%96 = icmp eq i64 %94, %95
br i1 %96, label %100, label %97
97: ; preds = %93
%98 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %93, %89
%101 = phi i32 [ %90, %89 ], [ -1, %93 ]
%102 = load i32, i32* %7
%103 = load i32, i32* %6
%104 = add nsw i32 %103, -1
%105 = icmp ne i32 %102, %104
%106 = icmp ne i32 %101, 0
%107 = select i1 %105, i1 true, i1 %106
br i1 %107, label %89, label %108
108: ; preds = %100
%109 = add nuw nsw i32 %79, 1
%110 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%111 = load i64, i64* %67
%112 = load i64, i64* %68
%113 = sub nsw i64 %111, %112
%114 = mul nsw i64 %113, 1000000
%115 = load i32, i32* %69
%116 = sext i32 %115 to i64
%117 = add nsw i64 %114, %116
%118 = load i32, i32* %70
%119 = sext i32 %118 to i64
%120 = sub i64 %117, %119
%121 = icmp eq i64 %78, -1
%122 = icmp slt i64 %120, %78
%123 = select i1 %121, i1 true, i1 %122
%124 = select i1 %123, i64 %120, i64 %78
%125 = icmp eq i64 %77, -1
%126 = icmp sgt i64 %120, %77
%127 = select i1 %125, i1 true, i1 %126
%128 = select i1 %127, i64 %120, i64 %77
%129 = sitofp i32 %109 to x86_fp80
%130 = sitofp i32 %79 to x86_fp80
%131 = fmul x86_fp80 %76, %130
%132 = fdiv x86_fp80 %131, %129
%133 = sitofp i64 %120 to x86_fp80
%134 = fdiv x86_fp80 %133, %129
%135 = fadd x86_fp80 %132, %134
%136 = load i32, i32* %6
%137 = icmp slt i32 %136, %23
br i1 %137, label %75, label %138
138: ; preds = %108
%139 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%140 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%141 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i64 %124)
%142 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0), i64 %128)
%143 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), x86_fp80 %135)
%144 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 0)
%145 = load %struct.addrinfo*, %struct.addrinfo** %5
%146 = call i32 @freeaddrinfo(%struct.addrinfo* %145)
%147 = call i32 @close(i32 %43)
ret i32 0
}