#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_multiplebuf(signed short buf[], int n) {
  int k, j;
  for (j = k = 0; k < 2 * 600; k += 2, j++) {
    buf[k] = 2047 * sin(2.0 * M_PI * j / 200);
    buf[k + 1] = 4096 * (j % 200) / 200 - 2047;
  }
  buf[0] = 0;
  buf[1] = 0;
  buf[2 * 600 - 2] = 0;
  buf[2 * 600 - 1] = 0;
}


x86 assembly (clang, -O0):
<init_multiplebuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4b0,-0x10(%rbp)
jge    11c4 <init_multiplebuf+0xb4>
movsd  0xec6(%rip),%xmm0
mov    0x2e9f(%rip),%rax
mulsd  (%rax),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea2(%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    -0x14(%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
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <init_multiplebuf+0x1d>
mov    -0x8(%rbp),%rax
movw   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movw   $0x0,0x2(%rax)
mov    -0x8(%rbp),%rax
movw   $0x0,0x95c(%rax)
mov    -0x8(%rbp),%rax
movw   $0x0,0x95e(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_multiplebuf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xorpd  %xmm1,%xmm1
xor    %r12d,%r12d
mov    0x2eba(%rip),%r15
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
mov    %ebx,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x26,%rax
imul   $0xc8000,%eax,%eax
mov    %r12d,%r13d
sub    %eax,%r13d
movsd  (%r15),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe9c(%rip),%xmm0
call   1030 <sin@plt>
movsd  0x8(%rsp),%xmm1
mov    %eax,%ecx
shl    $0xb,%ecx
sub    %eax,%ecx
mov    %cx,(%r14,%rbx,4)
imul   $0x51eb851f,%r13,%rax
shr    $0x26,%rax
add    $0xfffff801,%eax
mov    %ax,0x2(%r14,%rbx,4)
addsd  0xe6f(%rip),%xmm1
add    $0x1,%rbx
add    $0x1000,%r12d
cmp    $0x258,%ebx
jne    1130 <init_multiplebuf+0x20>
movl   $0x0,(%r14)
movl   $0x0,0x95c(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @init_multiplebuf(i16* %0, i32 %1) {
%3 = alloca i16*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i16* %0, i16** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %35, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1200
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = load double, double* @M_PI
%12 = fmul double 2.000000e+00, %11
%13 = load i32, i32* %6
%14 = sitofp i32 %13 to double
%15 = fmul double %12, %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
%24 = load i32, i32* %6
%25 = srem i32 %24, 200
%26 = mul nsw i32 4096, %25
%27 = sdiv i32 %26, 200
%28 = sub nsw i32 %27, 2047
%29 = trunc i32 %28 to i16
%30 = load i16*, i16** %3
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i16, i16* %30, i64 %33
store i16 %29, i16* %34
br label %35
35: ; preds = %10
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 2
store i32 %37, i32* %5
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %7
40: ; preds = %7
%41 = load i16*, i16** %3
%42 = getelementptr inbounds i16, i16* %41, i64 0
store i16 0, i16* %42
%43 = load i16*, i16** %3
%44 = getelementptr inbounds i16, i16* %43, i64 1
store i16 0, i16* %44
%45 = load i16*, i16** %3
%46 = getelementptr inbounds i16, i16* %45, i64 1198
store i16 0, i16* %46
%47 = load i16*, i16** %3
%48 = getelementptr inbounds i16, i16* %47, i64 1199
store i16 0, i16* %48
ret void
}

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