void init_ramp(signed short buf[], int n) {
  int k;
  for (k = 0; k < 3000; k++)
    buf[k] = 4096 * (k % 200) / 200 - 2047;
  buf[3000 - 2] = 1000;
  buf[3000 - 1] = 0;
}


x86 assembly (clang, -O0):
<init_ramp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xbb8,-0x10(%rbp)
jge    1159 <init_ramp+0x59>
mov    -0x10(%rbp),%eax
mov    $0xc8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
shl    $0xc,%eax
mov    $0xc8,%ecx
cltd
idiv   %ecx
sub    $0x7ff,%eax
mov    %ax,%dx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <init_ramp+0x12>
mov    -0x8(%rbp),%rax
movw   $0x3e8,0x176c(%rax)
e8 03
mov    -0x8(%rbp),%rax
movw   $0x0,0x176e(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_ramp>:
movdqa 0xef8(%rip),%xmm1
xor    %eax,%eax
movdqa 0xefd(%rip),%xmm8
movdqa 0xf04(%rip),%xmm9
pxor   %xmm3,%xmm3
movdqa 0xf08(%rip),%xmm4
movdqa 0xf10(%rip),%xmm5
movdqa 0xf18(%rip),%xmm6
nopl   0x0(%rax,%rax,1)
movdqa %xmm1,%xmm7
psrlw  $0x3,%xmm7
pmulhuw %xmm8,%xmm7
psrlw  $0x1,%xmm7
pmullw %xmm9,%xmm7
movdqa %xmm1,%xmm0
psubw  %xmm7,%xmm0
movdqa %xmm0,%xmm7
punpckhwd %xmm3,%xmm7
punpcklwd %xmm3,%xmm0
pslld  $0xc,%xmm0
pslld  $0xc,%xmm7
pshufd $0xf5,%xmm7,%xmm2
pmuludq %xmm4,%xmm7
pshufd $0xed,%xmm7,%xmm7
pmuludq %xmm4,%xmm2
pshufd $0xed,%xmm2,%xmm2
punpckldq %xmm2,%xmm7
psrld  $0x6,%xmm7
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm4,%xmm0
pshufd $0xed,%xmm0,%xmm0
pmuludq %xmm4,%xmm2
pshufd $0xed,%xmm2,%xmm2
punpckldq %xmm2,%xmm0
psrld  $0x6,%xmm0
packssdw %xmm7,%xmm0
paddw  %xmm5,%xmm0
movdqu %xmm0,(%rdi,%rax,2)
add    $0x8,%rax
paddw  %xmm6,%xmm1
cmp    $0xbb8,%rax
jne    1140 <init_ramp+0x40>
movl   $0x3e8,0x176c(%rdi)
ret

LLVM IR (-O0):
define void @init_ramp(i16* %0, i32 %1) {
%3 = alloca i16*
%4 = alloca i32
%5 = alloca i32
store i16* %0, i16** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %20, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 3000
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32, i32* %5
%11 = srem i32 %10, 200
%12 = mul nsw i32 4096, %11
%13 = sdiv i32 %12, 200
%14 = sub nsw i32 %13, 2047
%15 = trunc i32 %14 to i16
%16 = load i16*, i16** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i16, i16* %16, i64 %18
store i16 %15, i16* %19
br label %20
20: ; preds = %9
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %6
23: ; preds = %6
%24 = load i16*, i16** %3
%25 = getelementptr inbounds i16, i16* %24, i64 2998
store i16 1000, i16* %25
%26 = load i16*, i16** %3
%27 = getelementptr inbounds i16, i16* %26, i64 2999
store i16 0, i16* %27
ret void
}

LLVM IR (-O2):
define void @init_ramp(i16* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %14, %3 ]
%5 = phi <8 x i16> [ <i16 0, i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7>, %2 ], [ %15, %3 ]
%6 = urem <8 x i16> %5, <i16 200, i16 200, i16 200, i16 200, i16 200, i16 200, i16 200, i16 200>
%7 = zext <8 x i16> %6 to <8 x i32>
%8 = shl nuw nsw <8 x i32> %7, <i32 12, i32 12, i32 12, i32 12, i32 12, i32 12, i32 12, i32 12>
%9 = udiv <8 x i32> %8, <i32 200, i32 200, i32 200, i32 200, i32 200, i32 200, i32 200, i32 200>
%10 = trunc <8 x i32> %9 to <8 x i16>
%11 = add nsw <8 x i16> %10, <i16 -2047, i16 -2047, i16 -2047, i16 -2047, i16 -2047, i16 -2047, i16 -2047, i16 -2047>
%12 = getelementptr inbounds i16, i16* %0, i64 %4
%13 = bitcast i16* %12 to <8 x i16>*
store <8 x i16> %11, <8 x i16>* %13
%14 = add nuw i64 %4, 8
%15 = add <8 x i16> %5, <i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8>
%16 = icmp eq i64 %14, 3000
br i1 %16, label %17, label %3
17: ; preds = %3
%18 = getelementptr inbounds i16, i16* %0, i64 2998
store i16 1000, i16* %18
%19 = getelementptr inbounds i16, i16* %0, i64 2999
store i16 0, i16* %19
ret void
}