#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 fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *);
int y(float);
int main() {
  float x0, xn, h, s = 0, s_old = 0, err = 0, err_old = 0;
  float e = .00005;
  int i = 0, n = 1, count = 0;
  printf("Enter x0,xn :");
  scanf("%f%f", &x0, &xn);
  printf("i\tn\tI\t\terror\n");
  while (!((count > 0) && (fabs(err - err_old) < e))) {
    h = (xn - x0) / n;
    s_old = s;
    s = y(x0) + y(xn);
    for (i = 1; i <= n - 1; i++) {
      s += 2 * y(x0 + i * h);
    }
    s *= (h / 2);
    err_old = err;
    err = fabs(s - s_old);
    if (count)
      printf("%d\t%d\t%f\t%f\n", i, n, s, err);
    else
      printf("%d\t%d\t%f\t--------\n", i, n, s);
    count++;
    n++;
  }
  printf("\n\nI = %f\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xe89(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
jle    11f0 <main+0xb0>
movss  -0x1c(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
seta   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    1202 <main+0xc2>
jmp    1340 <main+0x200>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <y@plt>
mov    %eax,-0x38(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <y@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     129e <main+0x15e>
movss  -0x8(%rbp),%xmm1
cvtsi2ssl -0x28(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1050 <y@plt>
shl    $0x1,%eax
cvtsi2ss %eax,%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1252 <main+0x112>
movss  -0x10(%rbp),%xmm0
movss  0xd59(%rip),%xmm1
divss  %xmm1,%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
movss  %xmm0,-0x1c(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     130c <main+0x1cc>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd29(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    1329 <main+0x1e9>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd14(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c1 <main+0x81>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcf9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xecb(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1060 <scanf@plt>
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm2,%xmm2
mov    $0x1,%r12d
mov    $0x1,%r13b
lea    0xead(%rip),%r14
lea    0xe99(%rip),%r15
xorps  %xmm0,%xmm0
jmp    11ea <main+0xaa>
nop
mov    %r14,%rdi
mov    %r12d,%edx
mov    $0x1,%al
call   1040 <printf@plt>
movaps 0x20(%rsp),%xmm3
movss  0x8(%rsp),%xmm2
movss  0xc(%rsp),%xmm1
add    $0x1,%r12d
movaps %xmm3,%xmm0
subss  %xmm1,%xmm0
andps  0xe40(%rip),%xmm0
add    $0xffffffff,%ebx
xor    %r13d,%r13d
movss  0xe26(%rip),%xmm1
ucomiss %xmm0,%xmm1
movaps %xmm3,%xmm0
ja     12f6 <main+0x1b6>
movss  %xmm2,0x18(%rsp)
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm2
movss  0x14(%rsp),%xmm0
subss  %xmm0,%xmm2
xorps  %xmm1,%xmm1
cvtsi2ss %r12d,%xmm1
divss  %xmm1,%xmm2
movss  %xmm2,0x8(%rsp)
call   1050 <y@plt>
mov    %eax,%ebp
movss  0x10(%rsp),%xmm0
call   1050 <y@plt>
add    %ebp,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
cmp    $0x2,%r12d
jb     1290 <main+0x150>
mov    $0x1,%ebp
xchg   %ax,%ax
movss  %xmm1,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mulss  0x8(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
call   1050 <y@plt>
movss  0x20(%rsp),%xmm1
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  %xmm0,%xmm1
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1240 <main+0x100>
mov    %r12d,%esi
jmp    1295 <main+0x155>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%esi
movss  0x8(%rsp),%xmm2
movss  0x18(%rsp),%xmm0
mulss  0xd57(%rip),%xmm2
mulss  %xmm1,%xmm2
movaps %xmm2,%xmm3
subss  %xmm0,%xmm3
andps  0xd55(%rip),%xmm3
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
test   $0x1,%r13b
movss  %xmm2,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
movaps %xmm3,0x20(%rsp)
jne    11a0 <main+0x60>
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
mov    %r15,%rdi
mov    %r12d,%edx
mov    $0x2,%al
call   1040 <printf@plt>
jmp    11ad <main+0x6d>
lea    0xd56(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Enter x0,xn :\00"
@.str.1 = [5 x i8] c"%f%f\00"
@.str.2 = [14 x i8] c"i\09n\09I\09\09error\0A\00"
@.str.3 = [13 x i8] c"%d\09%d\09%f\09%f\0A\00"
@.str.4 = [19 x i8] c"%d\09%d\09%f\09--------\0A\00"
@.str.5 = [10 x i8] c"\0A\0AI = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %8
store float 0x3F0A36E2E0000000, float* %9
store i32 0, i32* %10
store i32 1, i32* %11
store i32 0, i32* %12
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %88, %0
%17 = load i32, i32* %12
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load float, float* %7
%21 = load float, float* %8
%22 = fsub float %20, %21
%23 = call float @fabs(float %22)
%24 = load float, float* %9
%25 = fcmp olt float %23, %24
br label %26
26: ; preds = %19, %16
%27 = phi i1 [ false, %16 ], [ %25, %19 ]
%28 = xor i1 %27, true
br i1 %28, label %29, label %93
29: ; preds = %26
%30 = load float, float* %3
%31 = load float, float* %2
%32 = fsub float %30, %31
%33 = load i32, i32* %11
%34 = sitofp i32 %33 to float
%35 = fdiv float %32, %34
store float %35, float* %4
%36 = load float, float* %5
store float %36, float* %6
%37 = load float, float* %2
%38 = call i32 @y(float %37)
%39 = load float, float* %3
%40 = call i32 @y(float %39)
%41 = add nsw i32 %38, %40
%42 = sitofp i32 %41 to float
store float %42, float* %5
store i32 1, i32* %10
br label %43
43: ; preds = %59, %29
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = sub nsw i32 %45, 1
%47 = icmp sle i32 %44, %46
br i1 %47, label %48, label %62
48: ; preds = %43
%49 = load float, float* %2
%50 = load i32, i32* %10
%51 = sitofp i32 %50 to float
%52 = load float, float* %4
%53 = call float @llvm.fmuladd.f32(float %51, float %52, float %49)
%54 = call i32 @y(float %53)
%55 = mul nsw i32 2, %54
%56 = sitofp i32 %55 to float
%57 = load float, float* %5
%58 = fadd float %57, %56
store float %58, float* %5
br label %59
59: ; preds = %48
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %43
62: ; preds = %43
%63 = load float, float* %4
%64 = fdiv float %63, 2.000000e+00
%65 = load float, float* %5
%66 = fmul float %65, %64
store float %66, float* %5
%67 = load float, float* %7
store float %67, float* %8
%68 = load float, float* %5
%69 = load float, float* %6
%70 = fsub float %68, %69
%71 = call float @fabs(float %70)
store float %71, float* %7
%72 = load i32, i32* %12
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %82
74: ; preds = %62
%75 = load i32, i32* %10
%76 = load i32, i32* %11
%77 = load float, float* %5
%78 = fpext float %77 to double
%79 = load float, float* %7
%80 = fpext float %79 to double
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %75, i32 %76, double %78, double %80)
br label %88
82: ; preds = %62
%83 = load i32, i32* %10
%84 = load i32, i32* %11
%85 = load float, float* %5
%86 = fpext float %85 to double
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %83, i32 %84, double %86)
br label %88
88: ; preds = %82, %74
%89 = load i32, i32* %12
%90 = add nsw i32 %89, 1
store i32 %90, i32* %12
%91 = load i32, i32* %11
%92 = add nsw i32 %91, 1
store i32 %92, i32* %11
br label %16
93: ; preds = %26
%94 = load float, float* %5
%95 = fpext float %94 to double
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %95)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Enter x0,xn :\00"
@.str.1 = [5 x i8] c"%f%f\00"
@.str.3 = [13 x i8] c"%d\09%d\09%f\09%f\0A\00"
@.str.4 = [19 x i8] c"%d\09%d\09%f\09--------\0A\00"
@.str.5 = [10 x i8] c"\0A\0AI = %f\0A\00"
@str = [13 x i8] c"i\09n\09I\09\09error\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %0, %49
%9 = phi i1 [ true, %0 ], [ false, %49 ]
%10 = phi i32 [ 1, %0 ], [ %50, %49 ]
%11 = phi float [ 0.000000e+00, %0 ], [ %40, %49 ]
%12 = phi float [ 0.000000e+00, %0 ], [ %42, %49 ]
%13 = load float, float* %2
%14 = load float, float* %1
%15 = fsub float %13, %14
%16 = sitofp i32 %10 to float
%17 = fdiv float %15, %16
%18 = call i32 @y(float %14)
%19 = load float, float* %2
%20 = call i32 @y(float %19)
%21 = add nsw i32 %20, %18
%22 = sitofp i32 %21 to float
%23 = icmp ugt i32 %10, 1
br i1 %23, label %24, label %36
24: ; preds = %8, %24
%25 = phi i32 [ %34, %24 ], [ 1, %8 ]
%26 = phi float [ %33, %24 ], [ %22, %8 ]
%27 = load float, float* %1
%28 = sitofp i32 %25 to float
%29 = call float @llvm.fmuladd.f32(float %28, float %17, float %27)
%30 = call i32 @y(float %29)
%31 = shl nsw i32 %30, 1
%32 = sitofp i32 %31 to float
%33 = fadd float %26, %32
%34 = add nuw nsw i32 %25, 1
%35 = icmp eq i32 %34, %10
br i1 %35, label %36, label %24
36: ; preds = %24, %8
%37 = phi float [ %22, %8 ], [ %33, %24 ]
%38 = phi i32 [ 1, %8 ], [ %10, %24 ]
%39 = fmul float %17, 5.000000e-01
%40 = fmul float %39, %37
%41 = fsub float %40, %11
%42 = call float @llvm.fabs.f32(float %41)
%43 = fpext float %40 to double
br i1 %9, label %47, label %44
44: ; preds = %36
%45 = fpext float %42 to double
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %10, double %43, double %45)
br label %49
47: ; preds = %36
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %10, double %43)
br label %49
49: ; preds = %47, %44
%50 = add nuw nsw i32 %10, 1
%51 = fsub float %42, %12
%52 = call float @llvm.fabs.f32(float %51)
%53 = fcmp olt float %52, 0x3F0A36E2E0000000
br i1 %53, label %54, label %8
54: ; preds = %49
%55 = fpext float %40 to double
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %55)
ret i32 0
}