#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 /*<<< orphan*/ conv(double *, int, double *, int, double *, int);
int /*<<< orphan*/ dyaddown_1D_keep_even(double *, int, double *, int);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ wkeep_1D_center(double *, int, double *, int);
void dwt_nex(double *sigIn, int sigInLength, double *lowDe, double *hiDe,
             int filterLen, double *approx, double *detail, int sigOutLength) {
  int sigOutLengthTemp, sigOutLengthPre;
  double *approxTemp, *approxPre;
  double *detailTemp, *detailPre;
  sigOutLengthTemp = sigInLength + filterLen - 1;
  approxTemp = malloc(sigOutLengthTemp * sizeof(double));
  conv(sigIn, sigInLength, approxTemp, sigOutLengthTemp, lowDe, filterLen);
  sigOutLengthPre = sigOutLengthTemp / 2;
  approxPre = malloc(sigOutLengthPre * sizeof(double));
  dyaddown_1D_keep_even(approxTemp, sigOutLengthTemp, approxPre,
                        sigOutLengthPre);
  wkeep_1D_center(approxPre, sigOutLengthPre, approx, sigOutLength);
  free(approxPre);
  free(approxTemp);
  detailTemp = malloc(sigOutLengthTemp * sizeof(double));
  conv(sigIn, sigInLength, detailTemp, sigOutLengthTemp, hiDe, filterLen);
  detailPre = malloc(sigOutLengthPre * sizeof(double));
  dyaddown_1D_keep_even(detailTemp, sigOutLengthTemp, detailPre,
                        sigOutLengthPre);
  wkeep_1D_center(detailPre, sigOutLengthPre, detail, sigOutLength);
  free(detailPre);
  free(detailTemp);
  return;
}


