#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)) / 2.0;
  x = a;
  for (i = 1; i <= n - 1; i++) {
    x = x + h;
    integral = integral + f(x);
  }
  integral = integral * h;
  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
cvtss2sd %xmm0,%xmm0
movsd  0xe52(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%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     121f <main+0xef>
movss  -0x1c(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cc <main+0x9c>
movss  -0x8(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdec(%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    0xde9(%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    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1060 <scanf@plt>
movss  0x14(%rsp),%xmm2
movss  0x18(%rsp),%xmm0
subss  %xmm0,%xmm2
cvtsi2ssl 0x10(%rsp),%xmm1
divss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
call   1040 <f@plt>
movss  %xmm0,0x8(%rsp)
movss  0x14(%rsp),%xmm0
call   1040 <f@plt>
addss  0x8(%rsp),%xmm0
mulss  0xe50(%rip),%xmm0
mov    0x10(%rsp),%esi
cmp    $0x2,%esi
jl     1211 <main+0xd1>
mov    $0x1,%ebx
movss  0x18(%rsp),%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm0,0x8(%rsp)
addss  0xc(%rsp),%xmm1
movss  %xmm1,0x1c(%rsp)
movaps %xmm1,%xmm0
call   1040 <f@plt>
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x1c(%rsp),%xmm1
movss  0x8(%rsp),%xmm0
add    $0x1,%ebx
mov    0x10(%rsp),%esi
cmp    %esi,%ebx
jl     11d0 <main+0x90>
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movss  0x18(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x14(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  0xc(%rsp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xddf(%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
%22 = fpext float %21 to double
%23 = fdiv double %22, 2.000000e+00
%24 = fptrunc double %23 to float
store float %24, float* %2
%25 = load float, float* %3
store float %25, float* %7
store i32 1, i32* %8
br label %26
26: ; preds = %39, %0
%27 = load i32, i32* %8
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = icmp sle i32 %27, %29
br i1 %30, label %31, label %42
31: ; preds = %26
%32 = load float, float* %7
%33 = load float, float* %6
%34 = fadd float %32, %33
store float %34, float* %7
%35 = load float, float* %2
%36 = load float, float* %7
%37 = call float @f(float %36)
%38 = fadd float %35, %37
store float %38, float* %2
br label %39
39: ; preds = %31
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %26
42: ; preds = %26
%43 = load float, float* %2
%44 = load float, float* %6
%45 = fmul float %43, %44
store float %45, float* %2
%46 = load i32, i32* %5
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = load float, float* %3
%49 = fpext float %48 to double
%50 = load float, float* %4
%51 = fpext float %50 to double
%52 = load float, float* %2
%53 = fpext float %52 to double
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %49, double %51, double %53)
%55 = load i32, i32* %1
ret i32 %55
}

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 = fmul float %18, 5.000000e-01
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %34
22: ; preds = %0
%23 = load float, float* %1
br label %24
24: ; preds = %22, %24
%25 = phi i32 [ %31, %24 ], [ 1, %22 ]
%26 = phi float [ %28, %24 ], [ %23, %22 ]
%27 = phi float [ %30, %24 ], [ %19, %22 ]
%28 = fadd float %14, %26
%29 = call float @f(float %28)
%30 = fadd float %27, %29
%31 = add nuw nsw i32 %25, 1
%32 = load i32, i32* %3
%33 = icmp slt i32 %31, %32
br i1 %33, label %24, label %34
34: ; preds = %24, %0
%35 = phi float [ %19, %0 ], [ %30, %24 ]
%36 = phi i32 [ %20, %0 ], [ %32, %24 ]
%37 = fmul float %14, %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%39 = load float, float* %1
%40 = fpext float %39 to double
%41 = load float, float* %2
%42 = fpext float %41 to double
%43 = fpext float %37 to double
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %40, double %42, double %43)
ret i32 0
}