#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 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;
};
typedef int /*<<< orphan*/ echoServAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
char *event_string();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ my_sleep(int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int send(int, char *, unsigned int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
unsigned int strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in echoServAddr;
  unsigned short echoServPort = 5000;
  char *servIP = "127.0.0.1";
  char *echoString;
  unsigned int echoStringLen;
  int loops;
  int sleep_time;
  if ((argc < 3) || (argc > 3)) {
    fprintf(stderr, "Usage: %s <loops> <sleep_time_milis>\n", argv[0]);
    exit(1);
  }
  loops = atoi(argv[1]);
  sleep_time = atoi(argv[2]);
  if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    error("socket() failed");
  memset(&echoServAddr, 0, sizeof(echoServAddr));
  echoServAddr.sin_family = AF_INET;
  echoServAddr.sin_addr.s_addr = inet_addr(servIP);
  echoServAddr.sin_port = htons(echoServPort);
  if (connect(sock, (struct sockaddr *)&echoServAddr, sizeof(echoServAddr)) < 0)
    error("connect() failed");
  int avg = sleep_time;
  int i;
  for (i = 0; i < loops; i++) {
    echoString = event_string();
    echoStringLen = strlen(echoString);
    if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
      error("send() sent a different number of bytes than expected");
    avg += my_sleep(sleep_time);
    avg = avg / 2;
  }
  printf("%d:%d", avg, i);
  printf("\n");
  close(sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x1388,-0x22(%rbp)
lea    0xded(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     122b <main+0x3b>
cmpl   $0x3,-0x8(%rbp)
jle    1251 <main+0x61>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc8(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
mov    0x2d56(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12a9 <main+0xb9>
lea    0xd8c(%rip),%rdi
call   10b0 <error@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
movzwl -0x22(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    1304 <main+0x114>
lea    0xd41(%rip),%rdi
call   10b0 <error@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    138b <main+0x19b>
mov    $0x0,%al
call   10c0 <event_string@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    -0x3c(%rbp),%eax
je     135a <main+0x16a>
lea    0xcfc(%rip),%rdi
call   10b0 <error@plt>
mov    -0x44(%rbp),%edi
call   1100 <my_sleep@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1311 <main+0x121>
mov    -0x48(%rbp),%esi
mov    -0x4c(%rbp),%edx
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1330 <main+0x130>
mov    0x8(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r13d
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
call   1120 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1264 <main+0x64>
lea    0xdd1(%rip),%rdi
call   10c0 <error@plt>
lea    0x8(%rsp),%r12
xor    %r15d,%r15d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xd71(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0x1388,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1100 <connect@plt>
test   %rax,%rax
jns    12c7 <main+0xc7>
lea    0xd7e(%rip),%rdi
call   10c0 <error@plt>
test   %ebp,%ebp
jle    135a <main+0x15a>
mov    %ebp,0x4(%rsp)
mov    %ebp,%r15d
mov    %r13d,%ebp
jmp    12f9 <main+0xf9>
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1110 <my_sleep@plt>
add    %eax,%ebp
mov    %ebp,%eax
shr    $0x1f,%eax
add    %eax,%ebp
sar    %ebp
add    $0xffffffff,%r15d
je     1352 <main+0x152>
xor    %eax,%eax
call   10d0 <event_string@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    %r12d,%eax
je     12e0 <main+0xe0>
lea    0xd28(%rip),%rdi
call   10c0 <error@plt>
jmp    12e0 <main+0xe0>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcc7(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    %ebp,%r13d
mov    0x4(%rsp),%r15d
lea    0xd26(%rip),%rdi
mov    %r13d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"Usage: %s <loops> <sleep_time_milis>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@AF_INET = global i32 0
@.str.3 = [17 x i8] c"connect() failed\00"
@.str.4 = [54 x i8] c"send() sent a different number of bytes than expected\00"
@.str.5 = [6 x i8] c"%d:%d\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i16
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 5000, i16* %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %9
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 3
br i1 %20, label %21, label %28
21: ; preds = %18, %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %12
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %13
%37 = load i32, i32* @PF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = load i32, i32* @IPPROTO_TCP
%40 = call i32 @socket(i32 %37, i32 %38, i32 %39)
store i32 %40, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %28
%43 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %28
%45 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %46, i32* %47
%48 = load i8*, i8** %9
%49 = call i32 @inet_addr(i8* %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
store i32 %49, i32* %51
%52 = load i16, i16* %8
%53 = call i32 @htons(i16 zeroext %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* %6
%56 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%57 = call i64 @connect(i32 %55, %struct.sockaddr* %56, i32 12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %44
%60 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %44
%62 = load i32, i32* %13
store i32 %62, i32* %14
store i32 0, i32* %15
br label %63
63: ; preds = %88, %61
%64 = load i32, i32* %15
%65 = load i32, i32* %12
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %91
67: ; preds = %63
%68 = call i8* (...) @event_string()
store i8* %68, i8** %10
%69 = load i8*, i8** %10
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %11
%71 = load i32, i32* %6
%72 = load i8*, i8** %10
%73 = load i32, i32* %11
%74 = call i32 @send(i32 %71, i8* %72, i32 %73, i32 0)
%75 = load i32, i32* %11
%76 = icmp ne i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %67
%78 = call i32 @error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %77, %67
%80 = load i32, i32* %13
%81 = call i64 @my_sleep(i32 %80)
%82 = load i32, i32* %14
%83 = sext i32 %82 to i64
%84 = add nsw i64 %83, %81
%85 = trunc i64 %84 to i32
store i32 %85, i32* %14
%86 = load i32, i32* %14
%87 = sdiv i32 %86, 2
store i32 %87, i32* %14
br label %88
88: ; preds = %79
%89 = load i32, i32* %15
%90 = add nsw i32 %89, 1
store i32 %90, i32* %15
br label %63
91: ; preds = %63
%92 = load i32, i32* %14
%93 = load i32, i32* %15
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %92, i32 %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%96 = load i32, i32* %6
%97 = call i32 @close(i32 %96)
%98 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"Usage: %s <loops> <sleep_time_milis>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@AF_INET = global i32 0
@.str.3 = [17 x i8] c"connect() failed\00"
@.str.4 = [54 x i8] c"send() sent a different number of bytes than expected\00"
@.str.5 = [6 x i8] c"%d:%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = load i32, i32* @IPPROTO_TCP
%21 = tail call i32 @socket(i32 %18, i32 %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %11
%26 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = call i32 @htons(i16 zeroext 5000)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i64 @connect(i32 %21, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %25
%39 = icmp sgt i32 %14, 0
br i1 %39, label %40, label %56
40: ; preds = %38, %49
%41 = phi i32 [ %54, %49 ], [ 0, %38 ]
%42 = phi i32 [ %53, %49 ], [ %17, %38 ]
%43 = call i8* (...) @event_string()
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @send(i32 %21, i8* %43, i32 %44, i32 0)
%46 = icmp eq i32 %45, %44
br i1 %46, label %49, label %47
47: ; preds = %40
%48 = call i32 @error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %47, %40
%50 = call i64 @my_sleep(i32 %17)
%51 = trunc i64 %50 to i32
%52 = add i32 %42, %51
%53 = sdiv i32 %52, 2
%54 = add nuw nsw i32 %41, 1
%55 = icmp eq i32 %54, %14
br i1 %55, label %56, label %40
56: ; preds = %49, %38
%57 = phi i32 [ %17, %38 ], [ %53, %49 ]
%58 = phi i32 [ 0, %38 ], [ %14, %49 ]
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %57, i32 %58)
%60 = call i32 @putchar(i32 10)
%61 = call i32 @close(i32 %21)
%62 = call i32 @exit(i32 0)
unreachable
}