x86 assembly (clang, -O0):
<dwt_nex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1050 <conv@plt>
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x38(%rbp),%ecx
call   1070 <dyaddown_1D_keep_even@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    0x18(%rbp),%ecx
call   1040 <wkeep_1D_center@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1050 <conv@plt>
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x58(%rbp),%rdx
mov    -0x38(%rbp),%ecx
call   1070 <dyaddown_1D_keep_even@plt>
mov    -0x58(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%ecx
call   1040 <wkeep_1D_center@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dwt_nex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x20(%rsp)
mov    %r8d,%ebp
mov    %rcx,0x28(%rsp)
mov    %rdx,0x8(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdi,0x18(%rsp)
mov    0x70(%rsp),%rax
mov    %rax,0x30(%rsp)
mov    0x78(%rsp),%eax
mov    %eax,(%rsp)
lea    (%r14,%rbp,1),%r15d
lea    -0x1(%r14,%rbp,1),%r13d
mov    %rbp,0x10(%rsp)
lea    -0x8(,%r15,8),%edi
ff
mov    %edi,0x4(%rsp)
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
mov    %r13d,%ecx
mov    0x8(%rsp),%r8
mov    %ebp,%r9d
call   1050 <conv@plt>
mov    %r13d,%eax
shr    $0x1f,%eax
add    %eax,%r15d
add    $0xffffffff,%r15d
sar    %r15d
lea    0x0(,%r15,8),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r13d,%esi
mov    %rax,%rdx
mov    %r15d,%ecx
call   1070 <dyaddown_1D_keep_even@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    0x20(%rsp),%rdx
mov    (%rsp),%ecx
call   1040 <wkeep_1D_center@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x18(%rsp),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
mov    %r13d,%ecx
mov    0x28(%rsp),%r8
mov    0x10(%rsp),%r9
call   1050 <conv@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %rax,%rdx
mov    %r15d,%ecx
call   1070 <dyaddown_1D_keep_even@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    0x30(%rsp),%rdx
mov    (%rsp),%ecx
call   1040 <wkeep_1D_center@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @dwt_nex(double* %0, i32 %1, double* %2, double* %3, i32 %4, double* %5, double* %6, i32 %7) {
%9 = alloca double*
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca double*
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double*
%20 = alloca double*
%21 = alloca double*
%22 = alloca double*
store double* %0, double** %9
store i32 %1, i32* %10
store double* %2, double** %11
store double* %3, double** %12
store i32 %4, i32* %13
store double* %5, double** %14
store double* %6, double** %15
store i32 %7, i32* %16
%23 = load i32, i32* %10
%24 = load i32, i32* %13
%25 = add nsw i32 %23, %24
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %17
%27 = load i32, i32* %17
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 8
%30 = trunc i64 %29 to i32
%31 = call double* @malloc(i32 %30)
store double* %31, double** %19
%32 = load double*, double** %9
%33 = load i32, i32* %10
%34 = load double*, double** %19
%35 = load i32, i32* %17
%36 = load double*, double** %11
%37 = load i32, i32* %13
%38 = call i32 @conv(double* %32, i32 %33, double* %34, i32 %35, double* %36, i32 %37)
%39 = load i32, i32* %17
%40 = sdiv i32 %39, 2
store i32 %40, i32* %18
%41 = load i32, i32* %18
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 8
%44 = trunc i64 %43 to i32
%45 = call double* @malloc(i32 %44)
store double* %45, double** %20
%46 = load double*, double** %19
%47 = load i32, i32* %17
%48 = load double*, double** %20
%49 = load i32, i32* %18
%50 = call i32 @dyaddown_1D_keep_even(double* %46, i32 %47, double* %48, i32 %49)
%51 = load double*, double** %20
%52 = load i32, i32* %18
%53 = load double*, double** %14
%54 = load i32, i32* %16
%55 = call i32 @wkeep_1D_center(double* %51, i32 %52, double* %53, i32 %54)
%56 = load double*, double** %20
%57 = call i32 @free(double* %56)
%58 = load double*, double** %19
%59 = call i32 @free(double* %58)
%60 = load i32, i32* %17
%61 = sext i32 %60 to i64
%62 = mul i64 %61, 8
%63 = trunc i64 %62 to i32
%64 = call double* @malloc(i32 %63)
store double* %64, double** %21
%65 = load double*, double** %9
%66 = load i32, i32* %10
%67 = load double*, double** %21
%68 = load i32, i32* %17
%69 = load double*, double** %12
%70 = load i32, i32* %13
%71 = call i32 @conv(double* %65, i32 %66, double* %67, i32 %68, double* %69, i32 %70)
%72 = load i32, i32* %18
%73 = sext i32 %72 to i64
%74 = mul i64 %73, 8
%75 = trunc i64 %74 to i32
%76 = call double* @malloc(i32 %75)
store double* %76, double** %22
%77 = load double*, double** %21
%78 = load i32, i32* %17
%79 = load double*, double** %22
%80 = load i32, i32* %18
%81 = call i32 @dyaddown_1D_keep_even(double* %77, i32 %78, double* %79, i32 %80)
%82 = load double*, double** %22
%83 = load i32, i32* %18
%84 = load double*, double** %15
%85 = load i32, i32* %16
%86 = call i32 @wkeep_1D_center(double* %82, i32 %83, double* %84, i32 %85)
%87 = load double*, double** %22
%88 = call i32 @free(double* %87)
%89 = load double*, double** %21
%90 = call i32 @free(double* %89)
ret void
}

LLVM IR (-O2):
define void @dwt_nex(double* %0, i32 %1, double* %2, double* %3, i32 %4, double* %5, double* %6, i32 %7) {
%9 = add i32 %1, -1
%10 = add i32 %9, %4
%11 = shl i32 %10, 3
%12 = tail call double* @malloc(i32 %11)
%13 = tail call i32 @conv(double* %0, i32 %1, double* %12, i32 %10, double* %2, i32 %4)
%14 = sdiv i32 %10, 2
%15 = shl i32 %14, 3
%16 = tail call double* @malloc(i32 %15)
%17 = tail call i32 @dyaddown_1D_keep_even(double* %12, i32 %10, double* %16, i32 %14)
%18 = tail call i32 @wkeep_1D_center(double* %16, i32 %14, double* %5, i32 %7)
%19 = tail call i32 @free(double* %16)
%20 = tail call i32 @free(double* %12)
%21 = tail call double* @malloc(i32 %11)
%22 = tail call i32 @conv(double* %0, i32 %1, double* %21, i32 %10, double* %3, i32 %4)
%23 = tail call double* @malloc(i32 %15)
%24 = tail call i32 @dyaddown_1D_keep_even(double* %21, i32 %10, double* %23, i32 %14)
%25 = tail call i32 @wkeep_1D_center(double* %23, i32 %14, double* %6, i32 %7)
%26 = tail call i32 @free(double* %23)
%27 = tail call i32 @free(double* %21)
ret void
}