#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 Trap(double, double, int, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  double integral;
  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;
  integral = Trap(a, b, n, h);
  printf("With n = %d trapezoids, our estimate\n", n);
  printf("of the integral from %f to %f = %.15f\n", a, b, integral);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xead(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe9f(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%edi
movsd  -0x30(%rbp),%xmm2
call   1040 <Trap@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    0xe62(%rip),%rdi
mov    $0x3,%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    0xf08(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe87(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
mov    0x4(%rsp),%edi
cvtsi2sd %edi,%xmm3
divsd  %xmm3,%xmm2
call   1050 <Trap@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x4(%rsp),%esi
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
lea    0xe54(%rip),%rdi
movsd  0x18(%rsp),%xmm2
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%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 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@.str.4 = [39 x i8] c"of the integral from %f to %f = %.15f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 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* %3)
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%11 = load double, double* %4
%12 = load double, double* %3
%13 = fsub double %11, %12
%14 = load i32, i32* %5
%15 = sitofp i32 %14 to double
%16 = fdiv double %13, %15
store double %16, double* %6
%17 = load double, double* %3
%18 = load double, double* %4
%19 = load i32, i32* %5
%20 = load double, double* %6
%21 = call double @Trap(double %17, double %18, i32 %19, double %20)
store double %21, double* %2
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load double, double* %3
%25 = load double, double* %4
%26 = load double, double* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), double %24, double %25, double %26)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@.str.4 = [39 x i8] c"of the integral from %f to %f = %.15f\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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load double, double* %1
%21 = load double, double* %2
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), double %20, double %21, double %17)
ret i32 0
}