#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*/ ksft_print_msg(char *, ...);
scalar_t__ labs(unsigned long);
int show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span) {
  unsigned long avg_bw_imc = 0, avg_bw_resc = 0;
  unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
  int runs, ret, avg_diff_per;
  float avg_diff = 0;
  for (runs = 1; runs < 5; runs++) {
    sum_bw_imc += bw_imc[runs];
    sum_bw_resc += bw_resc[runs];
  }
  avg_bw_imc = sum_bw_imc / 4;
  avg_bw_resc = sum_bw_resc / 4;
  avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc;
  avg_diff_per = (int)(avg_diff * 100);
  ret = avg_diff_per > 5;
  ksft_print_msg("%s Check MBM diff within %d%%\n", ret ? "Fail:" : "Pass:", 5);
  ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per);
  ksft_print_msg("Span (MB): %d\n", span);
  ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc);
  ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc);
  return ret;
}


x86 assembly (clang, -O0):
<show_bw_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
movl   $0x1,-0x3c(%rbp)
cmpl   $0x5,-0x3c(%rbp)
jge    11a2 <show_bw_info+0x82>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1162 <show_bw_info+0x42>
mov    -0x30(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
sub    %rax,%rdi
call   1030 <labs@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x54(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x50(%rbp)
test   %rax,%rax
movss  %xmm0,-0x4c(%rbp)
js     1211 <show_bw_info+0xf1>
movss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x54(%rbp),%xmm0
movss  -0x4c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  0xdd4(%rip),%xmm0
mulss  -0x48(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x5,-0x44(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%ecx
lea    0xdd8(%rip),%rsi
lea    0xdcb(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd9e(%rip),%rdi
mov    $0x5,%edx
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
mov    -0x44(%rbp),%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
mov    -0x14(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
mov    -0x20(%rbp),%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
mov    -0x28(%rbp),%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
mov    -0x40(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_bw_info>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
movdqu 0x8(%rdi),%xmm0
movdqu 0x18(%rdi),%xmm1
paddq  %xmm0,%xmm1
movdqu 0x8(%rsi),%xmm0
movdqu 0x18(%rsi),%xmm2
paddq  %xmm0,%xmm2
pshufd $0xee,%xmm1,%xmm0
paddq  %xmm1,%xmm0
movq   %xmm0,%rbx
pshufd $0xee,%xmm2,%xmm0
paddq  %xmm2,%xmm0
movq   %xmm0,%r14
shr    $0x2,%rbx
shr    $0x2,%r14
mov    %r14,%rax
sub    %rbx,%rax
mov    %rax,%rcx
neg    %rcx
cmovs  %rax,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %rbx,%xmm1
divss  %xmm1,%xmm0
mulss  0xe7c(%rip),%xmm0
cvttss2si %xmm0,%ebp
mov    %edx,%r12d
xor    %r15d,%r15d
cmp    $0x6,%ebp
setge  %r15b
lea    0xe87(%rip),%rax
lea    0xe86(%rip),%rsi
cmovge %rax,%rsi
lea    0xe56(%rip),%rdi
mov    $0x5,%edx
xor    %eax,%eax
call   1030 <ksft_print_msg@plt>
lea    0xe6e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <ksft_print_msg@plt>
lea    0xe72(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <ksft_print_msg@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <ksft_print_msg@plt>
lea    0xe70(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <ksft_print_msg@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"%s Check MBM diff within %d%%\0A\00"
@.str.1 = [6 x i8] c"Fail:\00"
@.str.2 = [6 x i8] c"Pass:\00"
@.str.3 = [20 x i8] c"avg_diff_per: %d%%\0A\00"
@.str.4 = [15 x i8] c"Span (MB): %d\0A\00"
@.str.5 = [17 x i8] c"avg_bw_imc: %lu\0A\00"
@.str.6 = [18 x i8] c"avg_bw_resc: %lu\0A\00"
define i32 @show_bw_info(i64* %0, i64* %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
store i64* %0, i64** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
store float 0.000000e+00, float* %14
store i32 1, i32* %11
br label %15
15: ; preds = %33, %3
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %36
18: ; preds = %15
%19 = load i64*, i64** %4
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i64, i64* %19, i64 %21
%23 = load i64, i64* %22
%24 = load i64, i64* %9
%25 = add i64 %24, %23
store i64 %25, i64* %9
%26 = load i64*, i64** %5
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %26, i64 %28
%30 = load i64, i64* %29
%31 = load i64, i64* %10
%32 = add i64 %31, %30
store i64 %32, i64* %10
br label %33
33: ; preds = %18
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %15
36: ; preds = %15
%37 = load i64, i64* %9
%38 = udiv i64 %37, 4
store i64 %38, i64* %7
%39 = load i64, i64* %10
%40 = udiv i64 %39, 4
store i64 %40, i64* %8
%41 = load i64, i64* %8
%42 = load i64, i64* %7
%43 = sub i64 %41, %42
%44 = call i64 @labs(i64 %43)
%45 = sitofp i64 %44 to float
%46 = load i64, i64* %7
%47 = uitofp i64 %46 to float
%48 = fdiv float %45, %47
store float %48, float* %14
%49 = load float, float* %14
%50 = fmul float %49, 1.000000e+02
%51 = fptosi float %50 to i32
store i32 %51, i32* %13
%52 = load i32, i32* %13
%53 = icmp sgt i32 %52, 5
%54 = zext i1 %53 to i32
store i32 %54, i32* %12
%55 = load i32, i32* %12
%56 = icmp ne i32 %55, 0
%57 = zext i1 %56 to i64
%58 = select i1 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%59 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %58, i32 5)
%60 = load i32, i32* %13
%61 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %6
%63 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%64 = load i64, i64* %7
%65 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 %64)
%66 = load i64, i64* %8
%67 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 %66)
%68 = load i32, i32* %12
ret i32 %68
}

LLVM IR (-O2):
@.str = [31 x i8] c"%s Check MBM diff within %d%%\0A\00"
@.str.1 = [6 x i8] c"Fail:\00"
@.str.2 = [6 x i8] c"Pass:\00"
@.str.3 = [20 x i8] c"avg_diff_per: %d%%\0A\00"
@.str.4 = [15 x i8] c"Span (MB): %d\0A\00"
@.str.5 = [17 x i8] c"avg_bw_imc: %lu\0A\00"
@.str.6 = [18 x i8] c"avg_bw_resc: %lu\0A\00"
define i32 @show_bw_info(i64* nocapture %0, i64* nocapture %1, i32 %2) {
%4 = getelementptr inbounds i64, i64* %0, i64 1
%5 = getelementptr inbounds i64, i64* %1, i64 1
%6 = bitcast i64* %4 to <4 x i64>*
%7 = load <4 x i64>, <4 x i64>* %6
%8 = bitcast i64* %5 to <4 x i64>*
%9 = load <4 x i64>, <4 x i64>* %8
%10 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> %7)
%11 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> %9)
%12 = lshr i64 %10, 2
%13 = lshr i64 %11, 2
%14 = sub nsw i64 %13, %12
%15 = tail call i64 @llvm.abs.i64(i64 %14, i1 true)
%16 = sitofp i64 %15 to float
%17 = uitofp i64 %12 to float
%18 = fdiv float %16, %17
%19 = fmul float %18, 1.000000e+02
%20 = fptosi float %19 to i32
%21 = icmp sgt i32 %20, 5
%22 = zext i1 %21 to i32
%23 = select i1 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%24 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %23, i32 5)
%25 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%26 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %2)
%27 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 %12)
%28 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 %13)
ret i32 %22
}