#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 */
float *malloc(int);
float sin(double);
float *create_sine_table(float *table) {
  table = malloc(2048 * sizeof(float));
  int i;
  for (i = 0; i < 2048; i++) {
    table[i] = sin(2.0 * 3.14159265 * i / 2048);
  }
  return table;
}


x86 assembly (clang, -O0):
<create_sine_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x800,-0xc(%rbp)
jge    118b <create_sine_table+0x6b>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xead(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe99(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <create_sine_table+0x21>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_sine_table>:
push   %r14
push   %rbx
push   %rax
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xeb1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xead(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movss  %xmm0,(%r14,%rbx,4)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe84(%rip),%xmm0
mulsd  0xe84(%rip),%xmm0
call   1030 <sin@plt>
movss  %xmm0,0x4(%r14,%rbx,4)
add    $0x2,%rbx
cmp    $0x800,%rbx
jne    1140 <create_sine_table+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define float* @create_sine_table(float* %0) {
%2 = alloca float*
%3 = alloca i32
store float* %0, float** %2
%4 = call float* @malloc(i32 8192)
store float* %4, float** %2
store i32 0, i32* %3
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 2048
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %3
%10 = sitofp i32 %9 to double
%11 = fmul double 0x401921FB53C8D4F1, %10
%12 = fdiv double %11, 2.048000e+03
%13 = call float @sin(double %12)
%14 = load float*, float** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds float, float* %14, i64 %16
store float %13, float* %17
br label %18
18: ; preds = %8
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %5
21: ; preds = %5
%22 = load float*, float** %2
ret float* %22
}

LLVM IR (-O2):
define noalias float* @create_sine_table(float* nocapture readnone %0) {
%2 = tail call float* @malloc(i32 8192)
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ 0, %1 ], [ %18, %3 ]
%5 = trunc i64 %4 to i32
%6 = sitofp i32 %5 to double
%7 = fmul double %6, 0x401921FB53C8D4F1
%8 = fmul double %7, 0x3F40000000000000
%9 = tail call float @sin(double %8)
%10 = getelementptr inbounds float, float* %2, i64 %4
store float %9, float* %10
%11 = or i64 %4, 1
%12 = trunc i64 %11 to i32
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 0x401921FB53C8D4F1
%15 = fmul double %14, 0x3F40000000000000
%16 = tail call float @sin(double %15)
%17 = getelementptr inbounds float, float* %2, i64 %11
store float %16, float* %17
%18 = add nuw nsw i64 %4, 2
%19 = icmp eq i64 %18, 2048
br i1 %19, label %20, label %3
20: ; preds = %3
ret float* %2
}