#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 fabs(double);
scalar_t__ fu(int, double);
double rectangles(int f, double n, double a, double h) {
  double s = 0.0;
  int token = 0;
  while (token < n) {
    s += fu(f, (a + h * token));
    token++;
  }
  return (fabs((h * s) - 1.0));
}


x86 assembly (clang, -O0):
<rectangles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1189 <rectangles+0x79>
mov    -0x4(%rbp),%edi
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <fu@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1139 <rectangles+0x29>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe71(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps 0xe56(%rip),%xmm1
pand   %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rectangles>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm0
jbe    1199 <rectangles+0x89>
movapd %xmm0,%xmm3
mov    %edi,%ebx
xorpd  %xmm0,%xmm0
mov    $0x1,%ebp
xorpd  %xmm4,%xmm4
movapd %xmm2,0x20(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm4,0x18(%rsp)
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    %ebx,%edi
call   1030 <fu@plt>
movsd  0x18(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movapd 0x20(%rsp),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm1,%xmm4
movsd  0x10(%rsp),%xmm1
add    $0x1,%ebp
ucomisd %xmm0,%xmm3
ja     1150 <rectangles+0x40>
mulsd  %xmm4,%xmm2
addsd  0xe5b(%rip),%xmm2
andpd  0xe63(%rip),%xmm2
movapd %xmm2,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @rectangles(i32 %0, double %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store double 0.000000e+00, double* %9
store i32 0, i32* %10
br label %11
11: ; preds = %16, %4
%12 = load i32, i32* %10
%13 = sitofp i32 %12 to double
%14 = load double, double* %6
%15 = fcmp olt double %13, %14
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i32, i32* %5
%18 = load double, double* %7
%19 = load double, double* %8
%20 = load i32, i32* %10
%21 = sitofp i32 %20 to double
%22 = call double @llvm.fmuladd.f64(double %19, double %21, double %18)
%23 = call i64 @fu(i32 %17, double %22)
%24 = sitofp i64 %23 to double
%25 = load double, double* %9
%26 = fadd double %25, %24
store double %26, double* %9
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
store i32 %28, i32* %10
br label %11
29: ; preds = %11
%30 = load double, double* %8
%31 = load double, double* %9
%32 = call double @llvm.fmuladd.f64(double %30, double %31, double -1.000000e+00)
%33 = call double @llvm.fabs.f64(double %32)
ret double %33
}

LLVM IR (-O2):
define double @rectangles(i32 %0, double %1, double %2, double %3) {
%5 = fcmp ogt double %1, 0.000000e+00
br i1 %5, label %6, label %17
6: ; preds = %4, %6
%7 = phi double [ %15, %6 ], [ 0.000000e+00, %4 ]
%8 = phi i32 [ %14, %6 ], [ 0, %4 ]
%9 = phi double [ %13, %6 ], [ 0.000000e+00, %4 ]
%10 = tail call double @llvm.fmuladd.f64(double %3, double %7, double %2)
%11 = tail call i64 @fu(i32 %0, double %10)
%12 = sitofp i64 %11 to double
%13 = fadd double %9, %12
%14 = add nuw nsw i32 %8, 1
%15 = sitofp i32 %14 to double
%16 = fcmp olt double %15, %1
br i1 %16, label %6, label %17
17: ; preds = %6, %4
%18 = phi double [ 0.000000e+00, %4 ], [ %13, %6 ]
%19 = tail call double @llvm.fmuladd.f64(double %3, double %18, double -1.000000e+00)
%20 = tail call double @llvm.fabs.f64(double %19)
ret double %20
}