#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 */

/* Variables and functions */
int /*<<< orphan*/ pmu_counter_enable();
int /*<<< orphan*/ pmu_counter_read_ns(unsigned long long *);
int /*<<< orphan*/ pmu_counter_reset();
float pmu_getres_ns();
int /*<<< orphan*/ pmu_init_ns(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  printf("Hello World!!\r\n");
  pmu_init_ns(800, 1);
  pmu_counter_enable();
  float pmu_res = pmu_getres_ns();
  printf("PMU is used like timer with the following characteristics\n\r");
  printf("PMU cycle counter resolution is %f ns\n\r", pmu_res);
  int seconds = 0;
  unsigned long long pmu_counter_ns;
  pmu_counter_reset();
  printf("%d\n\r", seconds);
  while (seconds < 61) {
    pmu_counter_read_ns(&pmu_counter_ns);
    if (pmu_counter_ns > 1000000000) {
      pmu_counter_reset();
      seconds++;
      printf("%d\n\r", seconds);
    }
  }
  printf("The end...\n\r");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x320,%edi
mov    $0x1,%esi
call   1040 <pmu_init_ns@plt>
mov    $0x0,%al
call   1030 <pmu_counter_enable@plt>
mov    $0x0,%al
call   1080 <pmu_getres_ns@plt>
movss  %xmm0,-0x8(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1060 <pmu_counter_reset@plt>
mov    -0xc(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x3d,-0xc(%rbp)
jge    122a <main+0xca>
lea    -0x18(%rbp),%rdi
call   1070 <pmu_counter_read_ns@plt>
cmpq   $0x3b9aca00,-0x18(%rbp)
3b
jbe    1225 <main+0xc5>
mov    $0x0,%al
call   1060 <pmu_counter_reset@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e3 <main+0x83>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x320,%edi
mov    $0x1,%esi
call   1050 <pmu_init_ns@plt>
xor    %eax,%eax
call   1030 <pmu_counter_enable@plt>
xor    %eax,%eax
call   1090 <pmu_getres_ns@plt>
movss  %xmm0,0x4(%rsp)
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <pmu_counter_reset@plt>
lea    0xe89(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rbx
xor    %ebp,%ebp
jmp    11f5 <main+0x85>
cmp    $0x3d,%ebp
jge    1220 <main+0xb0>
mov    %rbx,%rdi
call   1080 <pmu_counter_read_ns@plt>
cmpq   $0x3b9aca01,0x8(%rsp)
9a 3b
jb     11f0 <main+0x80>
xor    %eax,%eax
call   1070 <pmu_counter_reset@plt>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f0 <main+0x80>
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Hello World!!\0D\0A\00"
@.str.1 = [60 x i8] c"PMU is used like timer with the following characteristics\0A\0D\00"
@.str.2 = [40 x i8] c"PMU cycle counter resolution is %f ns\0A\0D\00"
@.str.3 = [5 x i8] c"%d\0A\0D\00"
@.str.4 = [13 x i8] c"The end...\0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @pmu_init_ns(i32 800, i32 1)
%7 = call i32 (...) @pmu_counter_enable()
%8 = call float (...) @pmu_getres_ns()
store float %8, float* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%10 = load float, float* %2
%11 = fpext float %10 to double
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %11)
store i32 0, i32* %3
%13 = call i32 (...) @pmu_counter_reset()
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %29, %0
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 61
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = call i32 @pmu_counter_read_ns(i64* %4)
%21 = load i64, i64* %4
%22 = icmp ugt i64 %21, 1000000000
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = call i32 (...) @pmu_counter_reset()
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %23, %19
br label %16
30: ; preds = %16
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [60 x i8] c"PMU is used like timer with the following characteristics\0A\0D\00"
@.str.2 = [40 x i8] c"PMU cycle counter resolution is %f ns\0A\0D\00"
@.str.3 = [5 x i8] c"%d\0A\0D\00"
@.str.4 = [13 x i8] c"The end...\0A\0D\00"
@str = [15 x i8] c"Hello World!!\0D\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @pmu_init_ns(i32 800, i32 1)
%4 = tail call i32 (...) @pmu_counter_enable()
%5 = tail call float (...) @pmu_getres_ns()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%7 = fpext float %5 to double
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %7)
%9 = bitcast i64* %1 to i8*
%10 = tail call i32 (...) @pmu_counter_reset()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %12
12: ; preds = %0, %21
%13 = phi i32 [ 0, %0 ], [ %22, %21 ]
%14 = call i32 @pmu_counter_read_ns(i64* %1)
%15 = load i64, i64* %1
%16 = icmp ugt i64 %15, 1000000000
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = call i32 (...) @pmu_counter_reset()
%19 = add nsw i32 %13, 1
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %12
%22 = phi i32 [ %19, %17 ], [ %13, %12 ]
%23 = icmp slt i32 %22, 61
br i1 %23, label %12, label %24
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}