#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 lower_limit, upper_limit, h, sum_even = 0, sum_odd = 0;
  int n;
  printf("Enter lower and upper limit: ");
  scanf("%f %f", &lower_limit, &upper_limit);
  float sum_const = area(lower_limit) + area(upper_limit);
  printf("Enter intervals: ");
  scanf("%d", &n);
  h = (upper_limit - lower_limit) / n;
  for (int i = 1; i < n; i += 2)
    sum_odd += area(lower_limit + i * h);
  for (int i = 2; i < n - 1; i += 2)
    sum_even += area(lower_limit + i * h);
  float sum = (h / 3) * (sum_const + 4 * sum_odd + 2 * sum_even);
  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    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movss  -0x8(%rbp),%xmm0
call   1040 <area@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <area@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8c(%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   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121c <main+0xec>
movss  -0x8(%rbp),%xmm1
cvtsi2ssl -0x24(%rbp),%xmm0
movss  -0x10(%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    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    11dc <main+0xac>
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1268 <main+0x138>
movss  -0x8(%rbp),%xmm1
cvtsi2ssl -0x28(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <area@plt>
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
jmp    1223 <main+0xf3>
movss  -0x10(%rbp),%xmm0
movss  0xd8f(%rip),%xmm1
divss  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
movss  0xd75(%rip),%xmm3
mulss  %xmm3,%xmm2
addss  %xmm1,%xmm2
movss  -0x14(%rbp),%xmm1
addss  %xmm1,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd88(%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    0xecc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x4(%rsp),%xmm0
call   1040 <area@plt>
movss  %xmm0,0x18(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <area@plt>
movss  %xmm0,0x14(%rsp)
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x10(%rsp),%xmm2
movss  0x4(%rsp),%xmm0
subss  %xmm0,%xmm2
mov    (%rsp),%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm2
xorps  %xmm1,%xmm1
xorps  %xmm3,%xmm3
cmp    $0x2,%eax
jl     1284 <main+0x154>
movss  %xmm2,0xc(%rsp)
addss  %xmm2,%xmm0
call   1040 <area@plt>
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
addss  %xmm0,%xmm1
mov    (%rsp),%eax
cmp    $0x4,%eax
jl     1222 <main+0xf2>
mov    $0x3,%ebx
nopl   0x0(%rax)
movss  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  0xc(%rsp),%xmm0
addss  0x4(%rsp),%xmm0
call   1040 <area@plt>
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
add    $0x2,%ebx
mov    (%rsp),%eax
cmp    %eax,%ebx
jl     11f0 <main+0xc0>
cmp    $0x4,%eax
movss  0xc(%rsp),%xmm2
jl     1281 <main+0x151>
movss  %xmm1,0x8(%rsp)
mov    $0x2,%ebx
xorps  %xmm3,%xmm3
nopl   0x0(%rax,%rax,1)
movss  %xmm3,0x1c(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm2,%xmm0
addss  0x4(%rsp),%xmm0
call   1040 <area@plt>
movss  0x1c(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
addss  %xmm0,%xmm3
add    $0x2,%ebx
mov    (%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebx
jl     1240 <main+0x110>
movss  0x8(%rsp),%xmm1
jmp    1284 <main+0x154>
xorps  %xmm3,%xmm3
divss  0xd74(%rip),%xmm2
movss  0x18(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
mulss  0xd64(%rip),%xmm1
addss  %xmm0,%xmm1
addss  %xmm3,%xmm3
addss  %xmm1,%xmm3
mulss  %xmm2,%xmm3
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
lea    0xd83(%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 limit: \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
%10 = alloca i32
%11 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3)
%14 = load float, float* %2
%15 = call float @area(float %14)
%16 = load float, float* %3
%17 = call float @area(float %16)
%18 = fadd float %15, %17
store float %18, float* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%21 = load float, float* %3
%22 = load float, float* %2
%23 = fsub float %21, %22
%24 = load i32, i32* %7
%25 = sitofp i32 %24 to float
%26 = fdiv float %23, %25
store float %26, float* %4
store i32 1, i32* %9
br label %27
27: ; preds = %40, %0
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load float, float* %2
%33 = load i32, i32* %9
%34 = sitofp i32 %33 to float
%35 = load float, float* %4
%36 = call float @llvm.fmuladd.f32(float %34, float %35, float %32)
%37 = call float @area(float %36)
%38 = load float, float* %6
%39 = fadd float %38, %37
store float %39, float* %6
br label %40
40: ; preds = %31
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 2
store i32 %42, i32* %9
br label %27
43: ; preds = %27
store i32 2, i32* %10
br label %44
44: ; preds = %58, %43
%45 = load i32, i32* %10
%46 = load i32, i32* %7
%47 = sub nsw i32 %46, 1
%48 = icmp slt i32 %45, %47
br i1 %48, label %49, label %61
49: ; preds = %44
%50 = load float, float* %2
%51 = load i32, i32* %10
%52 = sitofp i32 %51 to float
%53 = load float, float* %4
%54 = call float @llvm.fmuladd.f32(float %52, float %53, float %50)
%55 = call float @area(float %54)
%56 = load float, float* %5
%57 = fadd float %56, %55
store float %57, float* %5
br label %58
58: ; preds = %49
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 2
store i32 %60, i32* %10
br label %44
61: ; preds = %44
%62 = load float, float* %4
%63 = fdiv float %62, 3.000000e+00
%64 = load float, float* %8
%65 = load float, float* %6
%66 = call float @llvm.fmuladd.f32(float 4.000000e+00, float %65, float %64)
%67 = load float, float* %5
%68 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %67, float %66)
%69 = fmul float %63, %68
store float %69, float* %11
%70 = load float, float* %11
%71 = fpext float %70 to double
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter lower and upper limit: \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* %1, float* %2)
%9 = load float, float* %1
%10 = call float @area(float %9)
%11 = load float, float* %2
%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* %2
%16 = load float, float* %1
%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 %43
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, 3
br i1 %27, label %32, label %28
28: ; preds = %32, %22
%29 = phi float [ %25, %22 ], [ %39, %32 ]
%30 = phi i32 [ %26, %22 ], [ %41, %32 ]
%31 = icmp sgt i32 %30, 3
br i1 %31, label %53, label %43
32: ; preds = %22, %32
%33 = phi i32 [ %40, %32 ], [ 3, %22 ]
%34 = phi float [ %39, %32 ], [ %25, %22 ]
%35 = load float, float* %1
%36 = sitofp i32 %33 to float
%37 = call float @llvm.fmuladd.f32(float %36, float %20, float %35)
%38 = call float @area(float %37)
%39 = fadd float %34, %38
%40 = add nuw nsw i32 %33, 2
%41 = load i32, i32* %3
%42 = icmp slt i32 %40, %41
br i1 %42, label %32, label %28
43: ; preds = %53, %0, %28
%44 = phi float [ %29, %28 ], [ 0.000000e+00, %0 ], [ %29, %53 ]
%45 = phi float [ 0.000000e+00, %28 ], [ 0.000000e+00, %0 ], [ %60, %53 ]
%46 = fadd float %10, %12
%47 = fdiv float %20, 3.000000e+00
%48 = call float @llvm.fmuladd.f32(float %44, float 4.000000e+00, float %46)
%49 = call float @llvm.fmuladd.f32(float %45, float 2.000000e+00, float %48)
%50 = fmul float %47, %49
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %51)
ret i32 0
53: ; preds = %28, %53
%54 = phi float [ %60, %53 ], [ 0.000000e+00, %28 ]
%55 = phi i32 [ %61, %53 ], [ 2, %28 ]
%56 = load float, float* %1
%57 = sitofp i32 %55 to float
%58 = call float @llvm.fmuladd.f32(float %57, float %20, float %56)
%59 = call float @area(float %58)
%60 = fadd float %54, %59
%61 = add nuw nsw i32 %55, 2
%62 = load i32, i32* %3
%63 = add nsw i32 %62, -1
%64 = icmp slt i32 %61, %63
br i1 %64, label %53, label %43
}