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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ recv(int, scalar_t__ *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int portNumber;
  if (argc < 2) {
    portNumber = 9191;
  } else {
    portNumber = atoi(argv[1]);
  }
  struct sockaddr_in serv_addr, client_addr;
  int fd = 0;
  int fdconn = 0;
  int out = 0;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  printf("Socket: %dn", fd);
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(portNumber);
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  listen(fd, 100);
  struct timeval start_time, end_time, last_measurement;
  int goodCount = 0;
  int badCount = 0;
  uint8_t buffer[1500];
  gettimeofday(&start_time, NULL);
  last_measurement = start_time;
  while (1) {
    ssize_t size = recv(fd, buffer, 1500, 0);
    if (size > 0) {
      if (buffer[0] == 0)
        goodCount++;
      else
        badCount++;
    }
    gettimeofday(&end_time, NULL);
    long long measured = (end_time.tv_sec - last_measurement.tv_sec) * 1000000 +
                         (end_time.tv_usec - last_measurement.tv_usec);
    if (measured >= 0.1 * 1000000) {
      printf("good %.1f\tbad %.1f\n",
             goodCount * 8.0 * 1000.0 * 0.000001 / (measured / 1000000.0),
             badCount * 8.0 * 1000.0 * 0.000001 / (measured / 1000000.0));
      goodCount = badCount = 0;
      last_measurement = end_time;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bf <main+0x2f>
movl   $0x23e7,-0x14(%rbp)
jmp    11cf <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    -0x34(%rbp),%edi
mov    $0x64,%esi
call   1080 <listen@plt>
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x2f40(%rbp),%rsi
mov    $0x5dc,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x2f48(%rbp)
cmpq   $0x0,-0x2f48(%rbp)
jle    12cf <main+0x13f>
cmpq   $0x0,-0x2f40(%rbp)
jne    12c1 <main+0x131>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    12ca <main+0x13a>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    12cf <main+0x13f>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x50(%rbp),%eax
sub    -0x58(%rbp),%eax
imul   $0xf4240,%eax,%eax
mov    -0x4c(%rbp),%ecx
sub    -0x54(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x2f50(%rbp)
cvtsi2sdq -0x2f50(%rbp),%xmm0
movsd  0xcf6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     13c0 <main+0x230>
cvtsi2sdl -0x5c(%rbp),%xmm0
movsd  0xcff(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xceb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcd7(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x2f50(%rbp),%xmm1
ff ff
movsd  0xcba(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
cvtsi2sdl -0x60(%rbp),%xmm0
movsd  0xcb9(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xca5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc91(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x2f50(%rbp),%xmm1
ff ff
movsd  0xc74(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
lea    0xc91(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    127a <main+0xea>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2f18,%rsp
mov    $0x23e7,%ebp
cmp    $0x2,%edi
jl     11b6 <main+0x26>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x2e2b(%rip),%r14
mov    (%r14),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
lea    0xe47(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%eax
mov    %eax,0x28(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x24(%rsp)
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %ebx,%r14d
mov    %ebx,%edi
mov    $0x64,%esi
call   1080 <listen@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x18(%rsp),%r15d
mov    0x1c(%rsp),%r13d
jmp    12b0 <main+0x120>
xchg   %ax,%ax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
movsd  0xda8(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xda4(%rip),%xmm3
mulsd  %xmm3,%xmm0
movsd  0xda0(%rip),%xmm4
mulsd  %xmm4,%xmm0
divsd  0xd9c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm3,%xmm0
mulsd  %xmm4,%xmm0
divsd  %xmm1,%xmm0
lea    0xd89(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %ebp,%r13d
mov    %ebx,%r15d
movl   $0x0,0xc(%rsp)
xor    %r12d,%r12d
jmp    12f5 <main+0x165>
nopl   (%rax)
add    $0x1,%r12d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x10(%rsp),%ebx
mov    0x14(%rsp),%ebp
mov    %ebx,%eax
sub    %r15d,%eax
imul   $0xf4240,%eax,%ecx
mov    %ebp,%eax
sub    %r13d,%eax
add    %ecx,%eax
cmp    $0x186a0,%eax
jge    1240 <main+0xb0>
mov    %r14d,%edi
lea    0x30(%rsp),%rsi
mov    $0x5dc,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    12c4 <main+0x134>
cmpq   $0x0,0x30(%rsp)
jne    12c0 <main+0x130>
addl   $0x1,0xc(%rsp)
jmp    12c4 <main+0x134>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"Socket: %dn\00"
@INADDR_ANY = global i32 0
@.str.1 = [20 x i8] c"good %.1f\09bad %.1f\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 %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = alloca i32
%16 = alloca i32
%17 = alloca [1500 x i64]
%18 = alloca i64
%19 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 9191, i32* %6
br label %28
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %6
br label %28
28: ; preds = %23, %22
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_DGRAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* %6
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %37, i32* %38
%39 = load i32, i32* @INADDR_ANY
%40 = call i32 @htonl(i32 %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = load i32, i32* %9
%44 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = load i32, i32* %9
%47 = call i32 @listen(i32 %46, i32 100)
store i32 0, i32* %15
store i32 0, i32* %16
%48 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%49 = bitcast %struct.timeval* %14 to i8*
%50 = bitcast %struct.timeval* %12 to i8*
br label %51
51: ; preds = %28, %109
%52 = load i32, i32* %9
%53 = getelementptr inbounds [1500 x i64], [1500 x i64]* %17, i64 0, i64 0
%54 = call i64 @recv(i32 %52, i64* %53, i32 1500, i32 0)
store i64 %54, i64* %18
%55 = load i64, i64* %18
%56 = icmp sgt i64 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %51
%58 = getelementptr inbounds [1500 x i64], [1500 x i64]* %17, i64 0, i64 0
%59 = load i64, i64* %58
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i32, i32* %15
%63 = add nsw i32 %62, 1
store i32 %63, i32* %15
br label %67
64: ; preds = %57
%65 = load i32, i32* %16
%66 = add nsw i32 %65, 1
store i32 %66, i32* %16
br label %67
67: ; preds = %64, %61
br label %68
68: ; preds = %67, %51
%69 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%71 = load i32, i32* %70
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%73 = load i32, i32* %72
%74 = sub nsw i32 %71, %73
%75 = mul nsw i32 %74, 1000000
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%79 = load i32, i32* %78
%80 = sub nsw i32 %77, %79
%81 = add nsw i32 %75, %80
%82 = sext i32 %81 to i64
store i64 %82, i64* %19
%83 = load i64, i64* %19
%84 = sitofp i64 %83 to double
%85 = fcmp oge double %84, 1.000000e+05
br i1 %85, label %86, label %109
86: ; preds = %68
%87 = load i32, i32* %15
%88 = sitofp i32 %87 to double
%89 = fmul double %88, 8.000000e+00
%90 = fmul double %89, 1.000000e+03
%91 = fmul double %90, 0x3EB0C6F7A0B5ED8D
%92 = load i64, i64* %19
%93 = sitofp i64 %92 to double
%94 = fdiv double %93, 1.000000e+06
%95 = fdiv double %91, %94
%96 = fptosi double %95 to i32
%97 = load i32, i32* %16
%98 = sitofp i32 %97 to double
%99 = fmul double %98, 8.000000e+00
%100 = fmul double %99, 1.000000e+03
%101 = fmul double %100, 0x3EB0C6F7A0B5ED8D
%102 = load i64, i64* %19
%103 = sitofp i64 %102 to double
%104 = fdiv double %103, 1.000000e+06
%105 = fdiv double %101, %104
%106 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %96, double %105)
store i32 0, i32* %16
store i32 0, i32* %15
%107 = bitcast %struct.timeval* %14 to i8*
%108 = bitcast %struct.timeval* %13 to i8*
br label %109
109: ; preds = %86, %68
br label %51
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"Socket: %dn\00"
@INADDR_ANY = global i32 0
@.str.1 = [20 x i8] c"good %.1f\09bad %.1f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca [1500 x i64]
%7 = icmp slt i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ %11, %8 ], [ 9191, %2 ]
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 %13)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = tail call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i32 @bind(i32 %17, %struct.sockaddr* %26, i32 12)
%28 = call i32 @listen(i32 %17, i32 100)
%29 = bitcast %struct.timeval* %4 to i8*
%30 = bitcast %struct.timeval* %5 to i8*
%31 = bitcast [1500 x i64]* %6 to i8*
%32 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [1500 x i64], [1500 x i64]* %6, i64 0, i64 0
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
br label %40
40: ; preds = %66, %12
%41 = phi i32 [ %62, %66 ], [ %36, %12 ]
%42 = phi i32 [ %59, %66 ], [ %34, %12 ]
br label %43
43: ; preds = %40, %55
%44 = phi i32 [ %56, %55 ], [ 0, %40 ]
%45 = phi i32 [ %57, %55 ], [ 0, %40 ]
%46 = call i64 @recv(i32 %17, i64* %37, i32 1500, i32 0)
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i64, i64* %37
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = add nsw i32 %44, 1
br label %55
53: ; preds = %48
%54 = add nsw i32 %45, 1
br label %55
55: ; preds = %51, %53, %43
%56 = phi i32 [ %52, %51 ], [ %44, %53 ], [ %44, %43 ]
%57 = phi i32 [ %45, %51 ], [ %54, %53 ], [ %45, %43 ]
%58 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%59 = load i32, i32* %38
%60 = sub nsw i32 %59, %42
%61 = mul nsw i32 %60, 1000000
%62 = load i32, i32* %39
%63 = sub nsw i32 %62, %41
%64 = add nsw i32 %61, %63
%65 = icmp sgt i32 %64, 99999
br i1 %65, label %66, label %43
66: ; preds = %55
%67 = sitofp i32 %64 to double
%68 = sitofp i32 %56 to double
%69 = fmul double %68, 8.000000e+00
%70 = fmul double %69, 1.000000e+03
%71 = fmul double %70, 0x3EB0C6F7A0B5ED8D
%72 = fdiv double %67, 1.000000e+06
%73 = fdiv double %71, %72
%74 = fptosi double %73 to i32
%75 = sitofp i32 %57 to double
%76 = fmul double %75, 8.000000e+00
%77 = fmul double %76, 1.000000e+03
%78 = fmul double %77, 0x3EB0C6F7A0B5ED8D
%79 = fdiv double %78, %72
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %74, double %79)
br label %40
}