#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 sockaddr_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sock_opts;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EAGAIN;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int atoi(char *);
int /*<<< orphan*/ close(int);
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 recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int client_count_udp(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_DGRAM;
  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);
  }
  while (counter < number_try) {
    int skip = 0;
    struct sockaddr_storage client_addr;
    socklen_t addr_size = sizeof client_addr;
    gettimeofday(&tval_start, NULL);
    rc = sendto(sockfd, (char *)&counter, sizeof counter, 0, server->ai_addr,
                server->ai_addrlen);
    if (rc < 0) {
      perror("ERROR on sendto");
      exit(-1);
    }
    counter++;
    do {
      rc = recvfrom(sockfd, (char *)&re_counter, sizeof re_counter, MSG_WAITALL,
                    (struct sockaddr *)&client_addr, &addr_size);
      if (rc < 0) {
        if (errno == EAGAIN) {
          skip = -1;
        } else {
          perror("ERROR on recvfrom");
          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_udp>:
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    1255 <client_count_udp+0x75>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x64,-0x44(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d60(%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   10e0 <getaddrinfo@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     12b8 <client_count_udp+0xd8>
mov    -0x20(%rbp),%edi
call   1050 <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   1100 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12f5 <client_count_udp+0x115>
lea    0xd55(%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    0x2cd7(%rip),%rax
mov    (%rax),%esi
mov    0x2cae(%rip),%rax
mov    (%rax),%edx
lea    -0x88(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    134e <client_count_udp+0x16e>
lea    0xd11(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    1353 <client_count_udp+0x173>
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1585 <client_count_udp+0x3a5>
movl   $0x0,-0xb4(%rbp)
movl   $0x4,-0xbc(%rbp)
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x1c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x40(%rbp),%rax
mov    (%rax),%r9d
mov    $0x4,%edx
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    13c5 <client_count_udp+0x1e5>
lea    0xcae(%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    0x2bd4(%rip),%rax
mov    (%rax),%ecx
lea    -0xb8(%rbp),%r8
mov    $0x4,%edx
lea    -0xbc(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1447 <client_count_udp+0x267>
mov    0x2bb6(%rip),%rax
mov    (%rax),%rax
mov    0x2b94(%rip),%rcx
cmp    (%rcx),%rax
jne    142c <client_count_udp+0x24c>
movl   $0xffffffff,-0xb4(%rbp)
ff ff ff
jmp    1442 <client_count_udp+0x262>
lea    0xc41(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    1447 <client_count_udp+0x267>
jmp    144c <client_count_udp+0x26c>
mov    -0x4c(%rbp),%ecx
mov    -0x48(%rbp),%edx
sub    $0x1,%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0xcd(%rbp)
jne    1475 <client_count_udp+0x295>
cmpl   $0x0,-0xb4(%rbp)
setne  %al
mov    %al,-0xcd(%rbp)
mov    -0xcd(%rbp),%al
test   $0x1,%al
jne    13ce <client_count_udp+0x1ee>
cmpl   $0x0,-0xb4(%rbp)
je     149e <client_count_udp+0x2be>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1353 <client_count_udp+0x173>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
lea    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <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     14fa <client_count_udp+0x31a>
mov    -0x90(%rbp),%rax
cmp    -0x98(%rbp),%rax
jge    1508 <client_count_udp+0x328>
mov    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
cmpq   $0xffffffffffffffff,-0xa0(%rbp)
ff
je     152a <client_count_udp+0x34a>
mov    -0x90(%rbp),%rax
cmp    -0xa0(%rbp),%rax
jle    1538 <client_count_udp+0x358>
mov    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
fldt   -0xb0(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc0(%rbp)
fildl  -0xc0(%rbp)
fmulp  %st,%st(1)
mov    %eax,-0xcc(%rbp)
fildl  -0xcc(%rbp)
fdivr  %st,%st(1)
mov    -0x90(%rbp),%rax
mov    %rax,-0xc8(%rbp)
fildll -0xc8(%rbp)
fdivp  %st,%st(1)
faddp  %st,%st(1)
fstpt  -0xb0(%rbp)
jmp    1353 <client_count_udp+0x173>
lea    0xafa(%rip),%rdi
xor    %eax,%eax
mov    %al,-0xce(%rbp)
call   1040 <printf@plt>
mov    -0xce(%rbp),%al
mov    -0x44(%rbp),%esi
lea    0xae6(%rip),%rdi
call   1040 <printf@plt>
mov    -0xce(%rbp),%al
mov    -0x98(%rbp),%rsi
lea    0xaf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0xce(%rbp),%al
mov    -0xa0(%rbp),%rsi
lea    0xb0d(%rip),%rdi
call   1040 <printf@plt>
fldt   -0xb0(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb25(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x50(%rbp),%esi
lea    0xb42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_count_udp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
movl   $0x0,0x18(%rsp)
mov    %rdx,%rdi
call   10d0 <atoi@plt>
mov    %eax,0x1c(%rsp)
test   %eax,%eax
jg     1233 <client_count_udp+0x43>
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
movl   $0x64,0x1c(%rsp)
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xb0(%rsp)
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xac(%rsp)
lea    0x30(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
jne    1525 <client_count_udp+0x335>
mov    0x30(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     1531 <client_count_udp+0x341>
mov    %eax,%ebp
movq   $0x0,0x70(%rsp)
movl   $0x7a120,0x78(%rsp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
mov    0x2d04(%rip),%rax
mov    (%rax),%edx
lea    0x70(%rsp),%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     153a <client_count_udp+0x34a>
xor    %eax,%eax
mov    %rax,0x28(%rsp)
mov    $0xffffffffffffffff,%rbx
fldz
fstpt  0x4c(%rsp)
mov    0x2cb4(%rip),%r15
lea    0x48(%rsp),%r12
lea    0x68(%rsp),%r13
lea    0x44(%rsp),%r14
movq   $0xffffffffffffffff,0x20(%rsp)
ff ff
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,0x58(%rsp)
movl   $0x4,0x44(%rsp)
lea    0x90(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x30(%rsp),%rax
mov    (%rax),%r9d
mov    0x4(%rax),%r8d
mov    %ebp,%edi
lea    0x18(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1090 <sendto@plt>
test   %eax,%eax
js     151c <client_count_udp+0x32c>
addl   $0x1,0x18(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x4,%edx
mov    %r13,%r8
mov    %r14,%r9
call   10b0 <recvfrom@plt>
test   %eax,%eax
jns    13ab <client_count_udp+0x1bb>
mov    0x2c2d(%rip),%rax
mov    (%rax),%rax
mov    $0xffffffff,%ebx
mov    0x2c06(%rip),%rcx
cmp    (%rcx),%rax
jne    1506 <client_count_udp+0x316>
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,0x48(%rsp)
jne    1370 <client_count_udp+0x180>
test   %ebx,%ebx
jne    1370 <client_count_udp+0x180>
mov    0x28(%rsp),%rax
add    $0x1,%eax
mov    %eax,0x38(%rsp)
lea    0x80(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x80(%rsp),%rax
sub    0x90(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x88(%rsp),%rcx
add    %rax,%rcx
movslq 0x98(%rsp),%rax
sub    %rax,%rcx
mov    0x20(%rsp),%rdx
cmp    %rdx,%rcx
mov    %rdx,%rax
cmovl  %rcx,%rax
cmp    $0xffffffffffffffff,%rdx
cmove  %rcx,%rax
mov    %rax,0x20(%rsp)
mov    0x58(%rsp),%rdx
cmp    %rdx,%rcx
mov    %rdx,%rbx
cmovg  %rcx,%rbx
cmp    $0xffffffffffffffff,%rdx
cmove  %rcx,%rbx
mov    0x38(%rsp),%eax
mov    %eax,0x40(%rsp)
fildl  0x40(%rsp)
mov    0x28(%rsp),%rdx
mov    %edx,0x3c(%rsp)
fldt   0x4c(%rsp)
fimull 0x3c(%rsp)
fdiv   %st(1),%st
mov    %rcx,0x60(%rsp)
fildll 0x60(%rsp)
fdivp  %st,%st(2)
faddp  %st,%st(1)
fstpt  0x4c(%rsp)
mov    %rax,0x28(%rsp)
mov    0x1c(%rsp),%eax
cmp    %eax,0x18(%rsp)
jl     1320 <client_count_udp+0x130>
lea    0xcaa(%rip),%rdi
call   1030 <puts@plt>
lea    0xbbe(%rip),%rdi
mov    0x1c(%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xbd6(%rip),%rdi
mov    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xbf2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
fldt   0x4c(%rsp)
fstpt  (%rsp)
lea    0xc09(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc29(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rsp),%rdi
call   1100 <freeaddrinfo@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb2c(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xb06(%rip),%rdi
jmp    150d <client_count_udp+0x31d>
mov    %eax,%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
jmp    150d <client_count_udp+0x31d>
lea    0xac8(%rip),%rdi
jmp    150d <client_count_udp+0x31d>
lea    0xad4(%rip),%rdi
jmp    150d <client_count_udp+0x31d>

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

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