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


x86 assembly (clang, -O0):
<L0_ATROUS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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)
movl   $0x4,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    $0x4,%r8d
call   1040 <atrous_fwd@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
imul   -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    11ea <L0_ATROUS+0xaa>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe35(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a2 <L0_ATROUS+0x62>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
mov    -0x20(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
mov    $0x1,%r9d
call   1060 <L0@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<L0_ATROUS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %rdi,%r12
lea    0x0(,%r13,4),%r14d
mov    %r14d,%ebx
imul   %ecx,%ebx
lea    0x0(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
mov    $0x4,%r8d
call   1040 <atrous_fwd@plt>
test   %ebx,%ebx
jle    1224 <L0_ATROUS+0xe4>
mov    %ebx,%eax
add    $0xfffffffffffffffc,%rax
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
test   %rax,%rax
je     125d <L0_ATROUS+0x11d>
mov    %rcx,%rdx
and    $0xfffffffffffffffe,%rdx
xor    %eax,%eax
movaps 0xe46(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movups 0x0(%rbp,%rax,8),%xmm1
movups 0x10(%rbp,%rax,8),%xmm2
movups 0x20(%rbp,%rax,8),%xmm3
movups 0x30(%rbp,%rax,8),%xmm4
andps  %xmm0,%xmm1
andps  %xmm0,%xmm2
movups %xmm1,0x0(%rbp,%rax,8)
movups %xmm2,0x10(%rbp,%rax,8)
andps  %xmm0,%xmm3
andps  %xmm0,%xmm4
movups %xmm3,0x20(%rbp,%rax,8)
movups %xmm4,0x30(%rbp,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rdx
jne    11c0 <L0_ATROUS+0x80>
test   $0x1,%cl
je     1224 <L0_ATROUS+0xe4>
movups 0x0(%rbp,%rax,8),%xmm0
movups 0x10(%rbp,%rax,8),%xmm1
movaps 0xdec(%rip),%xmm2
andps  %xmm2,%xmm0
andps  %xmm2,%xmm1
movups %xmm0,0x0(%rbp,%rax,8)
movups %xmm1,0x10(%rbp,%rax,8)
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    $0x1,%r9d
call   1060 <L0@plt>
movsd  %xmm0,(%rsp)
mov    %rbp,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
test   $0x1,%cl
jne    1203 <L0_ATROUS+0xc3>
jmp    1224 <L0_ATROUS+0xe4>

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

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