#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 = datalen / 18;
  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)
mov    -0x14(%rbp),%eax
mov    $0x12,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1266 <gen_signal_double+0x146>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     118a <gen_signal_double+0x6a>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c1 <gen_signal_double+0xa1>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jle    11bc <gen_signal_double+0x9c>
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    11c1 <gen_signal_double+0xa1>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe43(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe27(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdfb(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
movsd  0xdd5(%rip),%xmm2
mulsd  %xmm3,%xmm2
movsd  0xdc1(%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    1151 <gen_signal_double+0x31>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_signal_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x8(%rsp)
test   %esi,%esi
jle    1235 <gen_signal_double+0x115>
mov    %rdi,%r14
movslq %esi,%rax
imul   $0x38e38e39,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
mov    %esi,%r13d
sub    %eax,%esi
movslq %esi,%r15
movslq %eax,%r12
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1216 <gen_signal_double+0xf6>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x1(%rbx),%rbp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xe4f(%rip),%xmm0
movsd  0xe4f(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe3a(%rip),%xmm0
divsd  0xe2a(%rip),%xmm0
call   1040 <cos@plt>
mulsd  0xe2d(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0xe27(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rbx,8)
mov    %rbp,%rbx
add    $0xffffffffffffffff,%r13
je     1235 <gen_signal_double+0x115>
cmp    %r12,%rbx
jle    1180 <gen_signal_double+0x60>
cmp    %r15,%rbx
jle    1192 <gen_signal_double+0x72>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
jmp    1187 <gen_signal_double+0x67>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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
%10 = load i32, i32* %6
%11 = sdiv i32 %10, 18
store i32 %11, i32* %8
store i32 0, i32* %7
br label %12
12: ; preds = %66, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %69
16: ; preds = %12
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load double, double* %5
%22 = load i32, i32* %7
%23 = sitofp i32 %22 to double
%24 = fmul double %21, %23
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
store double %27, double* %9
br label %45
28: ; preds = %16
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = load i32, i32* %8
%32 = sub nsw i32 %30, %31
%33 = icmp sgt i32 %29, %32
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = load double, double* %5
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = sub nsw i32 %36, %37
%39 = sitofp i32 %38 to double
%40 = fmul double %35, %39
%41 = load i32, i32* %8
%42 = sitofp i32 %41 to double
%43 = fdiv double %40, %42
store double %43, double* %9
br label %44
44: ; preds = %34, %28
br label %45
45: ; preds = %44, %20
%46 = load double, double* %9
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
%49 = sitofp i32 %48 to double
%50 = fmul double 0x406A275CBD4A2553, %49
%51 = fdiv double %50, 1.102500e+04
%52 = call double @sin(double %51)
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
%55 = sitofp i32 %54 to double
%56 = fmul double 0x4093BE31BB185B06, %55
%57 = fdiv double %56, 1.102500e+04
%58 = call double @cos(double %57)
%59 = fmul double 3.000000e-01, %58
%60 = call double @llvm.fmuladd.f64(double 4.000000e-01, double %52, double %59)
%61 = fmul double %46, %60
%62 = load double*, double** %4
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
store double %61, double* %65
br label %66
66: ; preds = %45
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %12
69: ; preds = %12
ret void
}

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