#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 */
double fnAreaTrapezoid(double, double, double);
double log(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *, ...);
int main(void) {
  double i, dDx = 0.1, dX1, dX2, dY1, dY2;
  double dLeft, dRight, dArea = 0.0, dTotArea = 0.0;
  printf("\nEnter the left and right limit\n");
  scanf("%lf%lf", &dLeft, &dRight);
  printf("\nEnter the increment dx\n");
  scanf("%lf", &dDx);
  for (i = dLeft; i < dRight; i += dDx) {
    dX1 = i;
    dX2 = i + dDx;
    dY1 = log(dX1);
    dY2 = log(dX2);
    dArea = fnAreaTrapezoid(dY1, dY2, dDx);
    dTotArea += dArea;
  }
  printf("\nArea under the curve is %lf units\n", dTotArea);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1241 <main+0x101>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1030 <fnAreaTrapezoid@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11ba <main+0x7a>
movsd  -0x58(%rbp),%xmm0
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
movabs $0x3fb999999999999a,%rax
99 b9 3f
mov    %rax,(%rsp)
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8b(%rip),%rdi
lea    0x30(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movsd  0x30(%rsp),%xmm2
movsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm0
jbe    1238 <main+0xe8>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x28(%rsp)
addsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
movapd %xmm2,%xmm0
call   1070 <log@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm1
movsd  (%rsp),%xmm2
movsd  0x18(%rsp),%xmm0
call   1040 <fnAreaTrapezoid@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  (%rsp),%xmm3
addsd  %xmm3,%xmm2
movsd  0x8(%rsp),%xmm0
ucomisd %xmm2,%xmm0
ja     11d0 <main+0x80>
lea    0xdc8(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0AEnter the left and right limit\0A\00"
@.str.1 = [7 x i8] c"%lf%lf\00"
@.str.2 = [25 x i8] c"\0AEnter the increment dx\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [36 x i8] c"\0AArea under the curve is %lf units\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 0, i32* %1
store double 1.000000e-01, double* %3
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, double*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double* %8, double* %9)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, double*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %3)
%16 = load double, double* %8
store double %16, double* %2
br label %17
17: ; preds = %37, %0
%18 = load double, double* %2
%19 = load double, double* %9
%20 = fcmp olt double %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = load double, double* %2
store double %22, double* %4
%23 = load double, double* %2
%24 = load double, double* %3
%25 = fadd double %23, %24
store double %25, double* %5
%26 = load double, double* %4
%27 = call double @log(double %26)
store double %27, double* %6
%28 = load double, double* %5
%29 = call double @log(double %28)
store double %29, double* %7
%30 = load double, double* %6
%31 = load double, double* %7
%32 = load double, double* %3
%33 = call double @fnAreaTrapezoid(double %30, double %31, double %32)
store double %33, double* %10
%34 = load double, double* %10
%35 = load double, double* %11
%36 = fadd double %35, %34
store double %36, double* %11
br label %37
37: ; preds = %21
%38 = load double, double* %3
%39 = load double, double* %2
%40 = fadd double %39, %38
store double %40, double* %2
br label %17
41: ; preds = %17
%42 = load double, double* %11
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %42)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%lf%lf\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [36 x i8] c"\0AArea under the curve is %lf units\0A\00"
@str = [32 x i8] c"\0AEnter the left and right limit\00"
@str.5 = [24 x i8] c"\0AEnter the increment dx\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = bitcast double* %1 to i8*
store double 1.000000e-01, double* %1
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%8 = call i32 (i8*, double*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double* %2, double* %3)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%10 = call i32 (i8*, double*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %1)
%11 = load double, double* %2
%12 = load double, double* %3
%13 = fcmp olt double %11, %12
br i1 %13, label %14, label %30
14: ; preds = %0
%15 = load double, double* %1
br label %16
16: ; preds = %14, %16
%17 = phi double [ %26, %16 ], [ %15, %14 ]
%18 = phi double [ %25, %16 ], [ 0.000000e+00, %14 ]
%19 = phi double [ %27, %16 ], [ %11, %14 ]
%20 = fadd double %19, %17
%21 = call double @log(double %19)
%22 = call double @log(double %20)
%23 = load double, double* %1
%24 = call double @fnAreaTrapezoid(double %21, double %22, double %23)
%25 = fadd double %18, %24
%26 = load double, double* %1
%27 = fadd double %19, %26
%28 = load double, double* %3
%29 = fcmp olt double %27, %28
br i1 %29, label %16, label %30
30: ; preds = %16, %0
%31 = phi double [ 0.000000e+00, %0 ], [ %25, %16 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %31)
ret i32 0
}