#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 char uint8_t;
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ pru_bridge_init(int *);
int /*<<< orphan*/ pru_channel_close(int);
int /*<<< orphan*/ pru_channel_open(int, int);
int /*<<< orphan*/ pru_read(int, char *, int);
int /*<<< orphan*/ pru_write(int, char *, int);
int main() {
  int size[5] = {11500, 2, 0, 0, 0};
  pru_bridge_init(size);
  pru_channel_open(1, 0);
  pru_channel_open(2, 1);
  int i = 0;
  clock_t t1, t2;
  uint8_t pru_data = 'a';
  pru_write(2, &pru_data, 1);
  t1 = clock();
  while (i < 11500) {
    pru_read(1, (uint8_t *)(&pru_data), 1);
    i++;
  }
  t2 = clock();
  double diff = ((double)(t2 - t1)) / CLOCKS_PER_SEC;
  printf("Time per byte : %f\n", diff / 11500);
  pru_channel_close(1);
  pru_channel_close(2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe85(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <pru_bridge_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1070 <pru_channel_open@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1070 <pru_channel_open@plt>
movl   $0x0,-0x24(%rbp)
movb   $0x61,-0x39(%rbp)
mov    $0x2,%edi
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
call   1030 <pru_write@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x2cec,-0x24(%rbp)
jge    1216 <main+0xa6>
mov    $0x1,%edx
lea    -0x39(%rbp),%rsi
mov    %edx,%edi
call   1090 <pru_read@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11eb <main+0x7b>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2db3(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xdb5(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdce(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1050 <pru_channel_close@plt>
mov    $0x2,%edi
call   1050 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0xea2(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xe87(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1080 <pru_bridge_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1070 <pru_channel_open@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1070 <pru_channel_open@plt>
movb   $0x61,0xf(%rsp)
lea    0xf(%rsp),%rbx
mov    $0x2,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <pru_write@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    $0x2cec,%ebp
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <pru_read@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x70>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2dd8(%rip),%rax
divsd  (%rax),%xmm0
divsd  0xde4(%rip),%xmm0
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1050 <pru_channel_close@plt>
mov    $0x2,%edi
call   1050 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.size = [5 x i32] [i32 11500, i32 2, i32 0, i32 0, i32 0]
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [20 x i8] c"Time per byte : %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8
%7 = alloca double
store i32 0, i32* %1
%8 = bitcast [5 x i32]* %2 to i8*
%9 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%10 = call i32 @pru_bridge_init(i32* %9)
%11 = call i32 @pru_channel_open(i32 1, i32 0)
%12 = call i32 @pru_channel_open(i32 2, i32 1)
store i32 0, i32* %3
store i8 97, i8* %6
%13 = call i32 @pru_write(i32 2, i8* %6, i32 1)
%14 = call i64 (...) @clock()
store i64 %14, i64* %4
br label %15
15: ; preds = %18, %0
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 11500
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 @pru_read(i32 1, i8* %6, i32 1)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %15
22: ; preds = %15
%23 = call i64 (...) @clock()
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = load i64, i64* %4
%26 = sub nsw i64 %24, %25
%27 = sitofp i64 %26 to double
%28 = load double, double* @CLOCKS_PER_SEC
%29 = fdiv double %27, %28
store double %29, double* %7
%30 = load double, double* %7
%31 = fdiv double %30, 1.150000e+04
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %31)
%33 = call i32 @pru_channel_close(i32 1)
%34 = call i32 @pru_channel_close(i32 2)
ret i32 0
}

LLVM IR (-O2):
@__const.main.size = [5 x i32] [i32 11500, i32 2, i32 0, i32 0, i32 0]
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [20 x i8] c"Time per byte : %f\0A\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = alloca i8
%3 = bitcast [5 x i32]* %1 to i8*
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = call i32 @pru_bridge_init(i32* %4)
%6 = call i32 @pru_channel_open(i32 1, i32 0)
%7 = call i32 @pru_channel_open(i32 2, i32 1)
store i8 97, i8* %2
%8 = call i32 @pru_write(i32 2, i8* %2, i32 1)
%9 = call i64 (...) @clock()
br label %10
10: ; preds = %0, %10
%11 = phi i32 [ 0, %0 ], [ %13, %10 ]
%12 = call i32 @pru_read(i32 1, i8* %2, i32 1)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 11500
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = call i64 (...) @clock()
%17 = sub nsw i64 %16, %9
%18 = sitofp i64 %17 to double
%19 = load double, double* @CLOCKS_PER_SEC
%20 = fdiv double %18, %19
%21 = fdiv double %20, 1.150000e+04
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %21)
%23 = call i32 @pru_channel_close(i32 1)
%24 = call i32 @pru_channel_close(i32 2)
ret i32 0
}