#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 *, double);
double sqrt(int);
void simpson() {
  int k;
  double a, b, n, h, fo, fe, sum, t;
  a = 0;
  b = 2;
  n = 50;
  h = (b - a) / (n * 2);
  fo = 0;
  fe = 0;
  for (k = 1; k <= 2 * n - 3; k = k + 2) {
    t = (a + h * k);
    fo = fo + sqrt(4 - t * t);
    t = (a + h * (k + 1));
    fe = fe + sqrt(4 - t * t);
  }
  t = b - h;
  sum = ((sqrt(4 - a * a)) + (sqrt(4 - b * b)) + 4 * (fo + sqrt(4 - t * t)) +
         2 * fe) *
        h / 3;
  printf("    /%f\n", b);
  printf("    sqrt(4 - x * x) = %f\n", sum);
  printf("    /%f\n", a);
}


x86 assembly (clang, -O0):
<simpson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec8(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     129a <simpson+0x17a>
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe28(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdb2(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <simpson+0x61>
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd4a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd0b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xcb6(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x68(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
addsd  %xmm2,%xmm1
movsd  0xc90(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xc66(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xc61(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xc59(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xc3f(%rip),%rdi
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpson>:
push   %rbx
sub    $0x20,%rsp
movsd  0xed3(%rip),%xmm1
mov    $0xffffffff,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
movsd  0xea6(%rip),%xmm1
mulsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movsd  0xe96(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
lea    0x3(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe5f(%rip),%xmm0
addsd  0xe77(%rip),%xmm0
mulsd  %xmm0,%xmm0
movsd  0xe53(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  0xe30(%rip),%xmm1
add    $0x2,%ebx
cmp    $0x60,%ebx
jb     1150 <simpson+0x30>
mov    $0x4,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1040 <sqrt@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1040 <sqrt@plt>
addsd  0x18(%rsp),%xmm0
mulsd  0xde4(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mulsd  0xdc0(%rip),%xmm0
divsd  0xdd0(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xdd3(%rip),%rbx
movsd  0xdb3(%rip),%xmm0
mov    %rbx,%rdi
call   1030 <printf@plt>
lea    0xdc5(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
mov    %rbx,%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c" /%f\0A\00"
@.str.1 = [26 x i8] c" sqrt(4 - x * x) = %f\0A\00"
define void @simpson() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double 0.000000e+00, double* %2
store double 2.000000e+00, double* %3
store double 5.000000e+01, double* %4
%10 = load double, double* %3
%11 = load double, double* %2
%12 = fsub double %10, %11
%13 = load double, double* %4
%14 = fmul double %13, 2.000000e+00
%15 = fdiv double %12, %14
store double %15, double* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i32 1, i32* %1
br label %16
16: ; preds = %50, %0
%17 = load i32, i32* %1
%18 = sitofp i32 %17 to double
%19 = load double, double* %4
%20 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %19, double -3.000000e+00)
%21 = fcmp ole double %18, %20
br i1 %21, label %22, label %53
22: ; preds = %16
%23 = load double, double* %2
%24 = load double, double* %5
%25 = load i32, i32* %1
%26 = sitofp i32 %25 to double
%27 = call double @llvm.fmuladd.f64(double %24, double %26, double %23)
store double %27, double* %9
%28 = load double, double* %6
%29 = load double, double* %9
%30 = load double, double* %9
%31 = fneg double %29
%32 = call double @llvm.fmuladd.f64(double %31, double %30, double 4.000000e+00)
%33 = fptosi double %32 to i32
%34 = call double @sqrt(i32 %33)
%35 = fadd double %28, %34
store double %35, double* %6
%36 = load double, double* %2
%37 = load double, double* %5
%38 = load i32, i32* %1
%39 = add nsw i32 %38, 1
%40 = sitofp i32 %39 to double
%41 = call double @llvm.fmuladd.f64(double %37, double %40, double %36)
store double %41, double* %9
%42 = load double, double* %7
%43 = load double, double* %9
%44 = load double, double* %9
%45 = fneg double %43
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double 4.000000e+00)
%47 = fptosi double %46 to i32
%48 = call double @sqrt(i32 %47)
%49 = fadd double %42, %48
store double %49, double* %7
br label %50
50: ; preds = %22
%51 = load i32, i32* %1
%52 = add nsw i32 %51, 2
store i32 %52, i32* %1
br label %16
53: ; preds = %16
%54 = load double, double* %3
%55 = load double, double* %5
%56 = fsub double %54, %55
store double %56, double* %9
%57 = load double, double* %2
%58 = load double, double* %2
%59 = fneg double %57
%60 = call double @llvm.fmuladd.f64(double %59, double %58, double 4.000000e+00)
%61 = fptosi double %60 to i32
%62 = call double @sqrt(i32 %61)
%63 = load double, double* %3
%64 = load double, double* %3
%65 = fneg double %63
%66 = call double @llvm.fmuladd.f64(double %65, double %64, double 4.000000e+00)
%67 = fptosi double %66 to i32
%68 = call double @sqrt(i32 %67)
%69 = fadd double %62, %68
%70 = load double, double* %6
%71 = load double, double* %9
%72 = load double, double* %9
%73 = fneg double %71
%74 = call double @llvm.fmuladd.f64(double %73, double %72, double 4.000000e+00)
%75 = fptosi double %74 to i32
%76 = call double @sqrt(i32 %75)
%77 = fadd double %70, %76
%78 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %77, double %69)
%79 = load double, double* %7
%80 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %79, double %78)
%81 = load double, double* %5
%82 = fmul double %80, %81
%83 = fdiv double %82, 3.000000e+00
store double %83, double* %8
%84 = load double, double* %3
%85 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %84)
%86 = load double, double* %8
%87 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %86)
%88 = load double, double* %2
%89 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %88)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c" /%f\0A\00"
@.str.1 = [26 x i8] c" sqrt(4 - x * x) = %f\0A\00"
define void @simpson() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 1, %0 ], [ %20, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %19, %1 ]
%4 = phi double [ 0.000000e+00, %0 ], [ %11, %1 ]
%5 = sitofp i32 %2 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e-02, double 0.000000e+00)
%7 = fneg double %6
%8 = tail call double @llvm.fmuladd.f64(double %7, double %6, double 4.000000e+00)
%9 = fptosi double %8 to i32
%10 = tail call double @sqrt(i32 %9)
%11 = fadd double %4, %10
%12 = add nuw nsw i32 %2, 1
%13 = sitofp i32 %12 to double
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e-02, double 0.000000e+00)
%15 = fneg double %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %14, double 4.000000e+00)
%17 = fptosi double %16 to i32
%18 = tail call double @sqrt(i32 %17)
%19 = fadd double %3, %18
%20 = add nuw nsw i32 %2, 2
%21 = icmp ult i32 %2, 96
br i1 %21, label %1, label %22
22: ; preds = %1
%23 = tail call double @sqrt(i32 4)
%24 = tail call double @sqrt(i32 0)
%25 = fadd double %23, %24
%26 = tail call double @sqrt(i32 0)
%27 = fadd double %11, %26
%28 = tail call double @llvm.fmuladd.f64(double %27, double 4.000000e+00, double %25)
%29 = tail call double @llvm.fmuladd.f64(double %19, double 2.000000e+00, double %28)
%30 = fmul double %29, 2.000000e-02
%31 = fdiv double %30, 3.000000e+00
%32 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double 2.000000e+00)
%33 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %31)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double 0.000000e+00)
ret void
}