#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 /*<<< orphan*/ 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 /*<<< orphan*/);
int /*<<< orphan*/ pru_read(int, int /*<<< orphan*/ *, int);
int main() {
  int size[5] = {1000, 0, 0, 0, 0};
  pru_bridge_init(size);
  pru_channel_open(1, 0);
  int i = 0;
  clock_t t1, t2;
  int pru_data;
  while (i < 1000) {
    t1 = clock();
    pru_read(1, (uint8_t *)(&pru_data), 4);
    printf("%d\n", pru_data);
    i++;
    t2 = clock();
    double diff = ((double)(t2 - t1)) / CLOCKS_PER_SEC;
    printf("%f\n", diff);
  }
  pru_channel_close(1);
  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   1070 <pru_bridge_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <pru_channel_open@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    122d <main+0xcd>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    $0x1,%edi
lea    -0x3c(%rbp),%rsi
mov    $0x4,%edx
call   1080 <pru_read@plt>
cvtsi2sdl -0x3c(%rbp),%xmm0
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dda(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xdf5(%rip),%rdi
call   1050 <printf@plt>
jmp    11aa <main+0x4a>
mov    $0x1,%edi
call   1040 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0xe9c(%rip),%eax
mov    %eax,0x20(%rsp)
movapd 0xe80(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1070 <pru_bridge_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <pru_channel_open@plt>
mov    $0x3e8,%ebp
lea    0xc(%rsp),%r14
lea    0xe67(%rip),%r15
mov    0x2e34(%rip),%r13
lea    0xe5d(%rip),%r12
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <pru_read@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
mov    %r15,%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
mov    %r12,%rdi
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x60>
mov    $0x1,%edi
call   1040 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.size = [5 x i32] [i32 1000, i32 0, i32 0, i32 0, i32 0]
@.str = [4 x i8] c"%d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [4 x i8] c"%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 i32
%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)
store i32 0, i32* %3
br label %12
12: ; preds = %15, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = call i64 (...) @clock()
store i64 %16, i64* %4
%17 = call i32 @pru_read(i32 1, i32* %6, i32 4)
%18 = load i32, i32* %6
%19 = sitofp i32 %18 to double
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %19)
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%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 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %30)
br label %12
32: ; preds = %12
%33 = call i32 @pru_channel_close(i32 1)
ret i32 0
}

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