#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);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main() {
  int i, j, SAMPLE_N = 512, nums[] = {10, 100, 1000};
  double x;
  char fname[50];
  FILE *fd;
  for (j = 0; j < 3; j++) {
    int num = nums[j];
    sprintf(fname, "38series%d.dat", num);
    fd = fopen(fname, "w");
    for (i = 0; i < SAMPLE_N; i++) {
      x = i * 2 * 3.14159265 / SAMPLE_N;
      fprintf(fd, "%f %f\n", x, func(x, num));
    }
    fclose(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0x10(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe96(%rip),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1253 <main+0x103>
movslq -0xc(%rbp),%rax
mov    -0x1c(%rbp,%rax,4),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%edx
lea    0xe6d(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123c <main+0xec>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe1b(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x80(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x6c(%rbp),%edi
call   1050 <func@plt>
mov    -0x80(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
lea    0xdfc(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c7 <main+0x77>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <main+0x34>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xeb1(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <sprintf@plt>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe95(%rip),%r14
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe61(%rip),%xmm0
mulsd  0xe61(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
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    1190 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe2a(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%edx
call   1070 <sprintf@plt>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe0e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xdd1(%rip),%xmm0
mulsd  0xdd1(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x64,%edi
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    1220 <main+0xd0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd9a(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3e8,%edx
call   1070 <sprintf@plt>
lea    0xd90(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xd7e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xd41(%rip),%xmm0
mulsd  0xd41(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x3e8,%edi
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    12b0 <main+0x160>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.nums = [3 x i32] [i32 10, i32 100, i32 1000]
@.str = [15 x i8] c"38series%d.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 [3 x i32]
%6 = alloca double
%7 = alloca [50 x i8]
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %1
store i32 512, i32* %4
%10 = bitcast [3 x i32]* %5 to i8*
store i32 0, i32* %3
br label %11
11: ; preds = %48, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %51
14: ; preds = %11
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %9
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %9
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %8
store i32 0, i32* %2
br label %24
24: ; preds = %42, %14
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = load i32, i32* %2
%30 = mul nsw i32 %29, 2
%31 = sitofp i32 %30 to double
%32 = fmul double %31, 0x400921FB53C8D4F1
%33 = load i32, i32* %4
%34 = sitofp i32 %33 to double
%35 = fdiv double %32, %34
store double %35, double* %6
%36 = load i32*, i32** %8
%37 = load double, double* %6
%38 = load double, double* %6
%39 = load i32, i32* %9
%40 = call double @func(double %38, i32 %39)
%41 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %37, double %40)
br label %42
42: ; preds = %28
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
br label %24
45: ; preds = %24
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %11
51: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"38series%d.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 [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 10)
%4 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %13, %5 ]
%7 = shl nuw nsw i32 %6, 1
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 0x400921FB53C8D4F1
%10 = fmul double %9, 0x3F60000000000000
%11 = tail call double @func(double %10, i32 10)
%12 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %10, double %11)
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, 512
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = tail call i32 @fclose(i32* %4)
%17 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 100)
%18 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %19, %15
%20 = phi i32 [ 0, %15 ], [ %27, %19 ]
%21 = shl nuw nsw i32 %20, 1
%22 = sitofp i32 %21 to double
%23 = fmul double %22, 0x400921FB53C8D4F1
%24 = fmul double %23, 0x3F60000000000000
%25 = tail call double @func(double %24, i32 100)
%26 = tail call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %24, double %25)
%27 = add nuw nsw i32 %20, 1
%28 = icmp eq i32 %27, 512
br i1 %28, label %29, label %19
29: ; preds = %19
%30 = tail call i32 @fclose(i32* %18)
%31 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 1000)
%32 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %33, %29
%34 = phi i32 [ 0, %29 ], [ %41, %33 ]
%35 = shl nuw nsw i32 %34, 1
%36 = sitofp i32 %35 to double
%37 = fmul double %36, 0x400921FB53C8D4F1
%38 = fmul double %37, 0x3F60000000000000
%39 = tail call double @func(double %38, i32 1000)
%40 = tail call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %38, double %39)
%41 = add nuw nsw i32 %34, 1
%42 = icmp eq i32 %41, 512
br i1 %42, label %43, label %33
43: ; preds = %33
%44 = tail call i32 @fclose(i32* %32)
ret i32 0
}