#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 fabs(double);
int rf3(double *array_ext, int nr, double *array_out) {
  double a[512], ampl, mean;
  int index, j, cNr, tot_num;
  tot_num = nr;
  for (index = 0; index < nr * 3; index++) {
    array_out[index] = 0.0;
  }
  j = -1;
  cNr = 1;
  for (index = 0; index < tot_num; index++) {
    a[++j] = *array_ext++;
    while ((j >= 2) && (fabs(a[j - 1] - a[j - 2]) <= fabs(a[j] - a[j - 1]))) {
      ampl = fabs((a[j - 1] - a[j - 2]) / 2);
      switch (j) {
      case 0: {
        break;
      }
      case 1: {
        break;
      }
      case 2: {
        mean = (a[0] + a[1]) / 2;
        a[0] = a[1];
        a[1] = a[2];
        j = 1;
        if (ampl > 0) {
          *array_out++ = ampl;
          *array_out++ = mean;
          *array_out++ = 0.50;
        }
        break;
      }
      default: {
        mean = (a[j - 1] + a[j - 2]) / 2;
        a[j - 2] = a[j];
        j = j - 2;
        if (ampl > 0) {
          *array_out++ = ampl;
          *array_out++ = mean;
          *array_out++ = 1.00;
          cNr++;
        }
        break;
      }
      }
    }
  }
  for (index = 0; index < j; index++) {
    ampl = fabs(a[index] - a[index + 1]) / 2;
    mean = (a[index] + a[index + 1]) / 2;
    if (ampl > 0) {
      *array_out++ = ampl;
      *array_out++ = mean;
      *array_out++ = 0.50;
    }
  }
  return (tot_num - 1 - cNr);
}


