; LLVM IR from imeplusplus/icpc-notebook :: math/simpson_rule.ll (Z7simpsonddi)

; 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z1fd(double noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z7simpsonddi(double noundef %0, double noundef %1, i32 noundef %2) #0 {
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load double, ptr %5, align 8, !tbaa !5
  %12 = load double, ptr %4, align 8, !tbaa !5
  %13 = fsub double %11, %12
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sitofp i32 %14 to double
  %16 = fdiv double %13, %15
  store double %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = call noundef double @_Z1fd(double noundef %17)
  %19 = load double, ptr %5, align 8, !tbaa !5
  %20 = call noundef double @_Z1fd(double noundef %19)
  %21 = fadd double %18, %20
  store double %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %36, %3
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %39

27:                                               ; preds = %22
  %28 = load double, ptr %4, align 8, !tbaa !5
  %29 = load double, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = sitofp i32 %30 to double
  %32 = call double @llvm.fmuladd.f64(double %29, double %31, double %28)
  %33 = call noundef double @_Z1fd(double noundef %32)
  %34 = load double, ptr %8, align 8, !tbaa !5
  %35 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %33, double %34)
  store double %35, ptr %8, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %27
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = add nsw i32 %37, 2
  store i32 %38, ptr %9, align 4, !tbaa !9
  br label %22, !llvm.loop !11

39:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 2, ptr %10, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %54, %39
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %57

45:                                               ; preds = %40
  %46 = load double, ptr %4, align 8, !tbaa !5
  %47 = load double, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sitofp i32 %48 to double
  %50 = call double @llvm.fmuladd.f64(double %47, double %49, double %46)
  %51 = call noundef double @_Z1fd(double noundef %50)
  %52 = load double, ptr %8, align 8, !tbaa !5
  %53 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %51, double %52)
  store double %53, ptr %8, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %45
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = add nsw i32 %55, 2
  store i32 %56, ptr %10, align 4, !tbaa !9
  br label %40, !llvm.loop !13

57:                                               ; preds = %44
  %58 = load double, ptr %8, align 8, !tbaa !5
  %59 = load double, ptr %7, align 8, !tbaa !5
  %60 = fmul double %58, %59
  %61 = fdiv double %60, 3.000000e+00
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret double %61
}

; 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

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

attributes #0 = { mustprogress 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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z1fd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z7simpsonddi(double noundef %0, double noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = fsub double %1, %0
  %5 = sitofp i32 %2 to double
  %6 = fdiv double %4, %5
  %7 = tail call noundef double @_Z1fd(double noundef %0)
  %8 = tail call noundef double @_Z1fd(double noundef %1)
  %9 = fadd double %7, %8
  %10 = icmp sgt i32 %2, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %.not = icmp eq i32 %2, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph27

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.02024 = phi i32 [ %15, %.lr.ph ], [ 1, %3 ]
  %.02123 = phi double [ %14, %.lr.ph ], [ %9, %3 ]
  %11 = uitofp nneg i32 %.02024 to double
  %12 = tail call double @llvm.fmuladd.f64(double %6, double %11, double %0)
  %13 = tail call noundef double @_Z1fd(double noundef %12)
  %14 = tail call double @llvm.fmuladd.f64(double %13, double 4.000000e+00, double %.02123)
  %15 = add nuw nsw i32 %.02024, 2
  %16 = icmp slt i32 %15, %2
  br i1 %16, label %.lr.ph, label %.preheader, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph27, %3, %.preheader
  %.1.lcssa = phi double [ %14, %.preheader ], [ %9, %3 ], [ %22, %.lr.ph27 ]
  %17 = fmul double %6, %.1.lcssa
  %18 = fdiv double %17, 3.000000e+00
  ret double %18

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %.026 = phi i32 [ %23, %.lr.ph27 ], [ 2, %.preheader ]
  %.125 = phi double [ %22, %.lr.ph27 ], [ %14, %.preheader ]
  %19 = uitofp nneg i32 %.026 to double
  %20 = tail call double @llvm.fmuladd.f64(double %6, double %19, double %0)
  %21 = tail call noundef double @_Z1fd(double noundef %20)
  %22 = tail call double @llvm.fmuladd.f64(double %21, double 2.000000e+00, double %.125)
  %23 = add nuw nsw i32 %.026, 2
  %24 = icmp slt i32 %23, %2
  br i1 %24, label %.lr.ph27, label %._crit_edge, !llvm.loop !7
}

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

attributes #0 = { mustprogress 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) }

!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"}
!7 = distinct !{!7, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass