#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 */
scalar_t__ MemAlloc(int);
double *HistAvg(double *h, int t) {
  double *d;
  int i;
  double acc = 0.0, dt;
  d = (double *)MemAlloc(sizeof(double) * 32768);
  for (i = 0; i < 32768; i++)
    d[i] = 0.0;
  dt = (double)t;
  for (i = 0; i < 32768; i++) {
    if (i > 0 && i % t == 0) {
      d[i - t] = acc / dt;
      acc = h[i];
    } else {
      acc += h[i];
    }
  }
  return d;
}


x86 assembly (clang, -O0):
<HistAvg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x40000,%edi
call   1030 <MemAlloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8000,-0x1c(%rbp)
jge    1167 <HistAvg+0x57>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <HistAvg+0x2c>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8000,-0x1c(%rbp)
jge    11fc <HistAvg+0xec>
cmpl   $0x0,-0x1c(%rbp)
jle    11d2 <HistAvg+0xc2>
mov    -0x1c(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11d2 <HistAvg+0xc2>
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11e9 <HistAvg+0xd9>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11ee <HistAvg+0xde>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <HistAvg+0x68>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HistAvg>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    $0x40000,%edi
call   1040 <MemAlloc@plt>
mov    %rax,%r15
mov    $0x40000,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
cvtsi2sd %ebx,%xmm0
xorpd  %xmm1,%xmm1
addsd  (%r14),%xmm1
movslq %ebx,%rax
shl    $0x3,%rax
mov    %r15,%rsi
sub    %rax,%rsi
mov    $0x1,%ecx
jmp    1183 <HistAvg+0x63>
nopw   0x0(%rax,%rax,1)
addsd  (%r14,%rcx,8),%xmm1
add    $0x1,%rcx
cmp    $0x8000,%rcx
je     119d <HistAvg+0x7d>
mov    %ecx,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    1170 <HistAvg+0x50>
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%rcx,8)
movsd  (%r14,%rcx,8),%xmm1
jmp    1176 <HistAvg+0x56>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @HistAvg(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %7
%9 = call i64 @MemAlloc(i32 262144)
%10 = inttoptr i64 %9 to double*
store double* %10, double** %5
store i32 0, i32* %6
br label %11
11: ; preds = %19, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 32768
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load double*, double** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
store double 0.000000e+00, double* %18
br label %19
19: ; preds = %14
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %11
22: ; preds = %11
%23 = load i32, i32* %4
%24 = sitofp i32 %23 to double
store double %24, double* %8
store i32 0, i32* %6
br label %25
25: ; preds = %60, %22
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 32768
br i1 %27, label %28, label %63
28: ; preds = %25
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %28
%32 = load i32, i32* %6
%33 = load i32, i32* %4
%34 = srem i32 %32, %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %51
36: ; preds = %31
%37 = load double, double* %7
%38 = load double, double* %8
%39 = fdiv double %37, %38
%40 = load double*, double** %5
%41 = load i32, i32* %6
%42 = load i32, i32* %4
%43 = sub nsw i32 %41, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %40, i64 %44
store double %39, double* %45
%46 = load double*, double** %3
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
store double %50, double* %7
br label %59
51: ; preds = %31, %28
%52 = load double*, double** %3
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = load double, double* %7
%58 = fadd double %57, %56
store double %58, double* %7
br label %59
59: ; preds = %51, %36
br label %60
60: ; preds = %59
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %25
63: ; preds = %25
%64 = load double*, double** %5
ret double* %64
}

LLVM IR (-O2):
define double* @HistAvg(double* nocapture %0, i32 %1) {
%3 = tail call i64 @MemAlloc(i32 262144)
%4 = inttoptr i64 %3 to double*
%5 = inttoptr i64 %3 to i8*
%6 = sitofp i32 %1 to double
%7 = sext i32 %1 to i64
%8 = load double, double* %0
%9 = fadd double %8, 0.000000e+00
br label %10
10: ; preds = %26, %2
%11 = phi i64 [ 1, %2 ], [ %28, %26 ]
%12 = phi double [ %9, %2 ], [ %27, %26 ]
%13 = trunc i64 %11 to i32
%14 = srem i32 %13, %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = fdiv double %12, %6
%18 = sub nsw i64 %11, %7
%19 = getelementptr inbounds double, double* %4, i64 %18
store double %17, double* %19
%20 = getelementptr inbounds double, double* %0, i64 %11
%21 = load double, double* %20
br label %26
22: ; preds = %10
%23 = getelementptr inbounds double, double* %0, i64 %11
%24 = load double, double* %23
%25 = fadd double %12, %24
br label %26
26: ; preds = %16, %22
%27 = phi double [ %21, %16 ], [ %25, %22 ]
%28 = add nuw nsw i64 %11, 1
%29 = icmp eq i64 %28, 32768
br i1 %29, label %30, label %10
30: ; preds = %26
ret double* %4
}