; LLVM IR from MinhasKamal/AlgorithmImplementations :: numericalMethods/calculus (IntersectingArea)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 100, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double -5.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store double 5.000000e+00, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load double, ptr %4, align 8, !tbaa !9
  %9 = load double, ptr %3, align 8, !tbaa !9
  %10 = fsub double %8, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sitofp i32 %11 to double
  %13 = fdiv double %10, %12
  store double %13, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %14 = load double, ptr %6, align 8, !tbaa !9
  %15 = load double, ptr %3, align 8, !tbaa !9
  %16 = fsub double %15, 5.000000e+00
  %17 = load double, ptr %3, align 8, !tbaa !9
  %18 = fsub double %17, 5.000000e+00
  %19 = fmul double %16, %18
  %20 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %19, double %14)
  %21 = fsub double %20, 0.000000e+00
  store double %21, ptr %6, align 8, !tbaa !9
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %43, %0
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = icmp slt i32 %23, %25
  br i1 %26, label %27, label %46

27:                                               ; preds = %22
  %28 = load double, ptr %6, align 8, !tbaa !9
  %29 = load double, ptr %3, align 8, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = sitofp i32 %30 to double
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = call double @llvm.fmuladd.f64(double %31, double %32, double %29)
  %34 = fsub double %33, 5.000000e+00
  %35 = load double, ptr %3, align 8, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = sitofp i32 %36 to double
  %38 = load double, ptr %5, align 8, !tbaa !9
  %39 = call double @llvm.fmuladd.f64(double %37, double %38, double %35)
  %40 = fsub double %39, 5.000000e+00
  %41 = call double @llvm.fmuladd.f64(double %34, double %40, double %28)
  %42 = fsub double %41, 0.000000e+00
  store double %42, ptr %6, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %27
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !5
  br label %22, !llvm.loop !11

46:                                               ; preds = %22
  %47 = load double, ptr %6, align 8, !tbaa !9
  %48 = load double, ptr %4, align 8, !tbaa !9
  %49 = fsub double %48, 5.000000e+00
  %50 = load double, ptr %4, align 8, !tbaa !9
  %51 = fsub double %50, 5.000000e+00
  %52 = fmul double %49, %51
  %53 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %52, double %47)
  %54 = fsub double %53, 0.000000e+00
  store double %54, ptr %6, align 8, !tbaa !9
  %55 = load double, ptr %6, align 8, !tbaa !9
  %56 = load double, ptr %5, align 8, !tbaa !9
  %57 = fmul double %55, %56
  store double %57, ptr %6, align 8, !tbaa !9
  %58 = load double, ptr %6, align 8, !tbaa !9
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %1, %0
  %.023 = phi i32 [ 1, %0 ], [ %11, %1 ]
  %.02122 = phi double [ 5.000000e+01, %0 ], [ %10, %1 ]
  %2 = uitofp nneg i32 %.023 to double
  %3 = tail call double @llvm.fmuladd.f64(double %2, double 1.000000e-01, double -5.000000e+00)
  %4 = fadd double %3, -5.000000e+00
  %5 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %.02122)
  %6 = add nuw nsw i32 %.023, 1
  %7 = uitofp nneg i32 %6 to double
  %8 = tail call double @llvm.fmuladd.f64(double %7, double 1.000000e-01, double -5.000000e+00)
  %9 = fadd double %8, -5.000000e+00
  %10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %5)
  %11 = add nuw nsw i32 %.023, 2
  %exitcond.not.1 = icmp eq i32 %11, 99
  br i1 %exitcond.not.1, label %12, label %1, !llvm.loop !5

12:                                               ; preds = %1
  %13 = fmul double %10, 1.000000e-01
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %13)
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass