#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 area(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  float h, b, a, sum = 0, area_sum = 0;
  int n;
  printf("Enter lower and upper bound: ");
  scanf("%f %f", &a, &b);
  float sum_const = area(a) + area(b);
  printf("Enter intervals: ");
  scanf("%d", &n);
  h = (b - a) / n;
  for (int i = 1; i < n; ++i)
    area_sum += area(a + i * h);
  sum = (h / 2) * (sum_const + 2 * area_sum);
  printf("Integrated value: %8.4f\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movss  -0x10(%rbp),%xmm0
call   1040 <area@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <area@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movss  -0xc(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121c <main+0xec>
movss  -0x10(%rbp),%xmm1
cvtsi2ssl -0x24(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <area@plt>
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11dc <main+0xac>
movss  -0x8(%rbp),%xmm0
movss  0xdd7(%rip),%xmm1
divss  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
addss  %xmm1,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde5(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed8(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0xc(%rsp),%xmm0
call   1040 <area@plt>
movss  %xmm0,0x18(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <area@plt>
movss  %xmm0,0x14(%rsp)
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x10(%rsp),%xmm2
movss  0xc(%rsp),%xmm0
mov    0x8(%rsp),%eax
cvtsi2ss %eax,%xmm1
subss  %xmm0,%xmm2
divss  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cmp    $0x2,%eax
jl     122d <main+0xfd>
movss  %xmm2,0x4(%rsp)
addss  %xmm2,%xmm0
call   1040 <area@plt>
xorps  %xmm1,%xmm1
addss  %xmm0,%xmm1
cmpl   $0x3,0x8(%rsp)
jl     1227 <main+0xf7>
mov    $0x2,%ebx
movss  0x4(%rsp),%xmm2
nopw   0x0(%rax,%rax,1)
movss  %xmm1,0x1c(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm2,%xmm0
addss  0xc(%rsp),%xmm0
call   1040 <area@plt>
movss  0x1c(%rsp),%xmm1
movss  0x4(%rsp),%xmm2
addss  %xmm0,%xmm1
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jl     11f0 <main+0xc0>
jmp    122d <main+0xfd>
movss  0x4(%rsp),%xmm2
movss  0x18(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
mulss  0xdbf(%rip),%xmm2
addss  %xmm1,%xmm1
addss  %xmm0,%xmm1
mulss  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xde2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter lower and upper bound: \00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [18 x i8] c"Enter intervals: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [25 x i8] c"Integrated value: %8.4f\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 i32
%8 = alloca float
%9 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %4, float* %3)
%12 = load float, float* %4
%13 = call float @area(float %12)
%14 = load float, float* %3
%15 = call float @area(float %14)
%16 = fadd float %13, %15
store float %16, float* %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%19 = load float, float* %3
%20 = load float, float* %4
%21 = fsub float %19, %20
%22 = load i32, i32* %7
%23 = sitofp i32 %22 to float
%24 = fdiv float %21, %23
store float %24, float* %2
store i32 1, i32* %9
br label %25
25: ; preds = %38, %0
%26 = load i32, i32* %9
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load float, float* %4
%31 = load i32, i32* %9
%32 = sitofp i32 %31 to float
%33 = load float, float* %2
%34 = call float @llvm.fmuladd.f32(float %32, float %33, float %30)
%35 = call float @area(float %34)
%36 = load float, float* %6
%37 = fadd float %36, %35
store float %37, float* %6
br label %38
38: ; preds = %29
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %25
41: ; preds = %25
%42 = load float, float* %2
%43 = fdiv float %42, 2.000000e+00
%44 = load float, float* %8
%45 = load float, float* %6
%46 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %45, float %44)
%47 = fmul float %43, %46
store float %47, float* %5
%48 = load float, float* %5
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter lower and upper bound: \00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [18 x i8] c"Enter intervals: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [25 x i8] c"Integrated value: %8.4f\0A\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 ([30 x i8], [30 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* %2, float* %1)
%9 = load float, float* %2
%10 = call float @area(float %9)
%11 = load float, float* %1
%12 = call float @area(float %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = load float, float* %1
%16 = load float, float* %2
%17 = fsub float %15, %16
%18 = load i32, i32* %3
%19 = sitofp i32 %18 to float
%20 = fdiv float %17, %19
%21 = icmp sgt i32 %18, 1
br i1 %21, label %22, label %28
22: ; preds = %0
%23 = fadd float %20, %16
%24 = call float @area(float %23)
%25 = fadd float %24, 0.000000e+00
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 2
br i1 %27, label %36, label %28
28: ; preds = %36, %22, %0
%29 = phi float [ 0.000000e+00, %0 ], [ %25, %22 ], [ %43, %36 ]
%30 = fadd float %10, %12
%31 = fmul float %20, 5.000000e-01
%32 = call float @llvm.fmuladd.f32(float %29, float 2.000000e+00, float %30)
%33 = fmul float %31, %32
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %34)
ret i32 0
36: ; preds = %22, %36
%37 = phi i32 [ %44, %36 ], [ 2, %22 ]
%38 = phi float [ %43, %36 ], [ %25, %22 ]
%39 = load float, float* %2
%40 = sitofp i32 %37 to float
%41 = call float @llvm.fmuladd.f32(float %40, float %20, float %39)
%42 = call float @area(float %41)
%43 = fadd float %38, %42
%44 = add nuw nsw i32 %37, 1
%45 = load i32, i32* %3
%46 = icmp slt i32 %44, %45
br i1 %46, label %36, label %28
}