#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) {
      sum += 2 * f(x);
    } else
      sum += f(x);
  }
  sum = sum * h / 2;
  printf("Result: %f", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec2(%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     1228 <main+0xf8>
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     1201 <main+0xd1>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1201 <main+0xd1>
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movss  -0x18(%rbp),%xmm1
addss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1215 <main+0xe5>
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    121a <main+0xea>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a2 <main+0x72>
movss  -0x18(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  0xdc6(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdea(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x14(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x14(%rsp),%xmm2
mov    0x8(%rsp),%eax
cvtsi2ss %eax,%xmm0
movss  0x10(%rsp),%xmm1
subss  %xmm1,%xmm2
divss  %xmm0,%xmm2
test   %eax,%eax
js     1216 <main+0xe6>
xorps  %xmm0,%xmm0
movss  %xmm2,0x4(%rsp)
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <f@plt>
mov    0x8(%rsp),%ebp
movss  0xe41(%rip),%xmm0
test   %ebp,%ebp
jle    1218 <main+0xe8>
mov    $0x1,%ebx
movss  0x4(%rsp),%xmm2
jmp    11f0 <main+0xc0>
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
mov    0x8(%rsp),%ebp
lea    0x1(%rbx),%eax
cmp    %ebp,%ebx
mov    %eax,%ebx
movss  0x4(%rsp),%xmm2
jge    121e <main+0xee>
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm2,%xmm0
addss  0x10(%rsp),%xmm0
call   1030 <f@plt>
cmp    %ebp,%ebx
je     11d0 <main+0xa0>
addss  %xmm0,%xmm0
jmp    11d0 <main+0xa0>
jmp    121e <main+0xee>
movss  0x4(%rsp),%xmm2
mulss  %xmm0,%xmm2
mulss  0xdda(%rip),%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
lea    0xe09(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
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 = [11 x i8] c"Result: %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 = %46, %0
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %49
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 %40
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 %40
35: ; preds = %31
%36 = load float, float* %5
%37 = call float @f(float %36)
%38 = load float, float* %6
%39 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %37, float %38)
store float %39, float* %6
br label %45
40: ; preds = %31, %23
%41 = load float, float* %5
%42 = call float @f(float %41)
%43 = load float, float* %6
%44 = fadd float %43, %42
store float %44, float* %6
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %19
49: ; preds = %19
%50 = load float, float* %6
%51 = load float, float* %4
%52 = fmul float %50, %51
%53 = fdiv float %52, 2.000000e+00
store float %53, float* %6
%54 = load float, float* %6
%55 = fpext float %54 to double
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double %55)
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 = [11 x i8] c"Result: %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 %38, label %18
18: ; preds = %0
%19 = call float @llvm.fmuladd.f32(float %16, float 0.000000e+00, float %12)
%20 = call float @f(float %19)
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %18, %23
%24 = phi i32 [ %36, %23 ], [ %21, %18 ]
%25 = phi float [ %35, %23 ], [ 0x7FF8000000000000, %18 ]
%26 = phi i32 [ %27, %23 ], [ 0, %18 ]
%27 = add nuw nsw i32 %26, 1
%28 = load float, float* %1
%29 = sitofp i32 %27 to float
%30 = call float @llvm.fmuladd.f32(float %29, float %16, float %28)
%31 = icmp eq i32 %27, %24
%32 = call float @f(float %30)
%33 = call float @llvm.fmuladd.f32(float %32, float 2.000000e+00, float %25)
%34 = fadd float %25, %32
%35 = select i1 %31, float %34, float %33
%36 = load i32, i32* %3
%37 = icmp slt i32 %27, %36
br i1 %37, label %23, label %38
38: ; preds = %23, %18, %0
%39 = phi float [ undef, %0 ], [ 0x7FF8000000000000, %18 ], [ %35, %23 ]
%40 = fmul float %16, %39
%41 = fmul float %40, 5.000000e-01
%42 = fpext float %41 to double
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double %42)
ret i32 0
}