#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
size_t sendMessage(int, char *);
long usec();
double getSpeed(int client_sock, uint32_t length, uint32_t count) {
  char *client_message = malloc(length * sizeof(char));
  memset(client_message, 255, length);
  client_message[length - 1] = 0;
  long beforeUsec = usec();
  for (length = 0; length < count; length++) {
    size_t result = sendMessage(client_sock, client_message);
  }
  long afterUsec = usec();
  double secs = (afterUsec * 1.0 - beforeUsec * 1.0) / (1000000.0);
  double speedBs = (length * count) / secs;
  free(client_message);
  return speedBs;
}


x86 assembly (clang, -O0):
<getSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0xff,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1070 <usec@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d2 <getSpeed+0x82>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <sendMessage@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a8 <getSpeed+0x58>
mov    $0x0,%al
call   1070 <usec@plt>
mov    %rax,-0x30(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xe17(%rip),%xmm2
mulsd  %xmm2,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  0xde8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSpeed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebp
mov    %esi,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0xff,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
movslq %r15d,%rax
movb   $0x0,-0x1(%rax,%r13,1)
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <usec@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    11b2 <getSpeed+0x62>
mov    %r14d,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
call   1050 <sendMessage@plt>
add    $0xffffffff,%ebx
jne    11a0 <getSpeed+0x50>
mov    %r14d,%r12d
xor    %eax,%eax
call   1070 <usec@plt>
cvtsi2sd %rax,%xmm0
cvtsi2sd %r15,%xmm1
subsd  %xmm1,%xmm0
divsd  0xe31(%rip),%xmm0
imul   %r14d,%r12d
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %r13,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @getSpeed(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = load i32, i32* %5
%20 = call i32 @memset(i8* %18, i32 255, i32 %19)
%21 = load i8*, i8** %7
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 0, i8* %25
%26 = call i64 (...) @usec()
store i64 %26, i64* %8
store i32 0, i32* %5
br label %27
27: ; preds = %35, %3
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i32, i32* %4
%33 = load i8*, i8** %7
%34 = call i64 @sendMessage(i32 %32, i8* %33)
store i64 %34, i64* %9
br label %35
35: ; preds = %31
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %27
38: ; preds = %27
%39 = call i64 (...) @usec()
store i64 %39, i64* %10
%40 = load i64, i64* %10
%41 = sitofp i64 %40 to double
%42 = load i64, i64* %8
%43 = sitofp i64 %42 to double
%44 = fmul double %43, 1.000000e+00
%45 = fneg double %44
%46 = call double @llvm.fmuladd.f64(double %41, double 1.000000e+00, double %45)
%47 = fdiv double %46, 1.000000e+06
store double %47, double* %11
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = mul nsw i32 %48, %49
%51 = sitofp i32 %50 to double
%52 = load double, double* %11
%53 = fdiv double %51, %52
store double %53, double* %12
%54 = load i8*, i8** %7
%55 = call i32 @free(i8* %54)
%56 = load double, double* %12
ret double %56
}

LLVM IR (-O2):
define double @getSpeed(i32 %0, i32 %1, i32 %2) {
%4 = tail call i8* @malloc(i32 %1)
%5 = tail call i32 @memset(i8* %4, i32 255, i32 %1)
%6 = add nsw i32 %1, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
store i8 0, i8* %8
%9 = tail call i64 (...) @usec()
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %16
11: ; preds = %3, %11
%12 = phi i32 [ %14, %11 ], [ 0, %3 ]
%13 = tail call i64 @sendMessage(i32 %0, i8* %4)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, %2
br i1 %15, label %16, label %11
16: ; preds = %11, %3
%17 = phi i32 [ 0, %3 ], [ %2, %11 ]
%18 = tail call i64 (...) @usec()
%19 = sitofp i64 %18 to double
%20 = sitofp i64 %9 to double
%21 = fsub double %19, %20
%22 = fdiv double %21, 1.000000e+06
%23 = mul nsw i32 %17, %2
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, %22
%26 = tail call i32 @free(i8* %4)
ret double %25
}