#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double);
double func(double);
int main() {
  int i, SAMPLE_N = 512;
  FILE *fd;
  fd = fopen("37impulse.dat", "w");
  for (i = 0; i < SAMPLE_N; i++) {
    double x = i * 2 * 3.14159265 / SAMPLE_N;
    fprintf(fd, "%f %f\n", x, func(x));
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0xc(%rbp)
lea    0xeab(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <main+0xa6>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <func@plt>
mov    -0x30(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1174 <main+0x34>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xeb9(%rip),%r14
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe81(%rip),%xmm0
mulsd  0xe81(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <func@plt>
movapd %xmm0,%xmm1
mov    %rbx,%rdi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm0
call   1040 <fprintf@plt>
add    $0x2,%ebp
cmp    $0x400,%ebp
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"37impulse.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%f %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca double
store i32 0, i32* %1
store i32 512, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
store i32 0, i32* %2
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, 2
%14 = sitofp i32 %13 to double
%15 = fmul double %14, 0x400921FB53C8D4F1
%16 = load i32, i32* %3
%17 = sitofp i32 %16 to double
%18 = fdiv double %15, %17
store double %18, double* %5
%19 = load i32*, i32** %4
%20 = load double, double* %5
%21 = load double, double* %5
%22 = call double @func(double %21)
%23 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %20, double %22)
br label %24
24: ; preds = %11
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %7
27: ; preds = %7
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"37impulse.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%f %f\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %10, %2 ]
%4 = shl nuw nsw i32 %3, 1
%5 = sitofp i32 %4 to double
%6 = fmul double %5, 0x400921FB53C8D4F1
%7 = fmul double %6, 0x3F60000000000000
%8 = tail call double @func(double %7)
%9 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %7, double %8)
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 512
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call i32 @fclose(i32* %1)
ret i32 0
}