#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 */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *, int *);
main() {
  float integral;
  float a, b;
  int n;
  float h;
  float x;
  int i;
  float f(float x);
  printf("Enter a, b, and n\n");
  scanf("%f %f %d", &a, &b, &n);
  h = (b - a) / n;
  integral = (f(a) + f(b));
  x = a;
  for (i = 1; i <= n - 1; i++) {
    x = x + h;
    integral = integral + (i % 2 ? 4 : 2) * f(x);
  }
  integral = integral * h / 3.0;
  printf("With n = %d trapezoids, our estimate\n", n);
  printf("of the integral from %f to %f = %f\n", a, b, integral);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1050 <scanf@plt>
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1238 <main+0x108>
movss  -0x1c(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x2,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1030 <f@plt>
movss  -0x2c(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x28(%rbp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b8 <main+0x88>
movss  -0x8(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdb2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0x8(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xdbc(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1060 <scanf@plt>
movss  0x10(%rsp),%xmm2
movss  0x14(%rsp),%xmm0
subss  %xmm0,%xmm2
cvtsi2ssl 0xc(%rsp),%xmm1
divss  %xmm1,%xmm2
movss  %xmm2,0x8(%rsp)
call   1040 <f@plt>
movss  %xmm0,0x4(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <f@plt>
addss  0x4(%rsp),%xmm0
mov    0xc(%rsp),%esi
cmp    $0x2,%esi
jl     121e <main+0xde>
mov    $0x1,%ebx
movss  0x14(%rsp),%xmm1
nopl   0x0(%rax)
movss  %xmm0,0x4(%rsp)
addss  0x8(%rsp),%xmm1
movss  %xmm1,0x1c(%rsp)
mov    %ebx,%eax
and    $0x1,%eax
add    %eax,%eax
add    $0x2,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x18(%rsp)
movaps %xmm1,%xmm0
call   1040 <f@plt>
mulss  0x18(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x1c(%rsp),%xmm1
movss  0x4(%rsp),%xmm0
add    $0x1,%ebx
mov    0xc(%rsp),%esi
cmp    %esi,%ebx
jl     11c0 <main+0x80>
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
divss  0xdd0(%rip),%xmm1
movss  %xmm1,0x8(%rsp)
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movss  0x14(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x10(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  0x8(%rsp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xdca(%rip),%rdi
mov    $0x3,%al
call   1050 <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 = [9 x i8] c"%f %f %d\00"
@.str.2 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@.str.3 = [36 x i8] c"of the integral from %f to %f = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float* %3, float* %4, i32* %5)
%11 = load float, float* %4
%12 = load float, float* %3
%13 = fsub float %11, %12
%14 = load i32, i32* %5
%15 = sitofp i32 %14 to float
%16 = fdiv float %13, %15
store float %16, float* %6
%17 = load float, float* %3
%18 = call float @f(float %17)
%19 = load float, float* %4
%20 = call float @f(float %19)
%21 = fadd float %18, %20
store float %21, float* %2
%22 = load float, float* %3
store float %22, float* %7
store i32 1, i32* %8
br label %23
23: ; preds = %42, %0
%24 = load i32, i32* %8
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = icmp sle i32 %24, %26
br i1 %27, label %28, label %45
28: ; preds = %23
%29 = load float, float* %7
%30 = load float, float* %6
%31 = fadd float %29, %30
store float %31, float* %7
%32 = load float, float* %2
%33 = load i32, i32* %8
%34 = srem i32 %33, 2
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 4, i32 2
%38 = sitofp i32 %37 to float
%39 = load float, float* %7
%40 = call float @f(float %39)
%41 = call float @llvm.fmuladd.f32(float %38, float %40, float %32)
store float %41, float* %2
br label %42
42: ; preds = %28
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %23
45: ; preds = %23
%46 = load float, float* %2
%47 = load float, float* %6
%48 = fmul float %46, %47
%49 = fpext float %48 to double
%50 = fdiv double %49, 3.000000e+00
%51 = fptrunc double %50 to float
store float %51, float* %2
%52 = load i32, i32* %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load float, float* %3
%55 = fpext float %54 to double
%56 = load float, float* %4
%57 = fpext float %56 to double
%58 = load float, float* %2
%59 = fpext float %58 to double
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %55, double %57, double %59)
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"%f %f %d\00"
@.str.2 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@.str.3 = [36 x i8] c"of the integral from %f to %f = %f\0A\00"
@str = [18 x i8] c"Enter a, b, and n\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2, i32* %3)
%9 = load float, float* %2
%10 = load float, float* %1
%11 = fsub float %9, %10
%12 = load i32, i32* %3
%13 = sitofp i32 %12 to float
%14 = fdiv float %11, %13
%15 = call float @f(float %10)
%16 = load float, float* %2
%17 = call float @f(float %16)
%18 = fadd float %15, %17
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %37
21: ; preds = %0
%22 = load float, float* %1
br label %23
23: ; preds = %21, %23
%24 = phi i32 [ %34, %23 ], [ 1, %21 ]
%25 = phi float [ %27, %23 ], [ %22, %21 ]
%26 = phi float [ %33, %23 ], [ %18, %21 ]
%27 = fadd float %14, %25
%28 = and i32 %24, 1
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i32 2, i32 4
%31 = sitofp i32 %30 to float
%32 = call float @f(float %27)
%33 = call float @llvm.fmuladd.f32(float %31, float %32, float %26)
%34 = add nuw nsw i32 %24, 1
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %23, label %37
37: ; preds = %23, %0
%38 = phi float [ %18, %0 ], [ %33, %23 ]
%39 = phi i32 [ %19, %0 ], [ %35, %23 ]
%40 = fmul float %14, %38
%41 = fdiv float %40, 3.000000e+00
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%43 = load float, float* %1
%44 = fpext float %43 to double
%45 = load float, float* %2
%46 = fpext float %45 to double
%47 = fpext float %41 to double
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %44, double %46, double %47)
ret i32 0
}