#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *const);
scalar_t__ feof(int /*<<< orphan*/ *const);
double fmin(double, double);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(double *, int, int, int /*<<< orphan*/ *const);
size_t sqrt(size_t);
double c_corr_trunc(const char f_name[]) {
  FILE *const pf = fopen(f_name, "rb");
  assert(pf != NULL);
  double sx = 0, sxx = 0, sy = 0, syy = 0, sxy = 0;
  size_t n = 0;
  while (1) {
    double x, y;
    if (fread(&x, sizeof(double), 1, pf) != 1 ||
        fread(&y, sizeof(double), 1, pf) != 1 || feof(pf)) {
      fclose(pf);
      break;
    }
    x = fmin(x, 0.25);
    y = fmin(x, 0.25);
    sx += x;
    sxx += x * x;
    sy += y;
    sxy += x * y;
    syy += y * y;
    ++n;
  }
  return (n * sxy - sx * sy) / sqrt(n * sxx - sx * sx) /
         sqrt(n * syy - sy * sy);
}


x86 assembly (clang, -O0):
<c_corr_trunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x48(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1218 <c_corr_trunc+0xb8>
mov    -0x10(%rbp),%rcx
lea    -0x50(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1218 <c_corr_trunc+0xb8>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1226 <c_corr_trunc+0xc6>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12d5 <c_corr_trunc+0x175>
movsd  -0x48(%rbp),%xmm0
movsd  0xdcd(%rip),%xmm1
minsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xdb7(%rip),%xmm1
minsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11c5 <c_corr_trunc+0x65>
movq   -0x40(%rbp),%xmm0
movaps 0xd2f(%rip),%xmm1
movaps %xmm1,-0x80(%rbp)
punpckldq %xmm1,%xmm0
movapd 0xd2f(%rip),%xmm1
movaps %xmm1,-0x70(%rbp)
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm4
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movaps %xmm1,%xmm3
mulsd  %xmm2,%xmm3
movaps %xmm0,%xmm2
mulsd  %xmm4,%xmm2
subsd  %xmm3,%xmm2
movsd  %xmm2,-0x90(%rbp)
ff
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm1,%xmm1
mulsd  %xmm2,%xmm0
subsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
mov    %rdi,%rcx
sar    $0x3f,%rcx
movsd  0xcb3(%rip),%xmm1
movsd  %xmm1,-0x88(%rbp)
ff
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rcx,%rax
or     %rax,%rdi
call   1080 <sqrt@plt>
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x88(%rbp),%xmm1
ff
movaps -0x80(%rbp),%xmm3
movaps -0x70(%rbp),%xmm2
movq   %rax,%xmm4
punpckldq %xmm3,%xmm4
subpd  %xmm2,%xmm4
movaps %xmm4,%xmm5
unpckhpd %xmm4,%xmm4
addsd  %xmm5,%xmm4
divsd  %xmm4,%xmm0
movsd  %xmm0,-0x58(%rbp)
movq   -0x40(%rbp),%xmm0
punpckldq %xmm3,%xmm0
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  -0x30(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm3,%xmm0
subsd  %xmm2,%xmm0
movaps %xmm0,%xmm2
cvttsd2si %xmm2,%rdi
mov    %rdi,%rcx
sar    $0x3f,%rcx
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rcx,%rax
or     %rax,%rdi
call   1080 <sqrt@plt>
movaps -0x80(%rbp),%xmm3
movaps -0x70(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm0
movq   %rax,%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_corr_trunc>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xebe(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0x38(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
xorpd  %xmm0,%xmm0
cmp    $0x1,%eax
jne    1289 <c_corr_trunc+0x129>
movapd %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
lea    0x50(%rsp),%r14
lea    0x38(%rsp),%r15
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    12af <c_corr_trunc+0x14f>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    12af <c_corr_trunc+0x14f>
movsd  0x38(%rsp),%xmm0
minsd  0xde3(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
unpcklpd %xmm0,%xmm0
movapd 0x20(%rsp),%xmm1
addpd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
add    $0x1,%rbx
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11e0 <c_corr_trunc+0x80>
jmp    12af <c_corr_trunc+0x14f>
movapd %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r12,%rdi
call   1040 <fclose@plt>
movq   %rbx,%xmm0
punpckldq 0xd4c(%rip),%xmm0
subpd  0xd54(%rip),%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movapd %xmm3,0x40(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm2
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm2
movapd %xmm3,%xmm1
mulsd  0x20(%rsp),%xmm1
subsd  %xmm2,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm3,%xmm2
cvttsd2si %xmm1,%rax
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xce0(%rip),%xmm1
cvttsd2si %xmm1,%rdi
and    %rcx,%rdi
or     %rax,%rdi
call   1080 <sqrt@plt>
movq   %rax,%xmm0
punpckldq 0xccb(%rip),%xmm0
subpd  0xcd3(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movapd 0x20(%rsp),%xmm1
unpckhpd %xmm1,%xmm1
mulsd  0x40(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xc6d(%rip),%xmm1
cvttsd2si %xmm1,%rdi
and    %rcx,%rdi
or     %rax,%rdi
call   1080 <sqrt@plt>
movq   %rax,%xmm0
punpckldq 0xc58(%rip),%xmm0
subpd  0xc60(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define double @c_corr_trunc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca double
%11 = alloca double
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i64 0, i64* %9
br label %18
18: ; preds = %1, %33
%19 = load i32*, i32** %3
%20 = call i32 @fread(double* %10, i32 8, i32 1, i32* %19)
%21 = icmp ne i32 %20, 1
br i1 %21, label %30, label %22
22: ; preds = %18
%23 = load i32*, i32** %3
%24 = call i32 @fread(double* %11, i32 8, i32 1, i32* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32*, i32** %3
%28 = call i64 @feof(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26, %22, %18
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
br label %58
33: ; preds = %26
%34 = load double, double* %10
%35 = call double @llvm.minnum.f64(double %34, double 2.500000e-01)
store double %35, double* %10
%36 = load double, double* %10
%37 = call double @llvm.minnum.f64(double %36, double 2.500000e-01)
store double %37, double* %11
%38 = load double, double* %10
%39 = load double, double* %4
%40 = fadd double %39, %38
store double %40, double* %4
%41 = load double, double* %10
%42 = load double, double* %10
%43 = load double, double* %5
%44 = call double @llvm.fmuladd.f64(double %41, double %42, double %43)
store double %44, double* %5
%45 = load double, double* %11
%46 = load double, double* %6
%47 = fadd double %46, %45
store double %47, double* %6
%48 = load double, double* %10
%49 = load double, double* %11
%50 = load double, double* %8
%51 = call double @llvm.fmuladd.f64(double %48, double %49, double %50)
store double %51, double* %8
%52 = load double, double* %11
%53 = load double, double* %11
%54 = load double, double* %7
%55 = call double @llvm.fmuladd.f64(double %52, double %53, double %54)
store double %55, double* %7
%56 = load i64, i64* %9
%57 = add i64 %56, 1
store i64 %57, i64* %9
br label %18
58: ; preds = %30
%59 = load i64, i64* %9
%60 = uitofp i64 %59 to double
%61 = load double, double* %8
%62 = load double, double* %4
%63 = load double, double* %6
%64 = fmul double %62, %63
%65 = fneg double %64
%66 = call double @llvm.fmuladd.f64(double %60, double %61, double %65)
%67 = load i64, i64* %9
%68 = uitofp i64 %67 to double
%69 = load double, double* %5
%70 = load double, double* %4
%71 = load double, double* %4
%72 = fmul double %70, %71
%73 = fneg double %72
%74 = call double @llvm.fmuladd.f64(double %68, double %69, double %73)
%75 = fptoui double %74 to i64
%76 = call i64 @sqrt(i64 %75)
%77 = uitofp i64 %76 to double
%78 = fdiv double %66, %77
%79 = load i64, i64* %9
%80 = uitofp i64 %79 to double
%81 = load double, double* %7
%82 = load double, double* %6
%83 = load double, double* %6
%84 = fmul double %82, %83
%85 = fneg double %84
%86 = call double @llvm.fmuladd.f64(double %80, double %81, double %85)
%87 = fptoui double %86 to i64
%88 = call i64 @sqrt(i64 %87)
%89 = uitofp i64 %88 to double
%90 = fdiv double %78, %89
ret double %90
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define double @c_corr_trunc(i8* nocapture %0) {
%2 = alloca double
%3 = alloca double
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i32* %4, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = bitcast double* %2 to i8*
%9 = bitcast double* %3 to i8*
%10 = call i32 @fread(double* %2, i32 8, i32 1, i32* %4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %35
12: ; preds = %1, %23
%13 = phi i64 [ %32, %23 ], [ 0, %1 ]
%14 = phi double [ %28, %23 ], [ 0.000000e+00, %1 ]
%15 = phi double [ %27, %23 ], [ 0.000000e+00, %1 ]
%16 = phi double [ %26, %23 ], [ 0.000000e+00, %1 ]
%17 = phi <2 x double> [ %31, %23 ], [ zeroinitializer, %1 ]
%18 = call i32 @fread(double* %3, i32 8, i32 1, i32* %4)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %35
20: ; preds = %12
%21 = tail call i64 @feof(i32* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = load double, double* %2
%25 = tail call double @llvm.minnum.f64(double %24, double 2.500000e-01)
%26 = fadd double %16, %25
%27 = fadd double %15, %25
%28 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %14)
%29 = insertelement <2 x double> poison, double %25, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %30, <2 x double> %17)
%32 = add i64 %13, 1
%33 = call i32 @fread(double* %2, i32 8, i32 1, i32* %4)
%34 = icmp eq i32 %33, 1
br i1 %34, label %12, label %35
35: ; preds = %20, %12, %23, %1
%36 = phi double [ 0.000000e+00, %1 ], [ %26, %23 ], [ %16, %12 ], [ %16, %20 ]
%37 = phi double [ 0.000000e+00, %1 ], [ %27, %23 ], [ %15, %12 ], [ %15, %20 ]
%38 = phi double [ 0.000000e+00, %1 ], [ %28, %23 ], [ %14, %12 ], [ %14, %20 ]
%39 = phi i64 [ 0, %1 ], [ %32, %23 ], [ %13, %12 ], [ %13, %20 ]
%40 = phi <2 x double> [ zeroinitializer, %1 ], [ %31, %23 ], [ %17, %12 ], [ %17, %20 ]
%41 = tail call i32 @fclose(i32* %4)
%42 = uitofp i64 %39 to double
%43 = fneg double %36
%44 = fmul double %37, %43
%45 = tail call double @llvm.fmuladd.f64(double %42, double %38, double %44)
%46 = fmul double %36, %43
%47 = extractelement <2 x double> %40, i64 0
%48 = tail call double @llvm.fmuladd.f64(double %42, double %47, double %46)
%49 = fptoui double %48 to i64
%50 = tail call i64 @sqrt(i64 %49)
%51 = uitofp i64 %50 to double
%52 = fdiv double %45, %51
%53 = fneg double %37
%54 = fmul double %37, %53
%55 = extractelement <2 x double> %40, i64 1
%56 = tail call double @llvm.fmuladd.f64(double %42, double %55, double %54)
%57 = fptoui double %56 to i64
%58 = tail call i64 @sqrt(i64 %57)
%59 = uitofp i64 %58 to double
%60 = fdiv double %52, %59
ret double %60
}