#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, s, h;
  int i, n;
  printf("Enter the value of n");
  scanf("%d", &n);
  printf("Enter the value of a and b");
  scanf("%f %f", &a, &b);
  s = 0;
  h = (b - a) / n;
  for (i = 0; i < n; i++) {
    s = s + (h / 2) * (f(a) + f(a + h));
    a = a + h;
  }
  printf("%f", s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1234 <main+0x104>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe33(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movss  -0x28(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
movaps %xmm0,%xmm3
movss  -0x20(%rbp),%xmm0
addss  %xmm3,%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11aa <main+0x7a>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xec8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x1c(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    121c <main+0xec>
movss  0x1c(%rsp),%xmm2
movss  0x4(%rsp),%xmm0
subss  %xmm0,%xmm2
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm2
movss  0xe56(%rip),%xmm1
movss  %xmm2,0x8(%rsp)
mulss  %xmm2,%xmm1
movss  %xmm1,0x10(%rsp)
xorps  %xmm1,%xmm1
nopl   (%rax)
movss  %xmm1,0x18(%rsp)
call   1030 <f@plt>
movss  %xmm0,0x14(%rsp)
movss  0x4(%rsp),%xmm0
addss  0x8(%rsp),%xmm0
call   1030 <f@plt>
movss  0x18(%rsp),%xmm1
addss  0x14(%rsp),%xmm0
mulss  0x10(%rsp),%xmm0
addss  %xmm0,%xmm1
movss  0x4(%rsp),%xmm0
addss  0x8(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     11c0 <main+0x90>
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
jmp    121f <main+0xef>
xorps  %xmm0,%xmm0
lea    0xe14(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter the value of n\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Enter the value of a and b\00"
@.str.3 = [6 x i8] c"%f %f\00"
@.str.4 = [3 x i8] c"%f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), float* %2, float* %3)
store float 0.000000e+00, float* %4
%12 = load float, float* %3
%13 = load float, float* %2
%14 = fsub float %12, %13
%15 = load i32, i32* %7
%16 = sitofp i32 %15 to float
%17 = fdiv float %14, %16
store float %17, float* %5
store i32 0, i32* %6
br label %18
18: ; preds = %37, %0
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load float, float* %4
%24 = load float, float* %5
%25 = fdiv float %24, 2.000000e+00
%26 = load float, float* %2
%27 = call float @f(float %26)
%28 = load float, float* %2
%29 = load float, float* %5
%30 = fadd float %28, %29
%31 = call float @f(float %30)
%32 = fadd float %27, %31
%33 = call float @llvm.fmuladd.f32(float %25, float %32, float %23)
store float %33, float* %4
%34 = load float, float* %2
%35 = load float, float* %5
%36 = fadd float %34, %35
store float %36, float* %2
br label %37
37: ; preds = %22
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %18
40: ; preds = %18
%41 = load float, float* %4
%42 = fpext float %41 to double
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %42)
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter the value of n\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Enter the value of a and b\00"
@.str.3 = [6 x i8] c"%f %f\00"
@.str.4 = [3 x i8] c"%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 ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), float* %1, float* %2)
%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 sgt i32 %14, 0
br i1 %17, label %18, label %37
18: ; preds = %0
%19 = fmul float %16, 5.000000e-01
br label %20
20: ; preds = %18, %20
%21 = phi float [ %12, %18 ], [ %31, %20 ]
%22 = phi i32 [ 0, %18 ], [ %32, %20 ]
%23 = phi float [ 0.000000e+00, %18 ], [ %29, %20 ]
%24 = call float @f(float %21)
%25 = load float, float* %1
%26 = fadd float %16, %25
%27 = call float @f(float %26)
%28 = fadd float %24, %27
%29 = call float @llvm.fmuladd.f32(float %19, float %28, float %23)
%30 = load float, float* %1
%31 = fadd float %16, %30
store float %31, float* %1
%32 = add nuw nsw i32 %22, 1
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %20, label %35
35: ; preds = %20
%36 = fpext float %29 to double
br label %37
37: ; preds = %35, %0
%38 = phi double [ 0.000000e+00, %0 ], [ %36, %35 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %38)
ret i32 0
}