#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 */
scalar_t__ calloc(unsigned int, int);
scalar_t__ sin(double);
float *sine_wavetable_init(unsigned int wavetable_size) {
  unsigned int i = 0;
  float *wt = (float *)calloc(wavetable_size + 1, sizeof(float));
  for (i = 0; i < wavetable_size; i += 1) {
    wt[i] =
        (float)sin(((double)i / (double)wavetable_size) * 3.141592653589 * 2.0);
  }
  wt[wavetable_size] = wt[0];
  return wt;
}


x86 assembly (clang, -O0):
<sine_wavetable_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11a9 <sine_wavetable_init+0x89>
mov    -0x8(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe93(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe7f(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
cvtsi2ss %rax,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114d <sine_wavetable_init+0x2d>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sine_wavetable_init>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x1(%r14),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
je     1160 <sine_wavetable_init+0x40>
mov    %r14d,%r15d
cvtsi2sd %r15,%xmm0
cmp    $0x1,%r14d
jne    1168 <sine_wavetable_init+0x48>
xor    %ebx,%ebx
test   $0x1,%r15b
jne    11f6 <sine_wavetable_init+0xd6>
jmp    1227 <sine_wavetable_init+0x107>
xor    %r15d,%r15d
jmp    1227 <sine_wavetable_init+0x107>
mov    %r15d,%r14d
and    $0xfffffffe,%r14d
xor    %ebx,%ebx
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rsp),%xmm0
movsd  0xe69(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
call   1040 <sin@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movss  %xmm1,(%r12,%rbx,4)
divsd  (%rsp),%xmm0
mulsd  0xe36(%rip),%xmm0
addsd  %xmm0,%xmm0
call   1040 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x4(%r12,%rbx,4)
add    $0x2,%rbx
cmp    %r14,%rbx
jne    1180 <sine_wavetable_init+0x60>
movsd  (%rsp),%xmm0
test   $0x1,%r15b
je     1227 <sine_wavetable_init+0x107>
mov    %ebx,%eax
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  %xmm1,%xmm0
mulsd  0xdf0(%rip),%xmm0
addsd  %xmm0,%xmm0
call   1040 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,(%r12,%rbx,4)
movss  (%r12),%xmm0
movss  %xmm0,(%r12,%r15,4)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float* @sine_wavetable_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca float*
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* %2
%6 = add i32 %5, 1
%7 = call i64 @calloc(i32 %6, i32 4)
%8 = inttoptr i64 %7 to float*
store float* %8, float** %4
store i32 0, i32* %3
br label %9
9: ; preds = %27, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i32, i32* %3
%15 = uitofp i32 %14 to double
%16 = load i32, i32* %2
%17 = uitofp i32 %16 to double
%18 = fdiv double %15, %17
%19 = fmul double %18, 0x400921FB5444261E
%20 = fmul double %19, 2.000000e+00
%21 = call i64 @sin(double %20)
%22 = sitofp i64 %21 to float
%23 = load float*, float** %4
%24 = load i32, i32* %3
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds float, float* %23, i64 %25
store float %22, float* %26
br label %27
27: ; preds = %13
%28 = load i32, i32* %3
%29 = add i32 %28, 1
store i32 %29, i32* %3
br label %9
30: ; preds = %9
%31 = load float*, float** %4
%32 = getelementptr inbounds float, float* %31, i64 0
%33 = load float, float* %32
%34 = load float*, float** %4
%35 = load i32, i32* %2
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds float, float* %34, i64 %36
store float %33, float* %37
%38 = load float*, float** %4
ret float* %38
}

LLVM IR (-O2):
define float* @sine_wavetable_init(i32 %0) {
%2 = add i32 %0, 1
%3 = tail call i64 @calloc(i32 %2, i32 4)
%4 = inttoptr i64 %3 to float*
%5 = icmp eq i32 %0, 0
br i1 %5, label %48, label %6
6: ; preds = %1
%7 = uitofp i32 %0 to double
%8 = zext i32 %0 to i64
%9 = and i64 %8, 1
%10 = icmp eq i32 %0, 1
br i1 %10, label %36, label %11
11: ; preds = %6
%12 = and i64 %8, 4294967294
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 0, %11 ], [ %33, %13 ]
%15 = phi i64 [ 0, %11 ], [ %34, %13 ]
%16 = trunc i64 %14 to i32
%17 = uitofp i32 %16 to double
%18 = fdiv double %17, %7
%19 = fmul double %18, 0x400921FB5444261E
%20 = fmul double %19, 2.000000e+00
%21 = tail call i64 @sin(double %20)
%22 = sitofp i64 %21 to float
%23 = getelementptr inbounds float, float* %4, i64 %14
store float %22, float* %23
%24 = or i64 %14, 1
%25 = trunc i64 %24 to i32
%26 = uitofp i32 %25 to double
%27 = fdiv double %26, %7
%28 = fmul double %27, 0x400921FB5444261E
%29 = fmul double %28, 2.000000e+00
%30 = tail call i64 @sin(double %29)
%31 = sitofp i64 %30 to float
%32 = getelementptr inbounds float, float* %4, i64 %24
store float %31, float* %32
%33 = add nuw nsw i64 %14, 2
%34 = add i64 %15, 2
%35 = icmp eq i64 %34, %12
br i1 %35, label %36, label %13
36: ; preds = %13, %6
%37 = phi i64 [ 0, %6 ], [ %33, %13 ]
%38 = icmp eq i64 %9, 0
br i1 %38, label %48, label %39
39: ; preds = %36
%40 = trunc i64 %37 to i32
%41 = uitofp i32 %40 to double
%42 = fdiv double %41, %7
%43 = fmul double %42, 0x400921FB5444261E
%44 = fmul double %43, 2.000000e+00
%45 = tail call i64 @sin(double %44)
%46 = sitofp i64 %45 to float
%47 = getelementptr inbounds float, float* %4, i64 %37
store float %46, float* %47
br label %48
48: ; preds = %39, %36, %1
%49 = phi i64 [ 0, %1 ], [ %8, %36 ], [ %8, %39 ]
%50 = load float, float* %4
%51 = getelementptr inbounds float, float* %4, i64 %49
store float %50, float* %51
ret float* %4
}