#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 double int64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, double);
void bandwidth_time(double *times, double *results, int64_t maxmem, int scale,
                    long int cur_threads) {
  int i;
  double bandwidth;
  printf("diff=%8.7f ", times[0]);
  for (i = 0; i < 2; i++) {
    bandwidth = ((maxmem / 1024.0) * cur_threads * scale) / times[i];
    bandwidth = bandwidth / 1024.0;
    if (i == 0)
      printf("add = %6.2f MB/sec ", bandwidth);
    if (i == 1)
      printf("triad = %6.2f MB/sec", bandwidth);
    results[i] = bandwidth;
  }
}


x86 assembly (clang, -O0):
<bandwidth_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    11f3 <bandwidth_time+0xe3>
movsd  -0x18(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe6c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11b8 <bandwidth_time+0xa8>
movsd  -0x38(%rbp),%xmm0
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x2c(%rbp)
jne    11d3 <bandwidth_time+0xc3>
movsd  -0x38(%rbp),%xmm0
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1147 <bandwidth_time+0x37>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bandwidth_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,%r15d
movsd  %xmm0,0x8(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbp
movsd  (%rdi),%xmm0
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
movsd  0xebc(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %r15d,%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
divsd  0x0(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%rsp),%xmm0
divsd  0x8(%rbp),%xmm0
mulsd  0xe57(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"diff=%8.7f \00"
@.str.1 = [20 x i8] c"add = %6.2f MB/sec \00"
@.str.2 = [21 x i8] c"triad = %6.2f MB/sec\00"
define void @bandwidth_time(double* %0, double* %1, double %2, i32 %3, i64 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double %2, double* %8
store i32 %3, i32* %9
store i64 %4, i64* %10
%13 = load double*, double** %6
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %15)
store i32 0, i32* %11
br label %17
17: ; preds = %54, %5
%18 = load i32, i32* %11
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %57
20: ; preds = %17
%21 = load double, double* %8
%22 = fdiv double %21, 1.024000e+03
%23 = load i64, i64* %10
%24 = sitofp i64 %23 to double
%25 = fmul double %22, %24
%26 = load i32, i32* %9
%27 = sitofp i32 %26 to double
%28 = fmul double %25, %27
%29 = load double*, double** %6
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = fdiv double %28, %33
store double %34, double* %12
%35 = load double, double* %12
%36 = fdiv double %35, 1.024000e+03
store double %36, double* %12
%37 = load i32, i32* %11
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %20
%40 = load double, double* %12
%41 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %40)
br label %42
42: ; preds = %39, %20
%43 = load i32, i32* %11
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load double, double* %12
%47 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %46)
br label %48
48: ; preds = %45, %42
%49 = load double, double* %12
%50 = load double*, double** %7
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
store double %49, double* %53
br label %54
54: ; preds = %48
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
br label %17
57: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"diff=%8.7f \00"
@.str.1 = [20 x i8] c"add = %6.2f MB/sec \00"
@.str.2 = [21 x i8] c"triad = %6.2f MB/sec\00"
define void @bandwidth_time(double* nocapture %0, double* nocapture writeonly %1, double %2, i32 %3, i64 %4) {
%6 = load double, double* %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %6)
%8 = fmul double %2, 0x3F50000000000000
%9 = sitofp i64 %4 to double
%10 = fmul double %8, %9
%11 = sitofp i32 %3 to double
%12 = fmul double %10, %11
%13 = load double, double* %0
%14 = fdiv double %12, %13
%15 = fmul double %14, 0x3F50000000000000
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %15)
store double %15, double* %1
%17 = getelementptr inbounds double, double* %0, i64 1
%18 = load double, double* %17
%19 = fdiv double %12, %18
%20 = fmul double %19, 0x3F50000000000000
%21 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %20)
%22 = getelementptr inbounds double, double* %1, i64 1
store double %20, double* %22
ret void
}