#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(float);
int /*<<< orphan*/ polint(float *, float *, double, float *, float *);
int /*<<< orphan*/ printf(char *);
float trapzd(float (*)(float, void *), float, float, int, void *);
float qromb(float (*func)(float, void *), float a, float b, void *params) {
  float ss, dss;
  float s[(20 + 1)], h[(20 + 1) + 1];
  int j;
  h[0] = 1.0;
  for (j = 0; j != 20; j++) {
    s[j] = trapzd(func, a, b, j + 1, params);
    if (j > 5) {
      polint(&h[j - 5], &s[j - 5], 0.0, &ss, &dss);
      if (fabs(dss) <= 1.0e-6 * fabs(ss))
        return (ss);
      if (fabs(ss) < 1.0e-14) {
        printf("Value of function within rounding errors\n");
        return (0.0);
      }
    }
    h[j + 1] = 0.25 * h[j];
  }
  printf("Too many steps in function qromb\n");
  return (0.0);
}


x86 assembly (clang, -O0):
<qromb>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
movss  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movss  0xe9b(%rip),%xmm0
movss  %xmm0,-0xe0(%rbp)
ff
movl   $0x0,-0xe4(%rbp)
cmpl   $0x14,-0xe4(%rbp)
je     12d2 <qromb+0x192>
mov    -0x10(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mov    -0xe4(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rdx
call   1040 <trapzd@plt>
movslq -0xe4(%rbp),%rax
movss  %xmm0,-0x80(%rbp,%rax,4)
cmpl   $0x5,-0xe4(%rbp)
jle    1286 <qromb+0x146>
mov    -0xe4(%rbp),%eax
sub    $0x5,%eax
cltq
lea    -0xe0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xe4(%rbp),%eax
sub    $0x5,%eax
cltq
lea    -0x80(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
xorps  %xmm0,%xmm0
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1060 <polint@plt>
movss  -0x28(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,-0xf0(%rbp)
ff
movss  -0x24(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  -0xf0(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  0xddc(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1249 <qromb+0x109>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12e6 <qromb+0x1a6>
movss  -0x24(%rbp),%xmm0
call   1050 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xdb2(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1281 <qromb+0x141>
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12e6 <qromb+0x1a6>
jmp    1286 <qromb+0x146>
movslq -0xe4(%rbp),%rax
movss  -0xe0(%rbp,%rax,4),%xmm0
ff ff
cvtss2sd %xmm0,%xmm1
movsd  0xd76(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
cltq
movss  %xmm0,-0xe0(%rbp,%rax,4)
ff ff
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    1177 <qromb+0x37>
lea    0xd71(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qromb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%r14
movss  %xmm1,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
mov    %rdi,%rbx
movl   $0x3f800000,0x20(%rsp)
3f
mov    $0xffffffffffffffec,%r15
xor    %ebp,%ebp
lea    0x14(%rsp),%r13
jmp    11a5 <qromb+0x65>
nopl   0x0(%rax,%rax,1)
movss  0x20(%rsp,%rbp,4),%xmm0
mulss  0xe82(%rip),%xmm0
movss  %xmm0,0x24(%rsp,%rbp,4)
add    $0x4,%r15
mov    %r12,%rbp
cmp    $0x14,%r12
je     1245 <qromb+0x105>
lea    0x1(%rbp),%r12
mov    %rbx,%rdi
movss  0xc(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
mov    %r12d,%esi
mov    %r14,%rdx
call   1040 <trapzd@plt>
movss  %xmm0,0x80(%rsp,%rbp,4)
cmp    $0x6,%rbp
jb     1180 <qromb+0x40>
lea    (%rsp,%r15,1),%rdi
add    $0x20,%rdi
lea    0x80(%rsp,%r15,1),%rsi
xorpd  %xmm0,%xmm0
lea    0x8(%rsp),%rdx
mov    %r13,%rcx
call   1060 <polint@plt>
movss  0x14(%rsp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,0x18(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
mulsd  0xde9(%rip),%xmm0
ucomisd 0x18(%rsp),%xmm0
movss  0x8(%rsp),%xmm0
jae    1254 <qromb+0x114>
call   1050 <fabs@plt>
movsd  0xdd6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1180 <qromb+0x40>
lea    0xdf2(%rip),%rdi
jmp    124c <qromb+0x10c>
lea    0xdc8(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Value of function within rounding errors\0A\00"
@.str.1 = [34 x i8] c"Too many steps in function qromb\0A\00"
define float @qromb(float (float, i8*)* %0, float %1, float %2, i8* %3) {
%5 = alloca float
%6 = alloca float (float, i8*)*
%7 = alloca float
%8 = alloca float
%9 = alloca i8*
%10 = alloca float
%11 = alloca float
%12 = alloca [21 x float]
%13 = alloca [22 x float]
%14 = alloca i32
store float (float, i8*)* %0, float (float, i8*)** %6
store float %1, float* %7
store float %2, float* %8
store i8* %3, i8** %9
%15 = getelementptr inbounds [22 x float], [22 x float]* %13, i64 0, i64 0
store float 1.000000e+00, float* %15
store i32 0, i32* %14
br label %16
16: ; preds = %69, %4
%17 = load i32, i32* %14
%18 = icmp ne i32 %17, 20
br i1 %18, label %19, label %72
19: ; preds = %16
%20 = load float (float, i8*)*, float (float, i8*)** %6
%21 = load float, float* %7
%22 = load float, float* %8
%23 = load i32, i32* %14
%24 = add nsw i32 %23, 1
%25 = load i8*, i8** %9
%26 = call float @trapzd(float (float, i8*)* %20, float %21, float %22, i32 %24, i8* %25)
%27 = load i32, i32* %14
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [21 x float], [21 x float]* %12, i64 0, i64 %28
store float %26, float* %29
%30 = load i32, i32* %14
%31 = icmp sgt i32 %30, 5
br i1 %31, label %32, label %57
32: ; preds = %19
%33 = load i32, i32* %14
%34 = sub nsw i32 %33, 5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [22 x float], [22 x float]* %13, i64 0, i64 %35
%37 = load i32, i32* %14
%38 = sub nsw i32 %37, 5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [21 x float], [21 x float]* %12, i64 0, i64 %39
%41 = call i32 @polint(float* %36, float* %40, double 0.000000e+00, float* %10, float* %11)
%42 = load float, float* %11
%43 = call double @fabs(float %42)
%44 = load float, float* %10
%45 = call double @fabs(float %44)
%46 = fmul double 0x3EB0C6F7A0B5ED8D, %45
%47 = fcmp ole double %43, %46
br i1 %47, label %48, label %50
48: ; preds = %32
%49 = load float, float* %10
store float %49, float* %5
br label %74
50: ; preds = %32
%51 = load float, float* %10
%52 = call double @fabs(float %51)
%53 = fcmp olt double %52, 0x3D06849B86A12B9B
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store float 0.000000e+00, float* %5
br label %74
56: ; preds = %50
br label %57
57: ; preds = %56, %19
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [22 x float], [22 x float]* %13, i64 0, i64 %59
%61 = load float, float* %60
%62 = fpext float %61 to double
%63 = fmul double 2.500000e-01, %62
%64 = fptrunc double %63 to float
%65 = load i32, i32* %14
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [22 x float], [22 x float]* %13, i64 0, i64 %67
store float %64, float* %68
br label %69
69: ; preds = %57
%70 = load i32, i32* %14
%71 = add nsw i32 %70, 1
store i32 %71, i32* %14
br label %16
72: ; preds = %16
%73 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store float 0.000000e+00, float* %5
br label %74
74: ; preds = %72, %54, %48
%75 = load float, float* %5
ret float %75
}

LLVM IR (-O2):
@str = [33 x i8] c"Too many steps in function qromb\00"
@str.2 = [41 x i8] c"Value of function within rounding errors\00"
define float @qromb(float (float, i8*)* %0, float %1, float %2, i8* %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca [21 x float]
%8 = alloca [22 x float]
%9 = bitcast float* %5 to i8*
%10 = bitcast float* %6 to i8*
%11 = bitcast [21 x float]* %7 to i8*
%12 = bitcast [22 x float]* %8 to i8*
%13 = getelementptr inbounds [22 x float], [22 x float]* %8, i64 0, i64 0
store float 1.000000e+00, float* %13
br label %14
14: ; preds = %4, %36
%15 = phi i64 [ 0, %4 ], [ %16, %36 ]
%16 = add nuw nsw i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call float @trapzd(float (float, i8*)* %0, float %1, float %2, i32 %17, i8* %3)
%19 = getelementptr inbounds [21 x float], [21 x float]* %7, i64 0, i64 %15
store float %18, float* %19
%20 = icmp ugt i64 %15, 5
br i1 %20, label %21, label %36
21: ; preds = %14
%22 = add nsw i64 %15, -5
%23 = getelementptr inbounds [22 x float], [22 x float]* %8, i64 0, i64 %22
%24 = getelementptr inbounds [21 x float], [21 x float]* %7, i64 0, i64 %22
%25 = call i32 @polint(float* %23, float* %24, double 0.000000e+00, float* %5, float* %6)
%26 = load float, float* %6
%27 = call double @fabs(float %26)
%28 = load float, float* %5
%29 = call double @fabs(float %28)
%30 = fmul double %29, 0x3EB0C6F7A0B5ED8D
%31 = fcmp ugt double %27, %30
%32 = load float, float* %5
br i1 %31, label %33, label %45
33: ; preds = %21
%34 = call double @fabs(float %32)
%35 = fcmp olt double %34, 0x3D06849B86A12B9B
br i1 %35, label %42, label %36
36: ; preds = %33, %14
%37 = getelementptr inbounds [22 x float], [22 x float]* %8, i64 0, i64 %15
%38 = load float, float* %37
%39 = fmul float %38, 2.500000e-01
%40 = getelementptr inbounds [22 x float], [22 x float]* %8, i64 0, i64 %16
store float %39, float* %40
%41 = icmp eq i64 %16, 20
br i1 %41, label %42, label %14
42: ; preds = %36, %33
%43 = phi i8* [ getelementptr inbounds ([41 x i8], [41 x i8]* @str.2, i64 0, i64 0), %33 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0), %36 ]
%44 = call i32 @puts(i8* dereferenceable(1) %43)
br label %45
45: ; preds = %21, %42
%46 = phi float [ 0.000000e+00, %42 ], [ %32, %21 ]
ret float %46
}