#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 */
int M_PI;
double sin(double);
void makewave(short wtable[]) {
  int i;
  for (i = 0; i < 1000; i++) {
    wtable[i] = sin((double)(2 * M_PI * (float)i / 1000)) * 32767.0;
  }
  return;
}


x86 assembly (clang, -O0):
<makewave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    118a <makewave+0x7a>
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
cvtsi2ss %eax,%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xeb0(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <sin@plt>
movsd  0xea3(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%dx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <makewave+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makewave>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
mov    0x2ec7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
mulss  %xmm0,%xmm1
divss  0xeb1(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
call   1030 <sin@plt>
mulsd  0xea5(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%r14,%rbx,2)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1130 <makewave+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @makewave(i16* %0) {
%2 = alloca i16*
%3 = alloca i32
store i16* %0, i16** %2
store i32 0, i32* %3
br label %4
4: ; preds = %23, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1000
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = load i32, i32* @M_PI
%9 = mul nsw i32 2, %8
%10 = sitofp i32 %9 to float
%11 = load i32, i32* %3
%12 = sitofp i32 %11 to float
%13 = fmul float %10, %12
%14 = fdiv float %13, 1.000000e+03
%15 = fpext float %14 to double
%16 = call double @sin(double %15)
%17 = fmul double %16, 3.276700e+04
%18 = fptosi double %17 to i16
%19 = load i16*, i16** %2
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i16, i16* %19, i64 %21
store i16 %18, i16* %22
br label %23
23: ; preds = %7
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %4
26: ; preds = %4
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @makewave(i16* nocapture writeonly %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %16, %2 ]
%4 = load i32, i32* @M_PI
%5 = shl nsw i32 %4, 1
%6 = sitofp i32 %5 to float
%7 = trunc i64 %3 to i32
%8 = sitofp i32 %7 to float
%9 = fmul float %8, %6
%10 = fdiv float %9, 1.000000e+03
%11 = fpext float %10 to double
%12 = tail call double @sin(double %11)
%13 = fmul double %12, 3.276700e+04
%14 = fptosi double %13 to i16
%15 = getelementptr inbounds i16, i16* %0, i64 %3
store i16 %14, i16* %15
%16 = add nuw nsw i64 %3, 1
%17 = icmp eq i64 %16, 1000
br i1 %17, label %18, label %2
18: ; preds = %2
ret void
}