#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 f(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  float a, b, h, x, sum;
  int n, i;
  printf("Enter Interval [a,b]: ");
  scanf("%f %f", &a, &b);
  printf("Enter no of subinterals:");
  scanf("%d", &n);
  h = (b - a) / n;
  for (i = 0; i <= n; i++) {
    x = a + i * h;
    if (i != 0 && i != n) {
      if (i % 2 == 0)
        sum += 2 * f(x);
      else
        sum += 4 * f(x);
    } else
      sum += f(x);
  }
  sum = sum * h / 3;
  printf("Resul: %f", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1265 <main+0x135>
movss  -0x8(%rbp),%xmm1
cvtsi2ssl -0x20(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     123e <main+0x10e>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     123e <main+0x10e>
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1215 <main+0xe5>
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movss  -0x18(%rbp),%xmm1
addss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1239 <main+0x109>
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movss  -0x18(%rbp),%xmm1
movss  0xdd8(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1252 <main+0x122>
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1257 <main+0x127>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a2 <main+0x72>
movss  -0x18(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  0xd89(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xecc(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x1c(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x1c(%rsp),%xmm2
mov    0x14(%rsp),%eax
cvtsi2ss %eax,%xmm0
movss  0x18(%rsp),%xmm1
subss  %xmm1,%xmm2
divss  %xmm0,%xmm2
movss  %xmm2,0x10(%rsp)
test   %eax,%eax
js     121b <main+0xeb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  0x10(%rsp),%xmm0
addss  %xmm1,%xmm0
test   %ebx,%ebx
je     11e0 <main+0xb0>
cmp    %eax,%ebx
je     11e0 <main+0xb0>
call   1030 <f@plt>
test   $0x1,%bl
jne    11f0 <main+0xc0>
addss  %xmm0,%xmm0
jmp    11f8 <main+0xc8>
nopl   0x0(%rax)
call   1030 <f@plt>
jmp    11f8 <main+0xc8>
nopw   0x0(%rax,%rax,1)
mulss  0xe08(%rip),%xmm0
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
mov    0x14(%rsp),%eax
cmp    %eax,%ebx
jge    121b <main+0xeb>
movss  %xmm1,0xc(%rsp)
add    $0x1,%ebx
movss  0x18(%rsp),%xmm1
jmp    11b0 <main+0x80>
movss  0x10(%rsp),%xmm0
mulss  %xmm1,%xmm0
divss  0xdd7(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe09(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Enter Interval [a,b]: \00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [25 x i8] c"Enter no of subinterals:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [10 x i8] c"Resul: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%13 = load float, float* %3
%14 = load float, float* %2
%15 = fsub float %13, %14
%16 = load i32, i32* %7
%17 = sitofp i32 %16 to float
%18 = fdiv float %15, %17
store float %18, float* %4
store i32 0, i32* %8
br label %19
19: ; preds = %56, %0
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %59
23: ; preds = %19
%24 = load float, float* %2
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to float
%27 = load float, float* %4
%28 = call float @llvm.fmuladd.f32(float %26, float %27, float %24)
store float %28, float* %5
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %50
31: ; preds = %23
%32 = load i32, i32* %8
%33 = load i32, i32* %7
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32, i32* %8
%37 = srem i32 %36, 2
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load float, float* %5
%41 = call float @f(float %40)
%42 = load float, float* %6
%43 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %41, float %42)
store float %43, float* %6
br label %49
44: ; preds = %35
%45 = load float, float* %5
%46 = call float @f(float %45)
%47 = load float, float* %6
%48 = call float @llvm.fmuladd.f32(float 4.000000e+00, float %46, float %47)
store float %48, float* %6
br label %49
49: ; preds = %44, %39
br label %55
50: ; preds = %31, %23
%51 = load float, float* %5
%52 = call float @f(float %51)
%53 = load float, float* %6
%54 = fadd float %53, %52
store float %54, float* %6
br label %55
55: ; preds = %50, %49
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %19
59: ; preds = %19
%60 = load float, float* %6
%61 = load float, float* %4
%62 = fmul float %60, %61
%63 = fdiv float %62, 3.000000e+00
store float %63, float* %6
%64 = load float, float* %6
%65 = fpext float %64 to double
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Enter Interval [a,b]: \00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [25 x i8] c"Enter no of subinterals:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [10 x i8] c"Resul: %f\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca i32
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load float, float* %2
%12 = load float, float* %1
%13 = fsub float %11, %12
%14 = load i32, i32* %3
%15 = sitofp i32 %14 to float
%16 = fdiv float %13, %15
%17 = icmp slt i32 %14, 0
br i1 %17, label %46, label %18
18: ; preds = %0, %43
%19 = phi float [ %45, %43 ], [ %12, %0 ]
%20 = phi i32 [ %41, %43 ], [ %14, %0 ]
%21 = phi i32 [ %44, %43 ], [ 0, %0 ]
%22 = phi float [ %40, %43 ], [ undef, %0 ]
%23 = sitofp i32 %21 to float
%24 = call float @llvm.fmuladd.f32(float %23, float %16, float %19)
%25 = icmp eq i32 %21, 0
%26 = icmp eq i32 %21, %20
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %36, label %28
28: ; preds = %18
%29 = and i32 %21, 1
%30 = icmp eq i32 %29, 0
%31 = call float @f(float %24)
br i1 %30, label %32, label %34
32: ; preds = %28
%33 = call float @llvm.fmuladd.f32(float %31, float 2.000000e+00, float %22)
br label %39
34: ; preds = %28
%35 = call float @llvm.fmuladd.f32(float %31, float 4.000000e+00, float %22)
br label %39
36: ; preds = %18
%37 = call float @f(float %24)
%38 = fadd float %22, %37
br label %39
39: ; preds = %36, %34, %32
%40 = phi float [ %33, %32 ], [ %35, %34 ], [ %38, %36 ]
%41 = load i32, i32* %3
%42 = icmp slt i32 %21, %41
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = add nuw nsw i32 %21, 1
%45 = load float, float* %1
br label %18
46: ; preds = %39, %0
%47 = phi float [ undef, %0 ], [ %40, %39 ]
%48 = fmul float %16, %47
%49 = fdiv float %48, 3.000000e+00
%50 = fpext float %49 to double
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %50)
ret i32 0
}