#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 */
double f(double);
double pow(int, double);
int /*<<< orphan*/ printf(char *, int, double);
int main() {
  double min = 0.0;
  double max = 1.0;
  int i, res = 4;
  int di = 1;
  for (i = 0; i < 10; i++, res *= 2) {
    double tse = 0.0;
    int j;
    for (j = 1; j < (res - 1); j++) {
      double err;
      double y1, y2, y3;
      y1 = f((min + (max - min) * (j - 1) / (res - 1.0)));
      y2 = f((min + (max - min) * (j) / (res - 1.0)));
      y3 = f((min + (max - min) * (j + 1) / (res - 1.0)));
      err = 0.5 * (y3 + y1) - y2;
      tse += err * err;
    }
    tse *= pow((res - 1.0), 4.0);
    tse /= pow((res - 2.0), (double)di);
    printf("Res %d, tse = %f\n", res, tse);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x4,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    133a <main+0x20a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12b3 <main+0x183>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x20(%rbp),%xmm2
movsd  0xe43(%rip),%xmm3
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x20(%rbp),%xmm2
movsd  0xe08(%rip),%xmm3
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x20(%rbp),%xmm2
movsd  0xdc8(%rip),%xmm3
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xd9c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1182 <main+0x52>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xd40(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xd40(%rip),%xmm0
call   1050 <pow@plt>
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xd1c(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
cvtsi2sdl -0x24(%rbp),%xmm0
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
lea    0xd02(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <main+0x39>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0x4,%ebx
xor    %r15d,%r15d
lea    0xee7(%rip),%r14
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x20(%rsp)
addsd  0xe9b(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x18(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe61(%rip),%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x18(%rsp),%xmm0
addsd  0xe28(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe2d(%rip),%xmm0
call   1030 <f@plt>
addsd  0x30(%rsp),%xmm0
mulsd  0xe02(%rip),%xmm0
subsd  0x28(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1190 <main+0x60>
cvttsd2si 0x8(%rsp),%edi
movsd  0xdd7(%rip),%xmm0
call   1050 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
addsd  0xdc0(%rip),%xmm0
cvttsd2si %xmm0,%edi
movsd  0xd9c(%rip),%xmm0
call   1050 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    %r14,%rdi
mov    %ebx,%esi
movapd %xmm1,%xmm0
call   1040 <printf@plt>
add    $0x1,%r15d
add    %ebx,%ebx
cmp    $0xa,%r15d
jne    1150 <main+0x20>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Res %d, tse = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 1.000000e+00, double* %3
store i32 4, i32* %5
store i32 1, i32* %6
store i32 0, i32* %4
br label %13
13: ; preds = %97, %0
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 10
br i1 %15, label %16, label %102
16: ; preds = %13
store double 0.000000e+00, double* %7
store i32 1, i32* %8
br label %17
17: ; preds = %74, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %77
22: ; preds = %17
%23 = load double, double* %2
%24 = load double, double* %3
%25 = load double, double* %2
%26 = fsub double %24, %25
%27 = load i32, i32* %8
%28 = sub nsw i32 %27, 1
%29 = sitofp i32 %28 to double
%30 = fmul double %26, %29
%31 = load i32, i32* %5
%32 = sitofp i32 %31 to double
%33 = fsub double %32, 1.000000e+00
%34 = fdiv double %30, %33
%35 = fadd double %23, %34
%36 = call double @f(double %35)
store double %36, double* %10
%37 = load double, double* %2
%38 = load double, double* %3
%39 = load double, double* %2
%40 = fsub double %38, %39
%41 = load i32, i32* %8
%42 = sitofp i32 %41 to double
%43 = fmul double %40, %42
%44 = load i32, i32* %5
%45 = sitofp i32 %44 to double
%46 = fsub double %45, 1.000000e+00
%47 = fdiv double %43, %46
%48 = fadd double %37, %47
%49 = call double @f(double %48)
store double %49, double* %11
%50 = load double, double* %2
%51 = load double, double* %3
%52 = load double, double* %2
%53 = fsub double %51, %52
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
%56 = sitofp i32 %55 to double
%57 = fmul double %53, %56
%58 = load i32, i32* %5
%59 = sitofp i32 %58 to double
%60 = fsub double %59, 1.000000e+00
%61 = fdiv double %57, %60
%62 = fadd double %50, %61
%63 = call double @f(double %62)
store double %63, double* %12
%64 = load double, double* %12
%65 = load double, double* %10
%66 = fadd double %64, %65
%67 = load double, double* %11
%68 = fneg double %67
%69 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %66, double %68)
store double %69, double* %9
%70 = load double, double* %9
%71 = load double, double* %9
%72 = load double, double* %7
%73 = call double @llvm.fmuladd.f64(double %70, double %71, double %72)
store double %73, double* %7
br label %74
74: ; preds = %22
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %17
77: ; preds = %17
%78 = load i32, i32* %5
%79 = sitofp i32 %78 to double
%80 = fsub double %79, 1.000000e+00
%81 = fptosi double %80 to i32
%82 = call double @pow(i32 %81, double 4.000000e+00)
%83 = load double, double* %7
%84 = fmul double %83, %82
store double %84, double* %7
%85 = load i32, i32* %5
%86 = sitofp i32 %85 to double
%87 = fsub double %86, 2.000000e+00
%88 = fptosi double %87 to i32
%89 = load i32, i32* %6
%90 = sitofp i32 %89 to double
%91 = call double @pow(i32 %88, double %90)
%92 = load double, double* %7
%93 = fdiv double %92, %91
store double %93, double* %7
%94 = load i32, i32* %5
%95 = load double, double* %7
%96 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %94, double %95)
br label %97
97: ; preds = %77
%98 = load i32, i32* %4
%99 = add nsw i32 %98, 1
store i32 %99, i32* %4
%100 = load i32, i32* %5
%101 = mul nsw i32 %100, 2
store i32 %101, i32* %5
br label %13
102: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Res %d, tse = %f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %29, %0
%2 = phi i32 [ 0, %0 ], [ %38, %29 ]
%3 = phi i32 [ 4, %0 ], [ %39, %29 ]
%4 = add nsw i32 %3, -1
%5 = sitofp i32 %3 to double
%6 = fadd double %5, -1.000000e+00
br label %7
7: ; preds = %1, %7
%8 = phi double [ 0.000000e+00, %1 ], [ %27, %7 ]
%9 = phi i32 [ 1, %1 ], [ %19, %7 ]
%10 = add nsw i32 %9, -1
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, %6
%13 = fadd double %12, 0.000000e+00
%14 = tail call double @f(double %13)
%15 = sitofp i32 %9 to double
%16 = fdiv double %15, %6
%17 = fadd double %16, 0.000000e+00
%18 = tail call double @f(double %17)
%19 = add nuw nsw i32 %9, 1
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, %6
%22 = fadd double %21, 0.000000e+00
%23 = tail call double @f(double %22)
%24 = fadd double %14, %23
%25 = fneg double %18
%26 = tail call double @llvm.fmuladd.f64(double %24, double 5.000000e-01, double %25)
%27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %8)
%28 = icmp eq i32 %19, %4
br i1 %28, label %29, label %7
29: ; preds = %7
%30 = fptosi double %6 to i32
%31 = tail call double @pow(i32 %30, double 4.000000e+00)
%32 = fmul double %27, %31
%33 = fadd double %5, -2.000000e+00
%34 = fptosi double %33 to i32
%35 = tail call double @pow(i32 %34, double 1.000000e+00)
%36 = fdiv double %32, %35
%37 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %3, double %36)
%38 = add nuw nsw i32 %2, 1
%39 = shl nsw i32 %3, 1
%40 = icmp eq i32 %38, 10
br i1 %40, label %41, label %1
41: ; preds = %29
ret i32 0
}