#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 c_lattice_worker(int, double *, double *, int, double, double);
double cos(double);
scalar_t__ memcpy(void *, void *, int);
int /*<<< orphan*/ posix_memalign(void **, int, int);
double sin(double);
double *c_dwt_worker(int lm, double *ls, int ln, double *xs, int xn) {
  double sin_, cos_;
  double *ds;
  posix_memalign((void **)&ds, 16, xn * sizeof(double));
  if (ln == 0 || xn == 0) {
    return (double *)memcpy((void *)ds, (void *)xs, xn * sizeof(double));
  }
  sin_ = sin(ls[0]);
  cos_ = cos(ls[0]);
  lm = c_lattice_worker(lm, xs, ds, xn, sin_, cos_);
  for (int lnc = 1; lnc < ln; lnc++) {
    sin_ = sin(ls[lnc]);
    cos_ = cos(ls[lnc]);
    lm = c_lattice_worker(lm, ds, ds, xn, sin_, cos_);
  }
  return ds;
}


x86 assembly (clang, -O0):
<c_dwt_worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
lea    -0x48(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
mov    $0x10,%esi
call   1060 <posix_memalign@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1196 <c_dwt_worker+0x46>
cmpl   $0x0,-0x2c(%rbp)
jne    11b6 <c_dwt_worker+0x66>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    1271 <c_dwt_worker+0x121>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1070 <c_lattice_worker@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1269 <c_dwt_worker+0x119>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1070 <c_lattice_worker@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1201 <c_dwt_worker+0xb1>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_dwt_worker>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rsi,%r13
mov    %edi,%ebx
lea    0x0(,%r14,8),%ebp
lea    0x8(%rsp),%rdi
mov    $0x10,%esi
mov    %ebp,%edx
call   1060 <posix_memalign@plt>
test   %r12d,%r12d
je     122b <c_dwt_worker+0xdb>
test   %r14d,%r14d
je     122b <c_dwt_worker+0xdb>
movsd  0x0(%r13),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x0(%r13),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
mov    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%ecx
movsd  0x10(%rsp),%xmm0
call   1070 <c_lattice_worker@plt>
cmp    $0x2,%r12d
jl     1224 <c_dwt_worker+0xd4>
mov    %eax,%ebp
mov    %r12d,%r15d
mov    $0x1,%ebx
xchg   %ax,%ax
movsd  0x0(%r13,%rbx,8),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x0(%r13,%rbx,8),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
mov    0x8(%rsp),%rdx
mov    %ebp,%edi
mov    %rdx,%rsi
mov    %r14d,%ecx
movsd  0x10(%rsp),%xmm0
call   1070 <c_lattice_worker@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <c_dwt_worker+0x90>
mov    0x8(%rsp),%rax
jmp    123a <c_dwt_worker+0xea>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @c_dwt_worker(i32 %0, double* %1, i32 %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double*
%15 = alloca i32
store i32 %0, i32* %7
store double* %1, double** %8
store i32 %2, i32* %9
store double* %3, double** %10
store i32 %4, i32* %11
%16 = bitcast double** %14 to i8**
%17 = load i32, i32* %11
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i32 @posix_memalign(i8** %16, i32 16, i32 %20)
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %5
%25 = load i32, i32* %11
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %24, %5
%28 = load double*, double** %14
%29 = bitcast double* %28 to i8*
%30 = load double*, double** %10
%31 = bitcast double* %30 to i8*
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 8
%35 = trunc i64 %34 to i32
%36 = call i64 @memcpy(i8* %29, i8* %31, i32 %35)
%37 = inttoptr i64 %36 to double*
store double* %37, double** %6
br label %83
38: ; preds = %24
%39 = load double*, double** %8
%40 = getelementptr inbounds double, double* %39, i64 0
%41 = load double, double* %40
%42 = call double @sin(double %41)
store double %42, double* %12
%43 = load double*, double** %8
%44 = getelementptr inbounds double, double* %43, i64 0
%45 = load double, double* %44
%46 = call double @cos(double %45)
store double %46, double* %13
%47 = load i32, i32* %7
%48 = load double*, double** %10
%49 = load double*, double** %14
%50 = load i32, i32* %11
%51 = load double, double* %12
%52 = load double, double* %13
%53 = call i32 @c_lattice_worker(i32 %47, double* %48, double* %49, i32 %50, double %51, double %52)
store i32 %53, i32* %7
store i32 1, i32* %15
br label %54
54: ; preds = %78, %38
%55 = load i32, i32* %15
%56 = load i32, i32* %9
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %81
58: ; preds = %54
%59 = load double*, double** %8
%60 = load i32, i32* %15
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = call double @sin(double %63)
store double %64, double* %12
%65 = load double*, double** %8
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
%70 = call double @cos(double %69)
store double %70, double* %13
%71 = load i32, i32* %7
%72 = load double*, double** %14
%73 = load double*, double** %14
%74 = load i32, i32* %11
%75 = load double, double* %12
%76 = load double, double* %13
%77 = call i32 @c_lattice_worker(i32 %71, double* %72, double* %73, i32 %74, double %75, double %76)
store i32 %77, i32* %7
br label %78
78: ; preds = %58
%79 = load i32, i32* %15
%80 = add nsw i32 %79, 1
store i32 %80, i32* %15
br label %54
81: ; preds = %54
%82 = load double*, double** %14
store double* %82, double** %6
br label %83
83: ; preds = %81, %27
%84 = load double*, double** %6
ret double* %84
}

LLVM IR (-O2):
define double* @c_dwt_worker(i32 %0, double* nocapture %1, i32 %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = bitcast double** %6 to i8*
%8 = bitcast double** %6 to i8**
%9 = shl i32 %4, 3
%10 = call i32 @posix_memalign(i8** %8, i32 16, i32 %9)
%11 = icmp eq i32 %2, 0
%12 = icmp eq i32 %4, 0
%13 = or i1 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %5
%15 = load i8*, i8** %8
%16 = bitcast double* %3 to i8*
%17 = call i64 @memcpy(i8* %15, i8* %16, i32 %9)
%18 = inttoptr i64 %17 to double*
br label %43
19: ; preds = %5
%20 = load double, double* %1
%21 = call double @sin(double %20)
%22 = load double, double* %1
%23 = call double @cos(double %22)
%24 = load double*, double** %6
%25 = call i32 @c_lattice_worker(i32 %0, double* %3, double* %24, i32 %4, double %21, double %23)
%26 = icmp sgt i32 %2, 1
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = zext i32 %2 to i64
br label %31
29: ; preds = %31, %19
%30 = load double*, double** %6
br label %43
31: ; preds = %27, %31
%32 = phi i64 [ 1, %27 ], [ %41, %31 ]
%33 = phi i32 [ %25, %27 ], [ %40, %31 ]
%34 = getelementptr inbounds double, double* %1, i64 %32
%35 = load double, double* %34
%36 = call double @sin(double %35)
%37 = load double, double* %34
%38 = call double @cos(double %37)
%39 = load double*, double** %6
%40 = call i32 @c_lattice_worker(i32 %33, double* %39, double* %39, i32 %4, double %36, double %38)
%41 = add nuw nsw i64 %32, 1
%42 = icmp eq i64 %41, %28
br i1 %42, label %29, label %31
43: ; preds = %29, %14
%44 = phi double* [ %18, %14 ], [ %30, %29 ]
ret double* %44
}