#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 */
double *eye(int);
int /*<<< orphan*/ free(double *);
double *mat(int, int);
int /*<<< orphan*/ matcpy(double *, double const *, int, int);
int matinv(double *, int);
int /*<<< orphan*/ matmul(char *, int, int, int, double, double const *,
                          double const *, double, double *);
int filter_(const double *x, const double *P, const double *H, const double *v,
            const double *R, int n, int m, double *xp, double *Pp) {
  double *F = mat(n, m), *Q = mat(m, m), *K = mat(n, m), *I = eye(n);
  int info;
  matcpy(Q, R, m, m);
  matcpy(xp, x, n, 1);
  matmul("NN", n, m, n, 1.0, P, H, 0.0, F);
  matmul("TN", m, m, n, 1.0, H, F, 1.0, Q);
  if (!(info = matinv(Q, m))) {
    matmul("NN", n, m, m, 1.0, F, Q, 0.0, K);
    matmul("NN", n, 1, m, 1.0, K, v, 1.0, xp);
    matmul("NT", n, n, m, -1.0, K, H, 1.0, I);
    matmul("NN", n, n, n, 1.0, I, P, 0.0, Pp);
  }
  free(F);
  free(Q);
  free(K);
  free(I);
  return info;
}


x86 assembly (clang, -O0):
<filter_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x10(%rbp),%esi
call   1040 <mat@plt>
mov    %rax,-0x38(%rbp)
mov    0x10(%rbp),%edi
mov    0x10(%rbp),%esi
call   1040 <mat@plt>
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x10(%rbp),%esi
call   1040 <mat@plt>
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <eye@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x10(%rbp),%edx
mov    0x10(%rbp),%ecx
call   1080 <matcpy@plt>
mov    0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x1,%ecx
call   1080 <matcpy@plt>
mov    -0x2c(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    0xe08(%rip),%rdi
movsd  0xdf0(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %rax,(%rsp)
call   1070 <matmul@plt>
mov    0x10(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x38(%rbp),%r9
mov    -0x40(%rbp),%rax
lea    0xddb(%rip),%rdi
movsd  0xdc0(%rip),%xmm1
movaps %xmm1,%xmm0
mov    %rax,(%rsp)
call   1070 <matmul@plt>
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1050 <matinv@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jne    132b <filter_+0x1cb>
mov    -0x2c(%rbp),%esi
mov    0x10(%rbp),%edx
mov    0x10(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    -0x48(%rbp),%rax
lea    0xd90(%rip),%rdi
movsd  0xd78(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %rax,(%rsp)
call   1070 <matmul@plt>
mov    -0x2c(%rbp),%esi
mov    0x10(%rbp),%ecx
mov    -0x48(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    0x18(%rbp),%rax
lea    0xd63(%rip),%rdi
mov    $0x1,%edx
movsd  0xd46(%rip),%xmm1
movaps %xmm1,%xmm0
mov    %rax,(%rsp)
call   1070 <matmul@plt>
mov    -0x2c(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    0x10(%rbp),%ecx
mov    -0x48(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x50(%rbp),%rax
lea    0xd34(%rip),%rdi
movsd  0xd1e(%rip),%xmm0
movsd  0xd0e(%rip),%xmm1
mov    %rax,(%rsp)
call   1070 <matmul@plt>
mov    -0x2c(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x50(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    0x20(%rbp),%rax
lea    0xcf9(%rip),%rdi
movsd  0xce1(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %rax,(%rsp)
call   1070 <matmul@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%ebx
mov    %r8,0x10(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,0x18(%rsp)
mov    0x70(%rsp),%ebp
mov    %r9d,%edi
mov    %ebp,%esi
call   1040 <mat@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    %ebp,%esi
call   1040 <mat@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <mat@plt>
mov    %rax,0x28(%rsp)
mov    %ebx,%edi
call   1060 <eye@plt>
mov    %rax,0x20(%rsp)
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    %ebp,%edx
mov    %ebp,%ecx
call   1080 <matcpy@plt>
mov    0x78(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %ebx,%edx
mov    $0x1,%ecx
call   1080 <matcpy@plt>
mov    %r15,(%rsp)
lea    0xe21(%rip),%rdi
movsd  0xe09(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %ebx,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r14,0x18(%rsp)
mov    %r14,%r8
mov    %r13,%r9
call   1070 <matmul@plt>
mov    %r12,(%rsp)
lea    0xdf8(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
movsd  0xdd7(%rip),%xmm0
mov    %r13,0x10(%rsp)
mov    %r13,%r8
mov    %r15,%r9
movaps %xmm0,%xmm1
call   1070 <matmul@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <matinv@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    1314 <filter_+0x1b4>
mov    0x28(%rsp),%r14
mov    %r14,(%rsp)
lea    0xdaf(%rip),%rdi
movsd  0xd97(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %ebx,%esi
mov    %ebp,%edx
mov    %ebp,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1070 <matmul@plt>
mov    0x78(%rsp),%rax
mov    %rax,(%rsp)
lea    0xd83(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %ebp,%ecx
movsd  0xd62(%rip),%xmm0
mov    %r14,%r8
mov    0x30(%rsp),%r9
movaps %xmm0,%xmm1
call   1070 <matmul@plt>
mov    0x20(%rsp),%rax
mov    %rax,(%rsp)
lea    0xd58(%rip),%rdi
movsd  0xd42(%rip),%xmm0
mov    %ebx,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14,%r8
mov    0x10(%rsp),%r9
movsd  0xd24(%rip),%xmm1
call   1070 <matmul@plt>
mov    0x80(%rsp),%rax
mov    %rax,(%rsp)
xorps  %xmm1,%xmm1
lea    0xd19(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %ebx,%ecx
movsd  0xcfb(%rip),%xmm0
mov    0x20(%rsp),%r8
mov    0x18(%rsp),%r9
call   1070 <matmul@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"NN\00"
@.str.1 = [3 x i8] c"TN\00"
@.str.2 = [3 x i8] c"NT\00"
define i32 @filter_(double* %0, double* %1, double* %2, double* %3, double* %4, i32 %5, i32 %6, double* %7, double* %8) {
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
%20 = alloca double*
%21 = alloca double*
%22 = alloca double*
%23 = alloca i32
store double* %0, double** %10
store double* %1, double** %11
store double* %2, double** %12
store double* %3, double** %13
store double* %4, double** %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store double* %7, double** %17
store double* %8, double** %18
%24 = load i32, i32* %15
%25 = load i32, i32* %16
%26 = call double* @mat(i32 %24, i32 %25)
store double* %26, double** %19
%27 = load i32, i32* %16
%28 = load i32, i32* %16
%29 = call double* @mat(i32 %27, i32 %28)
store double* %29, double** %20
%30 = load i32, i32* %15
%31 = load i32, i32* %16
%32 = call double* @mat(i32 %30, i32 %31)
store double* %32, double** %21
%33 = load i32, i32* %15
%34 = call double* @eye(i32 %33)
store double* %34, double** %22
%35 = load double*, double** %20
%36 = load double*, double** %14
%37 = load i32, i32* %16
%38 = load i32, i32* %16
%39 = call i32 @matcpy(double* %35, double* %36, i32 %37, i32 %38)
%40 = load double*, double** %17
%41 = load double*, double** %10
%42 = load i32, i32* %15
%43 = call i32 @matcpy(double* %40, double* %41, i32 %42, i32 1)
%44 = load i32, i32* %15
%45 = load i32, i32* %16
%46 = load i32, i32* %15
%47 = load double*, double** %11
%48 = load double*, double** %12
%49 = load double*, double** %19
%50 = call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %45, i32 %46, double 1.000000e+00, double* %47, double* %48, double 0.000000e+00, double* %49)
%51 = load i32, i32* %16
%52 = load i32, i32* %16
%53 = load i32, i32* %15
%54 = load double*, double** %12
%55 = load double*, double** %19
%56 = load double*, double** %20
%57 = call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %51, i32 %52, i32 %53, double 1.000000e+00, double* %54, double* %55, double 1.000000e+00, double* %56)
%58 = load double*, double** %20
%59 = load i32, i32* %16
%60 = call i32 @matinv(double* %58, i32 %59)
store i32 %60, i32* %23
%61 = icmp ne i32 %60, 0
br i1 %61, label %90, label %62
62: ; preds = %9
%63 = load i32, i32* %15
%64 = load i32, i32* %16
%65 = load i32, i32* %16
%66 = load double*, double** %19
%67 = load double*, double** %20
%68 = load double*, double** %21
%69 = call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %63, i32 %64, i32 %65, double 1.000000e+00, double* %66, double* %67, double 0.000000e+00, double* %68)
%70 = load i32, i32* %15
%71 = load i32, i32* %16
%72 = load double*, double** %21
%73 = load double*, double** %13
%74 = load double*, double** %17
%75 = call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %70, i32 1, i32 %71, double 1.000000e+00, double* %72, double* %73, double 1.000000e+00, double* %74)
%76 = load i32, i32* %15
%77 = load i32, i32* %15
%78 = load i32, i32* %16
%79 = load double*, double** %21
%80 = load double*, double** %12
%81 = load double*, double** %22
%82 = call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %76, i32 %77, i32 %78, double -1.000000e+00, double* %79, double* %80, double 1.000000e+00, double* %81)
%83 = load i32, i32* %15
%84 = load i32, i32* %15
%85 = load i32, i32* %15
%86 = load double*, double** %22
%87 = load double*, double** %11
%88 = load double*, double** %18
%89 = call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %83, i32 %84, i32 %85, double 1.000000e+00, double* %86, double* %87, double 0.000000e+00, double* %88)
br label %90
90: ; preds = %62, %9
%91 = load double*, double** %19
%92 = call i32 @free(double* %91)
%93 = load double*, double** %20
%94 = call i32 @free(double* %93)
%95 = load double*, double** %21
%96 = call i32 @free(double* %95)
%97 = load double*, double** %22
%98 = call i32 @free(double* %97)
%99 = load i32, i32* %23
ret i32 %99
}

LLVM IR (-O2):
@.str = [3 x i8] c"NN\00"
@.str.1 = [3 x i8] c"TN\00"
@.str.2 = [3 x i8] c"NT\00"
define i32 @filter_(double* %0, double* %1, double* %2, double* %3, double* %4, i32 %5, i32 %6, double* %7, double* %8) {
%10 = tail call double* @mat(i32 %5, i32 %6)
%11 = tail call double* @mat(i32 %6, i32 %6)
%12 = tail call double* @mat(i32 %5, i32 %6)
%13 = tail call double* @eye(i32 %5)
%14 = tail call i32 @matcpy(double* %11, double* %4, i32 %6, i32 %6)
%15 = tail call i32 @matcpy(double* %7, double* %0, i32 %5, i32 1)
%16 = tail call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %5, double 1.000000e+00, double* %1, double* %2, double 0.000000e+00, double* %10)
%17 = tail call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %6, i32 %5, double 1.000000e+00, double* %2, double* %10, double 1.000000e+00, double* %11)
%18 = tail call i32 @matinv(double* %11, i32 %6)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %9
%21 = tail call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %6, double 1.000000e+00, double* %10, double* %11, double 0.000000e+00, double* %12)
%22 = tail call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5, i32 1, i32 %6, double 1.000000e+00, double* %12, double* %3, double 1.000000e+00, double* %7)
%23 = tail call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %5, i32 %6, double -1.000000e+00, double* %12, double* %2, double 1.000000e+00, double* %13)
%24 = tail call i32 @matmul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %5, i32 %5, double 1.000000e+00, double* %13, double* %1, double 0.000000e+00, double* %8)
br label %25
25: ; preds = %20, %9
%26 = tail call i32 @free(double* %10)
%27 = tail call i32 @free(double* %11)
%28 = tail call i32 @free(double* %12)
%29 = tail call i32 @free(double* %13)
ret i32 %18
}