; LLVM IR from dartsim/dart :: dart/external/odelcpsolver (misc)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN4dart8external3ode27dMaxDifferenceLowerTriangleEPKdS3_i(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp sgt i32 %15, 1
  br i1 %16, label %17, label %22

17:                                               ; preds = %3
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = or i32 %19, 3
  %21 = add nsw i32 %20, 1
  br label %24

22:                                               ; preds = %3
  %23 = load i32, ptr %6, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %22, %17
  %25 = phi i32 [ %21, %17 ], [ %23, %22 ]
  store i32 %25, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %26, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %27, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %62, %24
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %73

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %58, %33
  %35 = load i32, ptr %13, align 4, !tbaa !9
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %61

39:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fsub double %44, %49
  %51 = call double @llvm.fabs.f64(double %50)
  store double %51, ptr %14, align 8, !tbaa !11
  %52 = load double, ptr %14, align 8, !tbaa !11
  %53 = load double, ptr %8, align 8, !tbaa !11
  %54 = fcmp ogt double %52, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %39
  %56 = load double, ptr %14, align 8, !tbaa !11
  store double %56, ptr %8, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %55, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %13, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %13, align 4, !tbaa !9
  br label %34, !llvm.loop !13

61:                                               ; preds = %38
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = sext i32 %63 to i64
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  store ptr %66, ptr %9, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds double, ptr %68, i64 %69
  store ptr %70, ptr %10, align 8, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %11, align 4, !tbaa !9
  br label %28, !llvm.loop !15

73:                                               ; preds = %32
  %74 = load double, ptr %8, align 8, !tbaa !11
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret double %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN4dart8external3ode27dMaxDifferenceLowerTriangleEPKdS3_i(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %3
  %.not = icmp eq i32 %2, 1
  %5 = add nsw i32 %2, -1
  %6 = or i32 %5, 3
  %7 = add nuw nsw i32 %6, 1
  %8 = select i1 %.not, i32 1, i32 %7
  %9 = zext nneg i32 %8 to i64
  %10 = add nuw i32 %2, 1
  %wide.trip.count41 = zext i32 %10 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %19
  %indvar = phi i64 [ 0, %.preheader.lr.ph ], [ %indvar.next, %19 ]
  %indvars.iv38 = phi i64 [ 1, %.preheader.lr.ph ], [ %indvars.iv.next39, %19 ]
  %.034 = phi double [ 0.000000e+00, %.preheader.lr.ph ], [ %.2.lcssa, %19 ]
  %.02432 = phi ptr [ %1, %.preheader.lr.ph ], [ %21, %19 ]
  %.02531 = phi ptr [ %0, %.preheader.lr.ph ], [ %20, %19 ]
  %xtraiter = and i64 %indvars.iv38, 1
  %11 = icmp eq i64 %indvar, 0
  br i1 %11, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader
  %unroll_iter = and i64 %indvars.iv38, 9223372036854775806
  br label %22

._crit_edge:                                      ; preds = %19, %3
  %.0.lcssa = phi double [ 0.000000e+00, %3 ], [ %.2.lcssa, %19 ]
  ret double %.0.lcssa

.unr-lcssa:                                       ; preds = %22, %.preheader
  %.2.lcssa.ph = phi double [ poison, %.preheader ], [ %.2.1, %22 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.1, %22 ]
  %.130.unr = phi double [ %.034, %.preheader ], [ %.2.1, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %19, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %12 = getelementptr inbounds double, ptr %.02531, i64 %indvars.iv.unr
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %.02432, i64 %indvars.iv.unr
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fsub double %13, %15
  %17 = tail call double @llvm.fabs.f64(double %16)
  %18 = fcmp ogt double %17, %.130.unr
  %.2.epil = select i1 %18, double %17, double %.130.unr
  br label %19

19:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %.2.lcssa = phi double [ %.2.lcssa.ph, %.unr-lcssa ], [ %.2.epil, %.epilog-lcssa ]
  %20 = getelementptr inbounds double, ptr %.02531, i64 %9
  %21 = getelementptr inbounds double, ptr %.02432, i64 %9
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond42.not, label %._crit_edge, label %.preheader, !llvm.loop !9

22:                                               ; preds = %22, %.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader.new ], [ %indvars.iv.next.1, %22 ]
  %.130 = phi double [ %.034, %.preheader.new ], [ %.2.1, %22 ]
  %niter = phi i64 [ 0, %.preheader.new ], [ %niter.next.1, %22 ]
  %23 = getelementptr inbounds double, ptr %.02531, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %.02432, i64 %indvars.iv
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fsub double %24, %26
  %28 = tail call double @llvm.fabs.f64(double %27)
  %29 = fcmp ogt double %28, %.130
  %.2 = select i1 %29, double %28, double %.130
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = getelementptr inbounds double, ptr %.02531, i64 %indvars.iv.next
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds double, ptr %.02432, i64 %indvars.iv.next
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fsub double %31, %33
  %35 = tail call double @llvm.fabs.f64(double %34)
  %36 = fcmp ogt double %35, %.2
  %.2.1 = select i1 %36, double %35, double %.2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.unr-lcssa, label %22, !llvm.loop !11
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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