#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 Simp(double, double, int, double);
double Trap(double, double, int, double);
int fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  double area, area2;
  double a, b;
  int n;
  double h;
  printf("Enter a, b, and n\n");
  scanf("%lf", &a);
  scanf("%lf", &b);
  scanf("%d", &n);
  h = (b - a) / n;
  area = Trap(a, b, n, h);
  if (n % 2 == 0) {
    area2 = Simp(a, b, n, h);
    printf("With n = %d parabolas, our estimate\n", n);
    printf("of the area from %f to %f = %.15f\n", a, b, area2);
    double abs = area - area2;
    int num = fabs(abs);
    printf("The absolute vale of the difference between %f and %f is %d.", area,
           area2, num);
  }
  printf("With n = %d trapezoids, our estimate\n", n);
  printf("of the area from %f to %f = %.15f\n", a, b, area);
  main();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xe7d(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xe6f(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x2c(%rbp),%edi
movsd  -0x38(%rbp),%xmm2
call   1060 <Trap@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    127c <main+0x11c>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x2c(%rbp),%edi
movsd  -0x38(%rbp),%xmm2
call   1030 <Simp@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xe01(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <fabs@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x44(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    0xd9c(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
call   1070 <main@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rbx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0xe57(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
mov    0xc(%rsp),%edi
cvtsi2sd %edi,%xmm3
divsd  %xmm3,%xmm2
movsd  %xmm2,0x10(%rsp)
call   1070 <Trap@plt>
movsd  %xmm0,0x28(%rsp)
mov    0xc(%rsp),%esi
test   $0x1,%sil
jne    127a <main+0x10a>
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mov    %esi,%edi
movsd  0x10(%rsp),%xmm2
call   1040 <Simp@plt>
movsd  %xmm0,0x10(%rsp)
mov    0xc(%rsp),%esi
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0xdf0(%rip),%rdi
movsd  0x10(%rsp),%xmm2
mov    $0x3,%al
call   1050 <printf@plt>
movsd  0x28(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
call   1060 <fabs@plt>
lea    0xdee(%rip),%rdi
movsd  0x28(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %eax,%esi
mov    $0x2,%al
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe0b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0xd91(%rip),%rdi
movsd  0x28(%rsp),%xmm2
mov    $0x3,%al
call   1050 <printf@plt>
call   1080 <main@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter a, b, and n\0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [37 x i8] c"With n = %d parabolas, our estimate\0A\00"
@.str.4 = [35 x i8] c"of the area from %f to %f = %.15f\0A\00"
@.str.5 = [61 x i8] c"The absolute vale of the difference between %f and %f is %d.\00"
@.str.6 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %5)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%14 = load double, double* %5
%15 = load double, double* %4
%16 = fsub double %14, %15
%17 = load i32, i32* %6
%18 = sitofp i32 %17 to double
%19 = fdiv double %16, %18
store double %19, double* %7
%20 = load double, double* %4
%21 = load double, double* %5
%22 = load i32, i32* %6
%23 = load double, double* %7
%24 = call double @Trap(double %20, double %21, i32 %22, double %23)
store double %24, double* %2
%25 = load i32, i32* %6
%26 = srem i32 %25, 2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %49
28: ; preds = %0
%29 = load double, double* %4
%30 = load double, double* %5
%31 = load i32, i32* %6
%32 = load double, double* %7
%33 = call double @Simp(double %29, double %30, i32 %31, double %32)
store double %33, double* %3
%34 = load i32, i32* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load double, double* %4
%37 = load double, double* %5
%38 = load double, double* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %36, double %37, double %38)
%40 = load double, double* %2
%41 = load double, double* %3
%42 = fsub double %40, %41
store double %42, double* %8
%43 = load double, double* %8
%44 = call i32 @fabs(double %43)
store i32 %44, i32* %9
%45 = load double, double* %2
%46 = load double, double* %3
%47 = load i32, i32* %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), double %45, double %46, i32 %47)
br label %49
49: ; preds = %28, %0
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = load double, double* %4
%53 = load double, double* %5
%54 = load double, double* %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %52, double %53, double %54)
%56 = call i32 @main()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [37 x i8] c"With n = %d parabolas, our estimate\0A\00"
@.str.4 = [35 x i8] c"of the area from %f to %f = %.15f\0A\00"
@.str.5 = [61 x i8] c"The absolute vale of the difference between %f and %f is %d.\00"
@.str.6 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@str = [18 x i8] c"Enter a, b, and n\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = bitcast double* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%11 = load double, double* %2
%12 = load double, double* %1
%13 = fsub double %11, %12
%14 = load i32, i32* %3
%15 = sitofp i32 %14 to double
%16 = fdiv double %13, %15
%17 = call double @Trap(double %12, double %11, i32 %14, double %16)
%18 = load i32, i32* %3
%19 = and i32 %18, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %0
%22 = load double, double* %1
%23 = load double, double* %2
%24 = call double @Simp(double %22, double %23, i32 %18, double %16)
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load double, double* %1
%28 = load double, double* %2
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %27, double %28, double %24)
%30 = fsub double %17, %24
%31 = call i32 @fabs(double %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), double %17, double %24, i32 %31)
%33 = load i32, i32* %3
br label %34
34: ; preds = %21, %0
%35 = phi i32 [ %33, %21 ], [ %18, %0 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = load double, double* %1
%38 = load double, double* %2
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %37, double %38, double %17)
%40 = call i32 @main()
ret i32 0
}