#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__ CombinedShannonEntropy(int *, int *, int);
scalar_t__ PredictionCostSpatial(int *, int, double const);
float PredictionCostSpatialHistogram(int accumulated[4][256],
                                     int tile[4][256]) {
  int i;
  double retval = 0;
  for (i = 0; i < 4; ++i) {
    const double kExpValue = 0.94;
    retval += PredictionCostSpatial(tile[i], 1, kExpValue);
    retval += CombinedShannonEntropy(tile[i], accumulated[i], 256);
  }
  return (float)retval;
}


x86 assembly (clang, -O0):
<PredictionCostSpatialHistogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11cb <PredictionCostSpatialHistogram+0xab>
movsd  0xeaf(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0xa,%rax
add    %rax,%rdi
mov    $0x1,%esi
movsd  0xe8e(%rip),%xmm0
call   1040 <PredictionCostSpatial@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0xa,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0xa,%rax
add    %rax,%rsi
mov    $0x100,%edx
call   1030 <CombinedShannonEntropy@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <PredictionCostSpatialHistogram+0x1f>
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PredictionCostSpatialHistogram>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  0xec9(%rip),%xmm0
mov    %rsi,%rdi
mov    $0x1,%esi
call   1040 <PredictionCostSpatial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <CombinedShannonEntropy@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x400(%rbx),%r15
mov    %r15,%rdi
mov    $0x1,%esi
movsd  0xe73(%rip),%xmm0
call   1040 <PredictionCostSpatial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x400(%r14),%rsi
mov    %r15,%rdi
mov    $0x100,%edx
call   1030 <CombinedShannonEntropy@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x800(%rbx),%r15
mov    %r15,%rdi
mov    $0x1,%esi
movsd  0xe1b(%rip),%xmm0
call   1040 <PredictionCostSpatial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x800(%r14),%rsi
mov    %r15,%rdi
mov    $0x100,%edx
call   1030 <CombinedShannonEntropy@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xc00,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
movsd  0xdc3(%rip),%xmm0
call   1040 <PredictionCostSpatial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xc00,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <CombinedShannonEntropy@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float @PredictionCostSpatialHistogram([256 x i32]* %0, [256 x i32]* %1) {
%3 = alloca [256 x i32]*
%4 = alloca [256 x i32]*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store [256 x i32]* %0, [256 x i32]** %3
store [256 x i32]* %1, [256 x i32]** %4
store double 0.000000e+00, double* %6
store i32 0, i32* %5
br label %8
8: ; preds = %35, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %38
11: ; preds = %8
store double 0x3FEE147AE147AE14, double* %7
%12 = load [256 x i32]*, [256 x i32]** %4
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [256 x i32], [256 x i32]* %12, i64 %14
%16 = getelementptr inbounds [256 x i32], [256 x i32]* %15, i64 0, i64 0
%17 = call i64 @PredictionCostSpatial(i32* %16, i32 1, double 0x3FEE147AE147AE14)
%18 = sitofp i64 %17 to double
%19 = load double, double* %6
%20 = fadd double %19, %18
store double %20, double* %6
%21 = load [256 x i32]*, [256 x i32]** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 %23
%25 = getelementptr inbounds [256 x i32], [256 x i32]* %24, i64 0, i64 0
%26 = load [256 x i32]*, [256 x i32]** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i32], [256 x i32]* %26, i64 %28
%30 = getelementptr inbounds [256 x i32], [256 x i32]* %29, i64 0, i64 0
%31 = call i64 @CombinedShannonEntropy(i32* %25, i32* %30, i32 256)
%32 = sitofp i64 %31 to double
%33 = load double, double* %6
%34 = fadd double %33, %32
store double %34, double* %6
br label %35
35: ; preds = %11
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %8
38: ; preds = %8
%39 = load double, double* %6
%40 = fptrunc double %39 to float
ret float %40
}

LLVM IR (-O2):
define float @PredictionCostSpatialHistogram([256 x i32]* %0, [256 x i32]* %1) {
%3 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 0
%4 = tail call i64 @PredictionCostSpatial(i32* %3, i32 1, double 0x3FEE147AE147AE14)
%5 = sitofp i64 %4 to double
%6 = getelementptr inbounds [256 x i32], [256 x i32]* %0, i64 0, i64 0
%7 = tail call i64 @CombinedShannonEntropy(i32* %3, i32* %6, i32 256)
%8 = sitofp i64 %7 to double
%9 = fadd double %5, %8
%10 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 1, i64 0
%11 = tail call i64 @PredictionCostSpatial(i32* %10, i32 1, double 0x3FEE147AE147AE14)
%12 = sitofp i64 %11 to double
%13 = fadd double %9, %12
%14 = getelementptr inbounds [256 x i32], [256 x i32]* %0, i64 1, i64 0
%15 = tail call i64 @CombinedShannonEntropy(i32* %10, i32* %14, i32 256)
%16 = sitofp i64 %15 to double
%17 = fadd double %13, %16
%18 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 2, i64 0
%19 = tail call i64 @PredictionCostSpatial(i32* %18, i32 1, double 0x3FEE147AE147AE14)
%20 = sitofp i64 %19 to double
%21 = fadd double %17, %20
%22 = getelementptr inbounds [256 x i32], [256 x i32]* %0, i64 2, i64 0
%23 = tail call i64 @CombinedShannonEntropy(i32* %18, i32* %22, i32 256)
%24 = sitofp i64 %23 to double
%25 = fadd double %21, %24
%26 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 3, i64 0
%27 = tail call i64 @PredictionCostSpatial(i32* %26, i32 1, double 0x3FEE147AE147AE14)
%28 = sitofp i64 %27 to double
%29 = fadd double %25, %28
%30 = getelementptr inbounds [256 x i32], [256 x i32]* %0, i64 3, i64 0
%31 = tail call i64 @CombinedShannonEntropy(i32* %26, i32* %30, i32 256)
%32 = sitofp i64 %31 to double
%33 = fadd double %29, %32
%34 = fptrunc double %33 to float
ret float %34
}