#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(double);
double sin(double);
void gen_signal_double(double *data, double scale, int datalen) {
  int k, ramplen;
  double amp = 0.0;
  ramplen = 1000;
  for (k = 0; k < datalen; k++) {
    if (k <= ramplen)
      amp = scale * k / ((double)ramplen);
    else if (k > datalen - ramplen)
      amp = scale * (datalen - k) / ((double)ramplen);
    data[k] = amp * (0.4 * sin(33.3 * 2.0 * 3.14159265358979323846264338 *
                               ((double)(k + 1)) / ((double)11025)) +
                     0.3 * cos(201.1 * 2.0 * 3.14159265358979323846264338 *
                               ((double)(k + 1)) / ((double)11025)));
  };
  return;
}


x86 assembly (clang, -O0):
<gen_signal_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x3e8,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125f <gen_signal_double+0x13f>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1183 <gen_signal_double+0x63>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11ba <gen_signal_double+0x9a>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jle    11b5 <gen_signal_double+0x95>
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11ba <gen_signal_double+0x9a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe4a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe2e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe16(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe02(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
movsd  0xddc(%rip),%xmm2
mulsd  %xmm3,%xmm2
movsd  0xdc8(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <gen_signal_double+0x2a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_signal_double>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,(%rsp)
test   %esi,%esi
jle    121c <gen_signal_double+0xfc>
mov    %rdi,%r15
lea    -0x3e8(%rsi),%eax
movslq %eax,%r14
mov    %esi,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    11f9 <gen_signal_double+0xd9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  (%rsp),%xmm0
divsd  0xe8c(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
lea    0x1(%rbx),%r13
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0xe74(%rip),%xmm0
movsd  0xe74(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe5f(%rip),%xmm0
divsd  0xe4f(%rip),%xmm0
call   1040 <cos@plt>
mulsd  0xe52(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0xe4c(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r15,%rbx,8)
mov    %r13,%rbx
add    $0xffffffffffffffff,%r12
je     121c <gen_signal_double+0xfc>
cmp    $0x3e8,%rbx
jbe    1160 <gen_signal_double+0x40>
cmp    %r14,%rbx
jle    1174 <gen_signal_double+0x54>
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
jmp    1167 <gen_signal_double+0x47>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gen_signal_double(double* %0, double %1, i32 %2) {
%4 = alloca double*
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double* %0, double** %4
store double %1, double* %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %9
store i32 1000, i32* %8
store i32 0, i32* %7
br label %10
10: ; preds = %64, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %67
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load double, double* %5
%20 = load i32, i32* %7
%21 = sitofp i32 %20 to double
%22 = fmul double %19, %21
%23 = load i32, i32* %8
%24 = sitofp i32 %23 to double
%25 = fdiv double %22, %24
store double %25, double* %9
br label %43
26: ; preds = %14
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = sub nsw i32 %28, %29
%31 = icmp sgt i32 %27, %30
br i1 %31, label %32, label %42
32: ; preds = %26
%33 = load double, double* %5
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = sub nsw i32 %34, %35
%37 = sitofp i32 %36 to double
%38 = fmul double %33, %37
%39 = load i32, i32* %8
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
store double %41, double* %9
br label %42
42: ; preds = %32, %26
br label %43
43: ; preds = %42, %18
%44 = load double, double* %9
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
%47 = sitofp i32 %46 to double
%48 = fmul double 0x406A275CBD4A2553, %47
%49 = fdiv double %48, 1.102500e+04
%50 = call double @sin(double %49)
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
%53 = sitofp i32 %52 to double
%54 = fmul double 0x4093BE31BB185B06, %53
%55 = fdiv double %54, 1.102500e+04
%56 = call double @cos(double %55)
%57 = fmul double 3.000000e-01, %56
%58 = call double @llvm.fmuladd.f64(double 4.000000e-01, double %50, double %57)
%59 = fmul double %44, %58
%60 = load double*, double** %4
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
store double %59, double* %63
br label %64
64: ; preds = %43
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %10
67: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @gen_signal_double(double* nocapture writeonly %0, double %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %42
5: ; preds = %3
%6 = add nsw i32 %2, -1000
%7 = sext i32 %6 to i64
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %5, %26
%10 = phi i64 [ 0, %5 ], [ %28, %26 ]
%11 = phi double [ 0.000000e+00, %5 ], [ %27, %26 ]
%12 = icmp ult i64 %10, 1001
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = trunc i64 %10 to i32
%15 = sitofp i32 %14 to double
%16 = fmul double %15, %1
%17 = fdiv double %16, 1.000000e+03
br label %26
18: ; preds = %9
%19 = icmp sgt i64 %10, %7
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = trunc i64 %10 to i32
%22 = sub nsw i32 %2, %21
%23 = sitofp i32 %22 to double
%24 = fmul double %23, %1
%25 = fdiv double %24, 1.000000e+03
br label %26
26: ; preds = %18, %20, %13
%27 = phi double [ %17, %13 ], [ %25, %20 ], [ %11, %18 ]
%28 = add nuw nsw i64 %10, 1
%29 = trunc i64 %28 to i32
%30 = sitofp i32 %29 to double
%31 = fmul double %30, 0x406A275CBD4A2553
%32 = fdiv double %31, 1.102500e+04
%33 = tail call double @sin(double %32)
%34 = fmul double %30, 0x4093BE31BB185B06
%35 = fdiv double %34, 1.102500e+04
%36 = tail call double @cos(double %35)
%37 = fmul double %36, 3.000000e-01
%38 = tail call double @llvm.fmuladd.f64(double %33, double 4.000000e-01, double %37)
%39 = fmul double %27, %38
%40 = getelementptr inbounds double, double* %0, i64 %10
store double %39, double* %40
%41 = icmp eq i64 %28, %8
br i1 %41, label %42, label %9
42: ; preds = %26, %3
ret void
}