#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 cos(int);
double sin(int);
void shanwavf_packet(double *x, int sigInLength, double *f, int sigOutLength,
                     double ys) {
  int count;
  double con, econ;
  con = 1;
  for (count = 0; count < sigInLength; count++) {
    if (x[count] != 0)
      econ = sin(x[count] * 3.1415926535897931159980) /
             (x[count] * 3.1415926535897931159980);
    else
      econ = 1;
    f[count] = cos(2 * 3.1415926535897931159980 * x[count]) * econ * con / ys;
    f[count + sigInLength] =
        sin(2 * 3.1415926535897931159980 * x[count]) * econ * con / ys;
  }
  return;
}


x86 assembly (clang, -O0):
<shanwavf_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  0xebd(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1255 <shanwavf_packet+0x135>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1180 <shanwavf_packet+0x60>
jp     1180 <shanwavf_packet+0x60>
jmp    11c1 <shanwavf_packet+0xa1>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xe78(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xe5a(%rip),%xmm1
mulsd  (%rax,%rcx,8),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11ce <shanwavf_packet+0xae>
movsd  0xe37(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xe32(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xdf8(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114f <shanwavf_packet+0x2f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shanwavf_packet>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
test   %esi,%esi
jle    1206 <shanwavf_packet+0xe6>
mov    %rdx,%r14
mov    %rdi,%r13
mov    %esi,%r15d
lea    (%rdx,%r15,8),%r12
xor    %ebx,%ebx
jmp    11d9 <shanwavf_packet+0xb9>
nop
movsd  0xeb0(%rip),%xmm1
mulsd  %xmm1,%xmm2
cvttsd2si %xmm2,%edi
call   1030 <sin@plt>
movsd  0x0(%r13,%rbx,8),%xmm2
movapd %xmm2,%xmm1
mulsd  0xe90(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe87(%rip),%xmm1
mulsd  %xmm1,%xmm2
cvttsd2si %xmm2,%edi
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x0(%r13,%rbx,8),%xmm0
mulsd  0xe5a(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1206 <shanwavf_packet+0xe6>
movsd  0x0(%r13,%rbx,8),%xmm2
ucomisd 0xe30(%rip),%xmm2
jne    1150 <shanwavf_packet+0x30>
jp     1150 <shanwavf_packet+0x30>
movsd  0xe04(%rip),%xmm1
movsd  %xmm1,(%rsp)
jmp    1181 <shanwavf_packet+0x61>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @shanwavf_packet(double* %0, i32 %1, double* %2, i32 %3, double %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
store double* %0, double** %6
store i32 %1, i32* %7
store double* %2, double** %8
store i32 %3, i32* %9
store double %4, double* %10
store double 1.000000e+00, double* %12
store i32 0, i32* %11
br label %14
14: ; preds = %81, %5
%15 = load i32, i32* %11
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %84
18: ; preds = %14
%19 = load double*, double** %6
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fcmp une double %23, 0.000000e+00
br i1 %24, label %25, label %41
25: ; preds = %18
%26 = load double*, double** %6
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = fmul double %30, 0x400921FB54442D18
%32 = fptosi double %31 to i32
%33 = call double @sin(i32 %32)
%34 = load double*, double** %6
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = fmul double %38, 0x400921FB54442D18
%40 = fdiv double %33, %39
store double %40, double* %13
br label %42
41: ; preds = %18
store double 1.000000e+00, double* %13
br label %42
42: ; preds = %41, %25
%43 = load double*, double** %6
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = fmul double 0x401921FB54442D18, %47
%49 = fptosi double %48 to i32
%50 = call double @cos(i32 %49)
%51 = load double, double* %13
%52 = fmul double %50, %51
%53 = load double, double* %12
%54 = fmul double %52, %53
%55 = load double, double* %10
%56 = fdiv double %54, %55
%57 = load double*, double** %8
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
store double %56, double* %60
%61 = load double*, double** %6
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = fmul double 0x401921FB54442D18, %65
%67 = fptosi double %66 to i32
%68 = call double @sin(i32 %67)
%69 = load double, double* %13
%70 = fmul double %68, %69
%71 = load double, double* %12
%72 = fmul double %70, %71
%73 = load double, double* %10
%74 = fdiv double %72, %73
%75 = load double*, double** %8
%76 = load i32, i32* %11
%77 = load i32, i32* %7
%78 = add nsw i32 %76, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %75, i64 %79
store double %74, double* %80
br label %81
81: ; preds = %42
%82 = load i32, i32* %11
%83 = add nsw i32 %82, 1
store i32 %83, i32* %11
br label %14
84: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @shanwavf_packet(double* nocapture %0, i32 %1, double* nocapture writeonly %2, i32 %3, double %4) {
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %41
7: ; preds = %5
%8 = zext i32 %1 to i64
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %7, %22
%11 = phi i64 [ 0, %7 ], [ %39, %22 ]
%12 = getelementptr inbounds double, double* %0, i64 %11
%13 = load double, double* %12
%14 = fcmp une double %13, 0.000000e+00
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = fmul double %13, 0x400921FB54442D18
%17 = fptosi double %16 to i32
%18 = tail call double @sin(i32 %17)
%19 = load double, double* %12
%20 = fmul double %19, 0x400921FB54442D18
%21 = fdiv double %18, %20
br label %22
22: ; preds = %10, %15
%23 = phi double [ %19, %15 ], [ %13, %10 ]
%24 = phi double [ %21, %15 ], [ 1.000000e+00, %10 ]
%25 = fmul double %23, 0x401921FB54442D18
%26 = fptosi double %25 to i32
%27 = tail call double @cos(i32 %26)
%28 = fmul double %24, %27
%29 = fdiv double %28, %4
%30 = getelementptr inbounds double, double* %2, i64 %11
store double %29, double* %30
%31 = load double, double* %12
%32 = fmul double %31, 0x401921FB54442D18
%33 = fptosi double %32 to i32
%34 = tail call double @sin(i32 %33)
%35 = fmul double %24, %34
%36 = fdiv double %35, %4
%37 = add nuw nsw i64 %11, %8
%38 = getelementptr inbounds double, double* %2, i64 %37
store double %36, double* %38
%39 = add nuw nsw i64 %11, 1
%40 = icmp eq i64 %39, %9
br i1 %40, label %41, label %10
41: ; preds = %22, %5
ret void
}