#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 L0(double *, int /*<<< orphan*/ *, int /*<<< orphan*/, int const,
          int const, int);
double fabs(double);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ fwt97_2D(double *, double const *, int const, int const,
                            int);
double *malloc(int const);
double L0_CDF97(const double *x, const double *pr, const double eps,
                const int nx, const int ny, const double flux) {
  double *wav = malloc(nx * ny * sizeof(double));
  fwt97_2D(wav, x, nx, ny, 1);
  for (int i = 0; i < nx * ny; ++i)
    wav[i] = fabs(wav[i]);
  double reg = L0(wav, NULL, 0, nx, ny, 1.);
  free(wav);
  return reg;
}


x86 assembly (clang, -O0):
<L0_CDF97>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    $0x1,%r8d
call   1040 <fwt97_2D@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    11dd <L0_CDF97+0x9d>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe42(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1198 <L0_CDF97+0x58>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
mov    $0x1,%r9d
call   1060 <L0@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<L0_CDF97>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%r12
mov    %ecx,%ebp
imul   %edx,%ebp
lea    0x0(,%rbp,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    $0x1,%r8d
call   1040 <fwt97_2D@plt>
test   %ebp,%ebp
jle    1255 <L0_CDF97+0x115>
mov    %ebp,%eax
cmp    $0x4,%ebp
jae    1196 <L0_CDF97+0x56>
xor    %ecx,%ecx
jmp    1236 <L0_CDF97+0xf6>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
test   %rdx,%rdx
je     128e <L0_CDF97+0x14e>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %edx,%edx
movaps 0xe3d(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups (%rbx,%rdx,8),%xmm1
movups 0x10(%rbx,%rdx,8),%xmm2
movups 0x20(%rbx,%rdx,8),%xmm3
movups 0x30(%rbx,%rdx,8),%xmm4
andps  %xmm0,%xmm1
andps  %xmm0,%xmm2
movups %xmm1,(%rbx,%rdx,8)
movups %xmm2,0x10(%rbx,%rdx,8)
andps  %xmm0,%xmm3
andps  %xmm0,%xmm4
movups %xmm3,0x20(%rbx,%rdx,8)
movups %xmm4,0x30(%rbx,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rdi
jne    11d0 <L0_CDF97+0x90>
test   $0x1,%sil
je     1231 <L0_CDF97+0xf1>
movups (%rbx,%rdx,8),%xmm0
movups 0x10(%rbx,%rdx,8),%xmm1
movaps 0xdde(%rip),%xmm2
andps  %xmm2,%xmm0
andps  %xmm2,%xmm1
movups %xmm0,(%rbx,%rdx,8)
movups %xmm1,0x10(%rbx,%rdx,8)
cmp    %rax,%rcx
je     1255 <L0_CDF97+0x115>
movaps 0xdc3(%rip),%xmm0
nopl   (%rax)
movsd  (%rbx,%rcx,8),%xmm1
andps  %xmm0,%xmm1
movlps %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1240 <L0_CDF97+0x100>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
mov    $0x1,%r9d
call   1060 <L0@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edx,%edx
test   $0x1,%sil
jne    1212 <L0_CDF97+0xd2>
jmp    1231 <L0_CDF97+0xf1>

LLVM IR (-O0):
define double @L0_CDF97(double* %0, double* %1, double %2, i32 %3, i32 %4, double %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double*
%14 = alloca i32
%15 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store double %2, double* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double %5, double* %12
%16 = load i32, i32* %10
%17 = load i32, i32* %11
%18 = mul nsw i32 %16, %17
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call double* @malloc(i32 %21)
store double* %22, double** %13
%23 = load double*, double** %13
%24 = load double*, double** %7
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = call i32 @fwt97_2D(double* %23, double* %24, i32 %25, i32 %26, i32 1)
store i32 0, i32* %14
br label %28
28: ; preds = %45, %6
%29 = load i32, i32* %14
%30 = load i32, i32* %10
%31 = load i32, i32* %11
%32 = mul nsw i32 %30, %31
%33 = icmp slt i32 %29, %32
br i1 %33, label %34, label %48
34: ; preds = %28
%35 = load double*, double** %13
%36 = load i32, i32* %14
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = call double @llvm.fabs.f64(double %39)
%41 = load double*, double** %13
%42 = load i32, i32* %14
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double %40, double* %44
br label %45
45: ; preds = %34
%46 = load i32, i32* %14
%47 = add nsw i32 %46, 1
store i32 %47, i32* %14
br label %28
48: ; preds = %28
%49 = load double*, double** %13
%50 = load i32, i32* %10
%51 = load i32, i32* %11
%52 = call double @L0(double* %49, i32* null, i32 0, i32 %50, i32 %51, i32 1)
store double %52, double* %15
%53 = load double*, double** %13
%54 = call i32 @free(double* %53)
%55 = load double, double* %15
ret double %55
}

LLVM IR (-O2):
define double @L0_CDF97(double* %0, double* nocapture readnone %1, double %2, i32 %3, i32 %4, double %5) {
%7 = mul nsw i32 %4, %3
%8 = shl i32 %7, 3
%9 = tail call double* @malloc(i32 %8)
%10 = tail call i32 @fwt97_2D(double* %9, double* %0, i32 %3, i32 %4, i32 1)
%11 = icmp sgt i32 %7, 0
br i1 %11, label %12, label %69
12: ; preds = %6
%13 = zext i32 %7 to i64
%14 = icmp ult i32 %7, 4
br i1 %14, label %67, label %15
15: ; preds = %12
%16 = and i64 %13, 4294967292
%17 = add nsw i64 %16, -4
%18 = lshr exact i64 %17, 2
%19 = add nuw nsw i64 %18, 1
%20 = and i64 %19, 1
%21 = icmp eq i64 %17, 0
br i1 %21, label %51, label %22
22: ; preds = %15
%23 = and i64 %19, 9223372036854775806
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %48, %24 ]
%26 = phi i64 [ 0, %22 ], [ %49, %24 ]
%27 = getelementptr inbounds double, double* %9, i64 %25
%28 = bitcast double* %27 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = getelementptr inbounds double, double* %27, i64 2
%31 = bitcast double* %30 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %29)
%34 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %32)
%35 = bitcast double* %27 to <2 x double>*
store <2 x double> %33, <2 x double>* %35
%36 = bitcast double* %30 to <2 x double>*
store <2 x double> %34, <2 x double>* %36
%37 = or i64 %25, 4
%38 = getelementptr inbounds double, double* %9, i64 %37
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = getelementptr inbounds double, double* %38, i64 2
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %40)
%45 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %43)
%46 = bitcast double* %38 to <2 x double>*
store <2 x double> %44, <2 x double>* %46
%47 = bitcast double* %41 to <2 x double>*
store <2 x double> %45, <2 x double>* %47
%48 = add nuw i64 %25, 8
%49 = add i64 %26, 2
%50 = icmp eq i64 %49, %23
br i1 %50, label %51, label %24
51: ; preds = %24, %15
%52 = phi i64 [ 0, %15 ], [ %48, %24 ]
%53 = icmp eq i64 %20, 0
br i1 %53, label %65, label %54
54: ; preds = %51
%55 = getelementptr inbounds double, double* %9, i64 %52
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %55, i64 2
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %57)
%62 = call <2 x double> @llvm.fabs.v2f64(<2 x double> %60)
%63 = bitcast double* %55 to <2 x double>*
store <2 x double> %61, <2 x double>* %63
%64 = bitcast double* %58 to <2 x double>*
store <2 x double> %62, <2 x double>* %64
br label %65
65: ; preds = %51, %54
%66 = icmp eq i64 %16, %13
br i1 %66, label %69, label %67
67: ; preds = %12, %65
%68 = phi i64 [ 0, %12 ], [ %16, %65 ]
br label %72
69: ; preds = %72, %65, %6
%70 = tail call double @L0(double* %9, i32* null, i32 0, i32 %3, i32 %4, i32 1)
%71 = tail call i32 @free(double* %9)
ret double %70
72: ; preds = %67, %72
%73 = phi i64 [ %77, %72 ], [ %68, %67 ]
%74 = getelementptr inbounds double, double* %9, i64 %73
%75 = load double, double* %74
%76 = tail call double @llvm.fabs.f64(double %75)
store double %76, double* %74
%77 = add nuw nsw i64 %73, 1
%78 = icmp eq i64 %77, %13
br i1 %78, label %69, label %72
}