#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 */
float cos(size_t);
void gen_signal(float *out, double omega, double bias_samples, size_t samples) {
  for (size_t i = 0; i < samples; i += 2) {
    out[i + 0] = cos(((i >> 1) + bias_samples) * omega);
    out[i + 1] = out[i + 0];
  }
}


x86 assembly (clang, -O0):
<gen_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11c2 <gen_signal+0xb2>
mov    -0x28(%rbp),%rax
shr    %rax
cvtsi2sd %rax,%xmm0
movsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
mov    %rdi,%rcx
sar    $0x3f,%rcx
movsd  0xe8b(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rcx,%rax
or     %rax,%rdi
call   1030 <cos@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  %xmm0,0x4(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1132 <gen_signal+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_signal>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rsi,%rsi
je     119b <gen_signal+0x8b>
mov    %rsi,%r14
movapd %xmm0,%xmm2
mov    %rdi,%r15
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rax
shr    %rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xe96(%rip),%xmm0
cvttsd2si %xmm0,%rdi
and    %rcx,%rdi
or     %rax,%rdi
call   1030 <cos@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
movss  %xmm0,(%r15,%rbx,4)
movss  %xmm0,0x4(%r15,%rbx,4)
add    $0x2,%rbx
cmp    %r14,%rbx
jb     1140 <gen_signal+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gen_signal(float* %0, double %1, double %2, i64 %3) {
%5 = alloca float*
%6 = alloca double
%7 = alloca double
%8 = alloca i64
%9 = alloca i64
store float* %0, float** %5
store double %1, double* %6
store double %2, double* %7
store i64 %3, i64* %8
store i64 0, i64* %9
br label %10
10: ; preds = %37, %4
%11 = load i64, i64* %9
%12 = load i64, i64* %8
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = load i64, i64* %9
%16 = lshr i64 %15, 1
%17 = uitofp i64 %16 to double
%18 = load double, double* %7
%19 = fadd double %17, %18
%20 = load double, double* %6
%21 = fmul double %19, %20
%22 = fptoui double %21 to i64
%23 = call float @cos(i64 %22)
%24 = load float*, float** %5
%25 = load i64, i64* %9
%26 = add i64 %25, 0
%27 = getelementptr inbounds float, float* %24, i64 %26
store float %23, float* %27
%28 = load float*, float** %5
%29 = load i64, i64* %9
%30 = add i64 %29, 0
%31 = getelementptr inbounds float, float* %28, i64 %30
%32 = load float, float* %31
%33 = load float*, float** %5
%34 = load i64, i64* %9
%35 = add i64 %34, 1
%36 = getelementptr inbounds float, float* %33, i64 %35
store float %32, float* %36
br label %37
37: ; preds = %14
%38 = load i64, i64* %9
%39 = add i64 %38, 2
store i64 %39, i64* %9
br label %10
40: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @gen_signal(float* nocapture writeonly %0, double %1, double %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %7
6: ; preds = %7, %4
ret void
7: ; preds = %4, %7
%8 = phi i64 [ %18, %7 ], [ 0, %4 ]
%9 = lshr exact i64 %8, 1
%10 = uitofp i64 %9 to double
%11 = fadd double %10, %2
%12 = fmul double %11, %1
%13 = fptoui double %12 to i64
%14 = tail call float @cos(i64 %13)
%15 = getelementptr inbounds float, float* %0, i64 %8
store float %14, float* %15
%16 = or i64 %8, 1
%17 = getelementptr inbounds float, float* %0, i64 %16
store float %14, float* %17
%18 = add i64 %8, 2
%19 = icmp ult i64 %18, %3
br i1 %19, label %7, label %6
}