#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 */
scalar_t__ abs(double);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
double func(double, int);
double func_(double);
int main() {
  int i, SAMPLE_N = 512, num;
  FILE *fd;
  fd = fopen("39error.dat", "w");
  for (num = 10; num < 1000; num += 10) {
    double sum = 0;
    for (i = 0; i < SAMPLE_N; i++) {
      double x = i * 2 * 3.14159265 / SAMPLE_N + 1.0;
      sum += abs(func(x, num) - func_(x));
    }
    sum = func(3.14159265 / 4, num) - func_(3.14159265 / 4);
    fprintf(fd, "%d %f\n", num, sum);
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0xc(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0xa,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    128f <main+0x12f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1236 <main+0xd6>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe42(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe25(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%edi
call   1070 <func@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <func_@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
call   1030 <abs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b0 <main+0x50>
mov    -0x10(%rbp),%edi
movsd  0xdbf(%rip),%xmm0
call   1070 <func@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xdad(%rip),%xmm0
call   1040 <func_@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xdaa(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
jmp    1194 <main+0x34>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeaf(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0xa,%ebx
lea    0xea2(%rip),%r15
nopl   0x0(%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe51(%rip),%xmm0
mulsd  0xe51(%rip),%xmm0
addsd  0xe51(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   1070 <func@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <func_@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <abs@plt>
add    $0x2,%ebp
cmp    $0x400,%ebp
jne    11a0 <main+0x40>
movsd  0xe15(%rip),%xmm0
mov    %ebx,%edi
call   1070 <func@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe00(%rip),%xmm0
call   1040 <func_@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
movapd %xmm1,%xmm0
call   1060 <fprintf@plt>
lea    0xa(%rbx),%eax
cmp    $0x3de,%ebx
mov    %eax,%ebx
jb     1190 <main+0x30>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"39error.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
store i32 512, i32* %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %5
store i32 10, i32* %4
br label %9
9: ; preds = %48, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %51
12: ; preds = %9
store double 0.000000e+00, double* %6
store i32 0, i32* %2
br label %13
13: ; preds = %36, %12
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %39
17: ; preds = %13
%18 = load i32, i32* %2
%19 = mul nsw i32 %18, 2
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 0x400921FB53C8D4F1
%22 = load i32, i32* %3
%23 = sitofp i32 %22 to double
%24 = fdiv double %21, %23
%25 = fadd double %24, 1.000000e+00
store double %25, double* %7
%26 = load double, double* %7
%27 = load i32, i32* %4
%28 = call double @func(double %26, i32 %27)
%29 = load double, double* %7
%30 = call double @func_(double %29)
%31 = fsub double %28, %30
%32 = call i64 @abs(double %31)
%33 = sitofp i64 %32 to double
%34 = load double, double* %6
%35 = fadd double %34, %33
store double %35, double* %6
br label %36
36: ; preds = %17
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %13
39: ; preds = %13
%40 = load i32, i32* %4
%41 = call double @func(double 0x3FE921FB53C8D4F1, i32 %40)
%42 = call double @func_(double 0x3FE921FB53C8D4F1)
%43 = fsub double %41, %42
store double %43, double* %6
%44 = load i32*, i32** %5
%45 = load i32, i32* %4
%46 = load double, double* %6
%47 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %45, double %46)
br label %48
48: ; preds = %39
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 10
store i32 %50, i32* %4
br label %9
51: ; preds = %9
%52 = load i32*, i32** %5
%53 = call i32 @fclose(i32* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"39error.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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, %17
%3 = phi i32 [ 10, %0 ], [ %22, %17 ]
br label %4
4: ; preds = %2, %4
%5 = phi i32 [ 0, %2 ], [ %15, %4 ]
%6 = shl nuw nsw i32 %5, 1
%7 = sitofp i32 %6 to double
%8 = fmul double %7, 0x400921FB53C8D4F1
%9 = fmul double %8, 0x3F60000000000000
%10 = fadd double %9, 1.000000e+00
%11 = tail call double @func(double %10, i32 %3)
%12 = tail call double @func_(double %10)
%13 = fsub double %11, %12
%14 = tail call i64 @abs(double %13)
%15 = add nuw nsw i32 %5, 1
%16 = icmp eq i32 %15, 512
br i1 %16, label %17, label %4
17: ; preds = %4
%18 = tail call double @func(double 0x3FE921FB53C8D4F1, i32 %3)
%19 = tail call double @func_(double 0x3FE921FB53C8D4F1)
%20 = fsub double %18, %19
%21 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %3, double %20)
%22 = add nuw nsw i32 %3, 10
%23 = icmp ult i32 %3, 990
br i1 %23, label %2, label %24
24: ; preds = %17
%25 = tail call i32 @fclose(i32* %1)
ret i32 0
}