x86 assembly (clang, -O0):
<rf3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1040(%rbp)
movl   $0x0,-0x1034(%rbp)
mov    -0x1034(%rbp),%eax
imul   $0x3,-0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    1172 <rf3+0x62>
mov    -0x18(%rbp),%rax
movslq -0x1034(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1034(%rbp)
jmp    1139 <rf3+0x29>
movl   $0xffffffff,-0x1038(%rbp)
ff ff ff
movl   $0x1,-0x103c(%rbp)
movl   $0x0,-0x1034(%rbp)
mov    -0x1034(%rbp),%eax
cmp    -0x1040(%rbp),%eax
jge    14b7 <rf3+0x3a7>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  (%rax),%xmm0
mov    -0x1038(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1038(%rbp)
cltq
movsd  %xmm0,-0x1020(%rbp,%rax,8)
ff ff
xor    %eax,%eax
cmpl   $0x2,-0x1038(%rbp)
mov    %al,-0x1041(%rbp)
jl     1253 <rf3+0x143>
mov    -0x1038(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
mov    -0x1038(%rbp),%eax
sub    $0x2,%eax
cltq
subsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
call   1030 <fabs@plt>
mov    %eax,-0x1048(%rbp)
movslq -0x1038(%rbp),%rax
movsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
mov    -0x1038(%rbp),%eax
sub    $0x1,%eax
cltq
subsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x1048(%rbp),%eax
cmp    %ecx,%eax
setle  %al
mov    %al,-0x1041(%rbp)
mov    -0x1041(%rbp),%al
test   $0x1,%al
jne    1266 <rf3+0x156>
jmp    149e <rf3+0x38e>
mov    -0x1038(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movsd  -0x1020(%rbp,%rcx,8),%xmm0
ff ff
add    $0xfffffffe,%eax
cltq
movsd  -0x1020(%rbp,%rax,8),%xmm1
ff ff
subsd  %xmm1,%xmm0
movsd  0xd69(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x1028(%rbp)
ff
mov    -0x1038(%rbp),%eax
mov    %eax,-0x104c(%rbp)
test   %eax,%eax
je     12ed <rf3+0x1dd>
jmp    12c5 <rf3+0x1b5>
mov    -0x104c(%rbp),%eax
sub    $0x1,%eax
je     12f2 <rf3+0x1e2>
jmp    12d9 <rf3+0x1c9>
mov    -0x104c(%rbp),%eax
sub    $0x2,%eax
je     12f7 <rf3+0x1e7>
jmp    13b0 <rf3+0x2a0>
jmp    1499 <rf3+0x389>
jmp    1499 <rf3+0x389>
movsd  -0x1020(%rbp),%xmm0
ff
addsd  -0x1018(%rbp),%xmm0
ff
movsd  0xcf1(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1030(%rbp)
ff
movsd  -0x1018(%rbp),%xmm0
ff
movsd  %xmm0,-0x1020(%rbp)
ff
movsd  -0x1010(%rbp),%xmm0
ff
movsd  %xmm0,-0x1018(%rbp)
ff
movl   $0x1,-0x1038(%rbp)
movsd  -0x1028(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    13ab <rf3+0x29b>
movsd  -0x1028(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x1030(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  0xc61(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    1499 <rf3+0x389>
mov    -0x1038(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
mov    -0x1038(%rbp),%eax
sub    $0x2,%eax
cltq
addsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
movsd  0xc20(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1030(%rbp)
ff
movslq -0x1038(%rbp),%rax
movsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
mov    -0x1038(%rbp),%eax
sub    $0x2,%eax
cltq
movsd  %xmm0,-0x1020(%rbp,%rax,8)
ff ff
mov    -0x1038(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1038(%rbp)
movsd  -0x1028(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1494 <rf3+0x384>
movsd  -0x1028(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x1030(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  0xb8f(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x103c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x103c(%rbp)
jmp    1499 <rf3+0x389>
jmp    11cf <rf3+0xbf>
jmp    14a3 <rf3+0x393>
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1034(%rbp)
jmp    1190 <rf3+0x80>
movl   $0x0,-0x1034(%rbp)
mov    -0x1034(%rbp),%eax
cmp    -0x1038(%rbp),%eax
jge    15c7 <rf3+0x4b7>
movslq -0x1034(%rbp),%rax
movsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
cltq
subsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
call   1030 <fabs@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x1028(%rbp)
ff
movslq -0x1034(%rbp),%rax
movsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
cltq
addsd  -0x1020(%rbp,%rax,8),%xmm0
ff ff
movsd  0xac4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1030(%rbp)
ff
movsd  -0x1028(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    15ae <rf3+0x49e>
movsd  -0x1028(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x1030(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  0xa5e(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    15b3 <rf3+0x4a3>
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1034(%rbp)
jmp    14c1 <rf3+0x3b1>
mov    -0x1040(%rbp),%eax
sub    $0x1,%eax
sub    -0x103c(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rf3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1048,%rsp
mov    %esi,%r15d
test   %esi,%esi
jle    13a5 <rf3+0x285>
mov    %rdx,%rbx
lea    (%r15,%r15,2),%edx
cmp    $0x2,%edx
mov    %rdi,%rbp
mov    $0x1,%eax
movl   $0x1,0xc(%rsp)
cmovl  %eax,%edx
shl    $0x3,%rdx
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbp,%rax
mov    $0xffffffff,%r12d
mov    %r15,0x20(%rsp)
jmp    119a <rf3+0x7a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12d
mov    0x10(%rsp),%rax
add    $0x8,%rax
add    $0x1,%r13d
cmp    %r15d,%r13d
je     1320 <rf3+0x200>
mov    %rax,0x10(%rsp)
movsd  (%rax),%xmm0
movslq %r12d,%rax
movsd  %xmm0,0x48(%rsp,%rax,8)
test   %r12d,%r12d
jle    1180 <rf3+0x60>
lea    -0x1(%r12),%eax
lea    (%rsp,%rax,8),%r15
add    $0x40,%r15
jmp    11da <rf3+0xba>
lea    -0x2(%r12),%eax
add    $0xffffffff,%r12d
add    $0xfffffffffffffff0,%r15
cmp    $0x1,%r12d
mov    %eax,%r12d
jbe    1310 <rf3+0x1f0>
lea    0x1(%r12),%r14d
mov    %r12d,%eax
movsd  0x40(%rsp,%rax,8),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  (%r15),%xmm1
movsd  %xmm1,0x30(%rsp)
subsd  %xmm1,%xmm0
movsd  %xmm0,0x28(%rsp)
call   1040 <fabs@plt>
mov    %eax,%ebp
movsd  0x40(%rsp,%r14,8),%xmm0
movsd  %xmm0,0x38(%rsp)
subsd  0x18(%rsp),%xmm0
call   1040 <fabs@plt>
cmp    %eax,%ebp
jg     12a0 <rf3+0x180>
movsd  0x28(%rsp),%xmm0
mulsd  0xdcc(%rip),%xmm0
call   1040 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
cmp    $0x1,%r12d
je     12b0 <rf3+0x190>
movsd  0x38(%rsp),%xmm1
movsd  %xmm1,(%r15)
test   %eax,%eax
jle    11c0 <rf3+0xa0>
movsd  0x18(%rsp),%xmm1
addsd  0x30(%rsp),%xmm1
mulsd  0xd93(%rip),%xmm1
movsd  %xmm0,(%rbx)
movsd  %xmm1,0x8(%rbx)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%rbx)
add    $0x18,%rbx
addl   $0x1,0xc(%rsp)
jmp    11c0 <rf3+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%r12d
jmp    1316 <rf3+0x1f6>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x40(%rsp),%xmm1
movupd 0x48(%rsp),%xmm2
movapd %xmm2,0x40(%rsp)
mov    $0x1,%r12d
test   %eax,%eax
mov    0x20(%rsp),%r15
jle    1184 <rf3+0x64>
addsd  %xmm2,%xmm1
mulsd  0xd1f(%rip),%xmm1
movsd  %xmm0,(%rbx)
movsd  %xmm1,0x8(%rbx)
movabs $0x3fe0000000000000,%rax
mov    %rax,0x10(%rbx)
add    $0x18,%rbx
jmp    1184 <rf3+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r12d
mov    0x20(%rsp),%r15
jmp    1184 <rf3+0x64>
test   %r12d,%r12d
jle    139f <rf3+0x27f>
mov    %r12d,%r14d
xor    %ebp,%ebp
movabs $0x3fe0000000000000,%r12
jmp    1345 <rf3+0x225>
cs nopw 0x0(%rax,%rax,1)
cmp    %rbp,%r14
je     139f <rf3+0x27f>
movsd  0x40(%rsp,%rbp,8),%xmm0
movsd  0x48(%rsp,%rbp,8),%xmm1
add    $0x1,%rbp
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x28(%rsp)
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
cmp    $0x2,%eax
jl     1340 <rf3+0x220>
shr    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x18(%rsp),%xmm1
addsd  0x28(%rsp),%xmm1
mulsd  0xc74(%rip),%xmm1
movsd  %xmm0,(%rbx)
movsd  %xmm1,0x8(%rbx)
mov    %r12,0x10(%rbx)
add    $0x18,%rbx
jmp    1340 <rf3+0x220>
mov    0xc(%rsp),%eax
jmp    13aa <rf3+0x28a>
mov    $0x1,%eax
not    %eax
add    %r15d,%eax
add    $0x1048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rf3(double* %0, i32 %1, double* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double*
%7 = alloca [512 x double]
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double* %2, double** %6
%14 = load i32, i32* %5
store i32 %14, i32* %13
store i32 0, i32* %10
br label %15
15: ; preds = %25, %3
%16 = load i32, i32* %10
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 3
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load double*, double** %6
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
store double 0.000000e+00, double* %24
br label %25
25: ; preds = %20
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
br label %15
28: ; preds = %15
store i32 -1, i32* %11
store i32 1, i32* %12
store i32 0, i32* %10
br label %29
29: ; preds = %153, %28
%30 = load i32, i32* %10
%31 = load i32, i32* %13
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %156
33: ; preds = %29
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i32 1
store double* %35, double** %4
%36 = load double, double* %34
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %39
store double %36, double* %40
br label %41
41: ; preds = %151, %33
%42 = load i32, i32* %11
%43 = icmp sge i32 %42, 2
br i1 %43, label %44, label %69
44: ; preds = %41
%45 = load i32, i32* %11
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %47
%49 = load double, double* %48
%50 = load i32, i32* %11
%51 = sub nsw i32 %50, 2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %52
%54 = load double, double* %53
%55 = fsub double %49, %54
%56 = call i32 @fabs(double %55)
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %58
%60 = load double, double* %59
%61 = load i32, i32* %11
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %63
%65 = load double, double* %64
%66 = fsub double %60, %65
%67 = call i32 @fabs(double %66)
%68 = icmp sle i32 %56, %67
br label %69
69: ; preds = %44, %41
%70 = phi i1 [ false, %41 ], [ %68, %44 ]
br i1 %70, label %71, label %152
71: ; preds = %69
%72 = load i32, i32* %11
%73 = sub nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %74
%76 = load double, double* %75
%77 = load i32, i32* %11
%78 = sub nsw i32 %77, 2
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %79
%81 = load double, double* %80
%82 = fsub double %76, %81
%83 = fdiv double %82, 2.000000e+00
%84 = call i32 @fabs(double %83)
%85 = sitofp i32 %84 to double
store double %85, double* %8
%86 = load i32, i32* %11
switch i32 %86, label %114 [
i32 0, label %87
i32 1, label %88
i32 2, label %89
]
87: ; preds = %71
br label %151
88: ; preds = %71
br label %151
89: ; preds = %71
%90 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 0
%91 = load double, double* %90
%92 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 1
%93 = load double, double* %92
%94 = fadd double %91, %93
%95 = fdiv double %94, 2.000000e+00
store double %95, double* %9
%96 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 1
%97 = load double, double* %96
%98 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 0
store double %97, double* %98
%99 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 2
%100 = load double, double* %99
%101 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 1
store double %100, double* %101
store i32 1, i32* %11
%102 = load double, double* %8
%103 = fcmp ogt double %102, 0.000000e+00
br i1 %103, label %104, label %113
104: ; preds = %89
%105 = load double, double* %8
%106 = load double*, double** %6
%107 = getelementptr inbounds double, double* %106, i32 1
store double* %107, double** %6
store double %105, double* %106
%108 = load double, double* %9
%109 = load double*, double** %6
%110 = getelementptr inbounds double, double* %109, i32 1
store double* %110, double** %6
store double %108, double* %109
%111 = load double*, double** %6
%112 = getelementptr inbounds double, double* %111, i32 1
store double* %112, double** %6
store double 5.000000e-01, double* %111
br label %113
113: ; preds = %104, %89
br label %151
114: ; preds = %71
%115 = load i32, i32* %11
%116 = sub nsw i32 %115, 1
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %117
%119 = load double, double* %118
%120 = load i32, i32* %11
%121 = sub nsw i32 %120, 2
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %122
%124 = load double, double* %123
%125 = fadd double %119, %124
%126 = fdiv double %125, 2.000000e+00
store double %126, double* %9
%127 = load i32, i32* %11
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %128
%130 = load double, double* %129
%131 = load i32, i32* %11
%132 = sub nsw i32 %131, 2
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %133
store double %130, double* %134
%135 = load i32, i32* %11
%136 = sub nsw i32 %135, 2
store i32 %136, i32* %11
%137 = load double, double* %8
%138 = fcmp ogt double %137, 0.000000e+00
br i1 %138, label %139, label %150
139: ; preds = %114
%140 = load double, double* %8
%141 = load double*, double** %6
%142 = getelementptr inbounds double, double* %141, i32 1
store double* %142, double** %6
store double %140, double* %141
%143 = load double, double* %9
%144 = load double*, double** %6
%145 = getelementptr inbounds double, double* %144, i32 1
store double* %145, double** %6
store double %143, double* %144
%146 = load double*, double** %6
%147 = getelementptr inbounds double, double* %146, i32 1
store double* %147, double** %6
store double 1.000000e+00, double* %146
%148 = load i32, i32* %12
%149 = add nsw i32 %148, 1
store i32 %149, i32* %12
br label %150
150: ; preds = %139, %114
br label %151
151: ; preds = %150, %113, %88, %87
br label %41
152: ; preds = %69
br label %153
153: ; preds = %152
%154 = load i32, i32* %10
%155 = add nsw i32 %154, 1
store i32 %155, i32* %10
br label %29
156: ; preds = %29
store i32 0, i32* %10
br label %157
157: ; preds = %198, %156
%158 = load i32, i32* %10
%159 = load i32, i32* %11
%160 = icmp slt i32 %158, %159
br i1 %160, label %161, label %201
161: ; preds = %157
%162 = load i32, i32* %10
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %163
%165 = load double, double* %164
%166 = load i32, i32* %10
%167 = add nsw i32 %166, 1
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %168
%170 = load double, double* %169
%171 = fsub double %165, %170
%172 = call i32 @fabs(double %171)
%173 = sdiv i32 %172, 2
%174 = sitofp i32 %173 to double
store double %174, double* %8
%175 = load i32, i32* %10
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %176
%178 = load double, double* %177
%179 = load i32, i32* %10
%180 = add nsw i32 %179, 1
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds [512 x double], [512 x double]* %7, i64 0, i64 %181
%183 = load double, double* %182
%184 = fadd double %178, %183
%185 = fdiv double %184, 2.000000e+00
store double %185, double* %9
%186 = load double, double* %8
%187 = fcmp ogt double %186, 0.000000e+00
br i1 %187, label %188, label %197
188: ; preds = %161
%189 = load double, double* %8
%190 = load double*, double** %6
%191 = getelementptr inbounds double, double* %190, i32 1
store double* %191, double** %6
store double %189, double* %190
%192 = load double, double* %9
%193 = load double*, double** %6
%194 = getelementptr inbounds double, double* %193, i32 1
store double* %194, double** %6
store double %192, double* %193
%195 = load double*, double** %6
%196 = getelementptr inbounds double, double* %195, i32 1
store double* %196, double** %6
store double 5.000000e-01, double* %195
br label %197
197: ; preds = %188, %161
br label %198
198: ; preds = %197
%199 = load i32, i32* %10
%200 = add nsw i32 %199, 1
store i32 %200, i32* %10
br label %157
201: ; preds = %157
%202 = load i32, i32* %13
%203 = sub nsw i32 %202, 1
%204 = load i32, i32* %12
%205 = sub nsw i32 %203, %204
ret i32 %205
}

LLVM IR (-O2):
define i32 @rf3(double* nocapture %0, i32 %1, double* nocapture writeonly %2) {
%4 = alloca [512 x double]
%5 = bitcast [512 x double]* %4 to i8*
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %110
7: ; preds = %3
%8 = mul i32 %1, 3
%9 = bitcast double* %2 to i8*
%10 = call i32 @llvm.smax.i32(i32 %8, i32 1)
%11 = zext i32 %10 to i64
%12 = shl nuw nsw i64 %11, 3
%13 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 0
%14 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 1
%15 = bitcast double* %14 to <2 x double>*
%16 = bitcast [512 x double]* %4 to <2 x double>*
br label %21
17: ; preds = %82
%18 = icmp sgt i32 %84, 0
br i1 %18, label %19, label %110
19: ; preds = %17
%20 = zext i32 %84 to i64
br label %88
21: ; preds = %7, %82
%22 = phi double* [ %0, %7 ], [ %27, %82 ]
%23 = phi i32 [ 1, %7 ], [ %85, %82 ]
%24 = phi i32 [ -1, %7 ], [ %84, %82 ]
%25 = phi i32 [ 0, %7 ], [ %86, %82 ]
%26 = phi double* [ %2, %7 ], [ %83, %82 ]
%27 = getelementptr inbounds double, double* %22, i64 1
%28 = load double, double* %22
%29 = add nsw i32 %24, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 %30
store double %28, double* %31
%32 = icmp sgt i32 %24, 0
br i1 %32, label %33, label %82
33: ; preds = %21, %78
%34 = phi i32 [ %80, %78 ], [ %23, %21 ]
%35 = phi i32 [ %41, %78 ], [ %29, %21 ]
%36 = phi double* [ %79, %78 ], [ %26, %21 ]
%37 = add nsw i32 %35, -1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 %38
%40 = load double, double* %39
%41 = add nsw i32 %35, -2
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 %42
%44 = load double, double* %43
%45 = fsub double %40, %44
%46 = tail call i32 @fabs(double %45)
%47 = zext i32 %35 to i64
%48 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 %47
%49 = load double, double* %48
%50 = fsub double %49, %40
%51 = tail call i32 @fabs(double %50)
%52 = icmp sgt i32 %46, %51
br i1 %52, label %82, label %53
53: ; preds = %33
%54 = fmul double %45, 5.000000e-01
%55 = tail call i32 @fabs(double %54)
%56 = sitofp i32 %55 to double
%57 = icmp eq i32 %35, 2
br i1 %57, label %58, label %69
58: ; preds = %53
%59 = load double, double* %13
%60 = load <2 x double>, <2 x double>* %15
store <2 x double> %60, <2 x double>* %16
%61 = icmp sgt i32 %55, 0
br i1 %61, label %62, label %82
62: ; preds = %58
%63 = extractelement <2 x double> %60, i64 0
%64 = fadd double %59, %63
%65 = fmul double %64, 5.000000e-01
%66 = getelementptr inbounds double, double* %36, i64 1
store double %56, double* %36
%67 = getelementptr inbounds double, double* %36, i64 2
store double %65, double* %66
%68 = getelementptr inbounds double, double* %36, i64 3
store double 5.000000e-01, double* %67
br label %82
69: ; preds = %53
store double %49, double* %43
%70 = icmp sgt i32 %55, 0
br i1 %70, label %71, label %78
71: ; preds = %69
%72 = fadd double %40, %44
%73 = fmul double %72, 5.000000e-01
%74 = getelementptr inbounds double, double* %36, i64 1
store double %56, double* %36
%75 = getelementptr inbounds double, double* %36, i64 2
store double %73, double* %74
%76 = getelementptr inbounds double, double* %36, i64 3
store double 1.000000e+00, double* %75
%77 = add nsw i32 %34, 1
br label %78
78: ; preds = %69, %71
%79 = phi double* [ %76, %71 ], [ %36, %69 ]
%80 = phi i32 [ %77, %71 ], [ %34, %69 ]
%81 = icmp ugt i32 %41, 1
br i1 %81, label %33, label %82
82: ; preds = %78, %33, %58, %62, %21
%83 = phi double* [ %26, %21 ], [ %36, %58 ], [ %68, %62 ], [ %36, %33 ], [ %79, %78 ]
%84 = phi i32 [ %29, %21 ], [ 1, %58 ], [ 1, %62 ], [ %35, %33 ], [ 1, %78 ]
%85 = phi i32 [ %23, %21 ], [ %34, %58 ], [ %34, %62 ], [ %34, %33 ], [ %80, %78 ]
%86 = add nuw nsw i32 %25, 1
%87 = icmp eq i32 %86, %1
br i1 %87, label %17, label %21
88: ; preds = %19, %107
%89 = phi i64 [ 0, %19 ], [ %93, %107 ]
%90 = phi double* [ %83, %19 ], [ %108, %107 ]
%91 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 %89
%92 = load double, double* %91
%93 = add nuw nsw i64 %89, 1
%94 = getelementptr inbounds [512 x double], [512 x double]* %4, i64 0, i64 %93
%95 = load double, double* %94
%96 = fsub double %92, %95
%97 = tail call i32 @fabs(double %96)
%98 = icmp sgt i32 %97, 1
br i1 %98, label %99, label %107
99: ; preds = %88
%100 = lshr i32 %97, 1
%101 = sitofp i32 %100 to double
%102 = fadd double %92, %95
%103 = fmul double %102, 5.000000e-01
%104 = getelementptr inbounds double, double* %90, i64 1
store double %101, double* %90
%105 = getelementptr inbounds double, double* %90, i64 2
store double %103, double* %104
%106 = getelementptr inbounds double, double* %90, i64 3
store double 5.000000e-01, double* %105
br label %107
107: ; preds = %88, %99
%108 = phi double* [ %106, %99 ], [ %90, %88 ]
%109 = icmp eq i64 %93, %20
br i1 %109, label %110, label %88
110: ; preds = %107, %3, %17
%111 = phi i32 [ %85, %17 ], [ 1, %3 ], [ %85, %107 ]
%112 = xor i32 %111, -1
%113 = add i32 %112, %1
ret i32 %113
}