#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 M_PI;
int sin(double);
void init_sine(signed short buf[], int n) {
  int k;
  for (k = 0; k < 3000; k++)
    buf[k] = 2047 * sin(2.0 * M_PI * (k + 1) / 200);
  buf[3000 - 1] = 0;
}


x86 assembly (clang, -O0):
<init_sine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xbb8,-0x10(%rbp)
jge    1188 <init_sine+0x78>
movsd  0xecd(%rip),%xmm0
mov    0x2ea6(%rip),%rax
mulsd  (%rax),%xmm0
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea4(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
imul   $0x7ff,%eax,%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    1126 <init_sine+0x16>
mov    -0x8(%rbp),%rax
movw   $0x0,0x176e(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_sine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%ebx
mov    $0x2,%ebp
mov    0x2ebd(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsd  (%r15),%xmm1
addsd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xeb4(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
mov    %eax,%ecx
shl    $0xb,%ecx
sub    %eax,%ecx
mov    %cx,-0x2(%r14,%rbx,2)
movsd  (%r15),%xmm1
addsd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe82(%rip),%xmm0
call   1030 <sin@plt>
mov    %eax,%ecx
shl    $0xb,%ecx
sub    %eax,%ecx
mov    %cx,(%r14,%rbx,2)
add    $0x2,%rbx
add    $0x2,%ebp
cmp    $0xbb9,%rbx
jne    1130 <init_sine+0x20>
movw   $0x0,0x176e(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @init_sine(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 = %24, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 3000
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load double, double* @M_PI
%11 = fmul double 2.000000e+00, %10
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = fmul double %11, %14
%16 = fdiv double %15, 2.000000e+02
%17 = call i32 @sin(double %16)
%18 = mul nsw i32 2047, %17
%19 = trunc i32 %18 to i16
%20 = load i16*, i16** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i16, i16* %20, i64 %22
store i16 %19, i16* %23
br label %24
24: ; preds = %9
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %6
27: ; preds = %6
%28 = load i16*, i16** %3
%29 = getelementptr inbounds i16, i16* %28, i64 2999
store i16 0, i16* %29
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @init_sine(i16* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %18, %3 ]
%5 = load double, double* @M_PI
%6 = fmul double %5, 2.000000e+00
%7 = or i64 %4, 1
%8 = trunc i64 %7 to i32
%9 = sitofp i32 %8 to double
%10 = fmul double %6, %9
%11 = fdiv double %10, 2.000000e+02
%12 = tail call i32 @sin(double %11)
%13 = trunc i32 %12 to i16
%14 = mul i16 %13, 2047
%15 = getelementptr inbounds i16, i16* %0, i64 %4
store i16 %14, i16* %15
%16 = load double, double* @M_PI
%17 = fmul double %16, 2.000000e+00
%18 = add nuw nsw i64 %4, 2
%19 = trunc i64 %18 to i32
%20 = sitofp i32 %19 to double
%21 = fmul double %17, %20
%22 = fdiv double %21, 2.000000e+02
%23 = tail call i32 @sin(double %22)
%24 = trunc i32 %23 to i16
%25 = mul i16 %24, 2047
%26 = getelementptr inbounds i16, i16* %0, i64 %7
store i16 %25, i16* %26
%27 = icmp eq i64 %18, 3000
br i1 %27, label %28, label %3
28: ; preds = %3
%29 = getelementptr inbounds i16, i16* %0, i64 2999
store i16 0, i16* %29
ret void
}