#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*/ abort();
int /*<<< orphan*/ compute_mean_and_vari_from_hist(int, unsigned long *,
                                                   double *, double *);
int /*<<< orphan*/ printf(char *, int, int, int, char const *, double, double);
int /*<<< orphan*/ puts(char *);
void test(const char *what, int (*pfun)(void)) {
  unsigned long histogram[32 * 2 + 1] = {0};
  for (unsigned long pass = 0; pass < 1222333; ++pass) {
    int hd = pfun();
    if (0 <= hd && hd <= (32 * 2)) {
      histogram[hd]++;
    } else {
      puts("unexpected output difference, internal error");
      abort();
    }
  }
  double m, v;
  compute_mean_and_vari_from_hist(32 * 2 + 1, histogram, &m, &v);
  printf("Speck-%d-%d [nr=%d], %s test: mean=%f, variance=%f\n", 2 * 32,
         (144 / 32) * 32, (23 + (144 / 32)), what, m, v);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x208,%edx
call   1060 <memset@plt>
movq   $0x0,-0x228(%rbp)
cmpq   $0x12a6bd,-0x228(%rbp)
jae    1205 <test+0xb5>
call   *-0x10(%rbp)
mov    %eax,-0x22c(%rbp)
xor    %eax,%eax
cmp    -0x22c(%rbp),%eax
jg     11d6 <test+0x86>
cmpl   $0x40,-0x22c(%rbp)
jg     11d6 <test+0x86>
movslq -0x22c(%rbp),%rax
mov    -0x220(%rbp,%rax,8),%rcx
ff
add    $0x1,%rcx
mov    %rcx,-0x220(%rbp,%rax,8)
ff
jmp    11e9 <test+0x99>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11ee <test+0x9e>
mov    -0x228(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x228(%rbp)
jmp    1181 <test+0x31>
lea    -0x220(%rbp),%rsi
mov    $0x41,%edi
lea    -0x238(%rbp),%rdx
lea    -0x240(%rbp),%rcx
call   1070 <compute_mean_and_vari_from_hist@plt>
mov    -0x8(%rbp),%r8
movsd  -0x238(%rbp),%xmm0
ff
movsd  -0x240(%rbp),%xmm1
ff
lea    0xdee(%rip),%rdi
mov    $0x40,%esi
mov    $0x80,%edx
mov    $0x1b,%ecx
call   1050 <printf@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %rbx
sub    $0x220,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
mov    $0x208,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x12a6bd,%ebx
nopl   0x0(%rax,%rax,1)
call   *%r15
cmp    $0x40,%eax
ja     11e3 <test+0x93>
mov    %eax,%eax
addq   $0x1,0x10(%rsp,%rax,8)
add    $0xffffffffffffffff,%rbx
jne    1180 <test+0x30>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
mov    $0x41,%edi
call   1070 <compute_mean_and_vari_from_hist@plt>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
lea    0xe6e(%rip),%rdi
mov    $0x40,%esi
mov    $0x80,%edx
mov    $0x1b,%ecx
mov    %r14,%r8
call   1050 <printf@plt>
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"unexpected output difference, internal error\00"
@.str.1 = [52 x i8] c"Speck-%d-%d [nr=%d], %s test: mean=%f, variance=%f\0A\00"
define void @test(i8* %0, i32 ()* %1) {
%3 = alloca i8*
%4 = alloca i32 ()*
%5 = alloca [65 x i64]
%6 = alloca i64
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store i8* %0, i8** %3
store i32 ()* %1, i32 ()** %4
%10 = bitcast [65 x i64]* %5 to i8*
store i64 0, i64* %6
br label %11
11: ; preds = %32, %2
%12 = load i64, i64* %6
%13 = icmp ult i64 %12, 1222333
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = load i32 ()*, i32 ()** %4
%16 = call i32 %15()
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp sle i32 0, %17
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = load i32, i32* %7
%21 = icmp sle i32 %20, 64
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [65 x i64], [65 x i64]* %5, i64 0, i64 %24
%26 = load i64, i64* %25
%27 = add i64 %26, 1
store i64 %27, i64* %25
br label %31
28: ; preds = %19, %14
%29 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i64, i64* %6
%34 = add i64 %33, 1
store i64 %34, i64* %6
br label %11
35: ; preds = %11
%36 = getelementptr inbounds [65 x i64], [65 x i64]* %5, i64 0, i64 0
%37 = call i32 @compute_mean_and_vari_from_hist(i32 65, i64* %36, double* %8, double* %9)
%38 = load i8*, i8** %3
%39 = load double, double* %8
%40 = load double, double* %9
%41 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 64, i32 128, i32 27, i8* %38, double %39, double %40)
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"unexpected output difference, internal error\00"
@.str.1 = [52 x i8] c"Speck-%d-%d [nr=%d], %s test: mean=%f, variance=%f\0A\00"
define void @test(i8* %0, i32 ()* nocapture %1) {
%3 = alloca [65 x i64]
%4 = alloca double
%5 = alloca double
%6 = bitcast [65 x i64]* %3 to i8*
br label %15
7: ; preds = %19
%8 = bitcast double* %4 to i8*
%9 = bitcast double* %5 to i8*
%10 = getelementptr inbounds [65 x i64], [65 x i64]* %3, i64 0, i64 0
%11 = call i32 @compute_mean_and_vari_from_hist(i32 65, i64* %10, double* %4, double* %5)
%12 = load double, double* %4
%13 = load double, double* %5
%14 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 64, i32 128, i32 27, i8* %0, double %12, double %13)
ret void
15: ; preds = %2, %19
%16 = phi i64 [ 0, %2 ], [ %24, %19 ]
%17 = tail call i32 %1()
%18 = icmp ult i32 %17, 65
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = zext i32 %17 to i64
%21 = getelementptr inbounds [65 x i64], [65 x i64]* %3, i64 0, i64 %20
%22 = load i64, i64* %21
%23 = add i64 %22, 1
store i64 %23, i64* %21
%24 = add nuw nsw i64 %16, 1
%25 = icmp eq i64 %24, 1222333
br i1 %25, label %7, label %15
26: ; preds = %15
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 (...) @abort()
unreachable
}