#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__ calc_ic_column(char const *, size_t, size_t, size_t);
double calc_ic(const char *text, size_t length, size_t width) {
  double total = 0;
  for (size_t offset = 0; offset < width; offset++)
    total += calc_ic_column(text, length, offset, width);
  return total / width;
}


x86 assembly (clang, -O0):
<calc_ic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1177 <calc_ic+0x67>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <calc_ic_column@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1134 <calc_ic+0x24>
movsd  -0x20(%rbp),%xmm0
movaps 0xe7d(%rip),%xmm2
movq   -0x18(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe7c(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_ic>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
test   %rdx,%rdx
je     1162 <calc_ic+0x52>
mov    %rsi,%r14
mov    %rdi,%r15
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1030 <calc_ic_column@plt>
movsd  (%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <calc_ic+0x20>
jmp    1166 <calc_ic+0x56>
xorpd  %xmm0,%xmm0
movq   %r12,%xmm2
punpckldq 0xe8d(%rip),%xmm2
subpd  0xe95(%rip),%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @calc_ic(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store double 0.000000e+00, double* %7
store i64 0, i64* %8
br label %9
9: ; preds = %22, %3
%10 = load i64, i64* %8
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = load i64, i64* %8
%17 = load i64, i64* %6
%18 = call i64 @calc_ic_column(i8* %14, i64 %15, i64 %16, i64 %17)
%19 = sitofp i64 %18 to double
%20 = load double, double* %7
%21 = fadd double %20, %19
store double %21, double* %7
br label %22
22: ; preds = %13
%23 = load i64, i64* %8
%24 = add i64 %23, 1
store i64 %24, i64* %8
br label %9
25: ; preds = %9
%26 = load double, double* %7
%27 = load i64, i64* %6
%28 = uitofp i64 %27 to double
%29 = fdiv double %26, %28
ret double %29
}

LLVM IR (-O2):
define double @calc_ic(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %9
5: ; preds = %9, %3
%6 = phi double [ 0.000000e+00, %3 ], [ %14, %9 ]
%7 = uitofp i64 %2 to double
%8 = fdiv double %6, %7
ret double %8
9: ; preds = %3, %9
%10 = phi i64 [ %15, %9 ], [ 0, %3 ]
%11 = phi double [ %14, %9 ], [ 0.000000e+00, %3 ]
%12 = tail call i64 @calc_ic_column(i8* %0, i64 %1, i64 %10, i64 %2)
%13 = sitofp i64 %12 to double
%14 = fadd double %11, %13
%15 = add nuw i64 %10, 1
%16 = icmp eq i64 %15, %2
br i1 %16, label %5, label %9
}