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

; 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: mustprogress nounwind uwtable
define dso_local noundef double @_ZN4dart8external3ode14dMaxDifferenceEPKdS3_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp sgt i32 %17, 1
  br i1 %18, label %19, label %24

19:                                               ; preds = %4
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = or i32 %21, 3
  %23 = add nsw i32 %22, 1
  br label %26

24:                                               ; preds = %4
  %25 = load i32, ptr %8, align 4, !tbaa !9
  br label %26

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

30:                                               ; preds = %64, %26
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %75

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %60, %35
  %37 = load i32, ptr %15, align 4, !tbaa !9
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %63

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

57:                                               ; preds = %41
  %58 = load double, ptr %16, align 8, !tbaa !11
  store double %58, ptr %10, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %57, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %15, align 4, !tbaa !9
  br label %36, !llvm.loop !13

63:                                               ; preds = %40
  br label %64

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN4dart8external3ode14dMaxDifferenceEPKdS3_ii(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge35

.preheader.lr.ph:                                 ; preds = %4
  %6 = icmp sgt i32 %3, 1
  %7 = add nsw i32 %3, -1
  %8 = or i32 %7, 3
  %9 = add nuw nsw i32 %8, 1
  %10 = select i1 %6, i32 %9, i32 %3
  %11 = icmp sgt i32 %3, 0
  %12 = sext i32 %10 to i64
  br i1 %11, label %.preheader.us.preheader, label %._crit_edge35

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %3, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.034.us = phi double [ %.2.us.lcssa, %._crit_edge.us ], [ 0.000000e+00, %.preheader.us.preheader ]
  %.02333.us = phi i32 [ %37, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02432.us = phi ptr [ %36, %._crit_edge.us ], [ %1, %.preheader.us.preheader ]
  %.02531.us = phi ptr [ %35, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  br i1 %13, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.130.us = phi double [ %.2.us.1, %.preheader.us.new ], [ %.034.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %14 = getelementptr inbounds double, ptr %.02531.us, i64 %indvars.iv
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds double, ptr %.02432.us, i64 %indvars.iv
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fsub double %15, %17
  %19 = tail call double @llvm.fabs.f64(double %18)
  %20 = fcmp ogt double %19, %.130.us
  %.2.us = select i1 %20, double %19, double %.130.us
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = getelementptr inbounds double, ptr %.02531.us, i64 %indvars.iv.next
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %.02432.us, i64 %indvars.iv.next
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fsub double %22, %24
  %26 = tail call double @llvm.fabs.f64(double %25)
  %27 = fcmp ogt double %26, %.2.us
  %.2.us.1 = select i1 %27, double %26, double %.2.us
  %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 %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.2.us.lcssa.ph = phi double [ poison, %.preheader.us ], [ %.2.us.1, %.preheader.us.new ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %.preheader.us.new ]
  %.130.us.unr = phi double [ %.034.us, %.preheader.us ], [ %.2.us.1, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %28 = getelementptr inbounds double, ptr %.02531.us, i64 %indvars.iv.unr
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %.02432.us, i64 %indvars.iv.unr
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fsub double %29, %31
  %33 = tail call double @llvm.fabs.f64(double %32)
  %34 = fcmp ogt double %33, %.130.us.unr
  %.2.us.epil = select i1 %34, double %33, double %.130.us.unr
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.2.us.lcssa = phi double [ %.2.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %.2.us.epil, %._crit_edge.us.epilog-lcssa ]
  %35 = getelementptr inbounds double, ptr %.02531.us, i64 %12
  %36 = getelementptr inbounds double, ptr %.02432.us, i64 %12
  %37 = add nuw nsw i32 %.02333.us, 1
  %exitcond39.not = icmp eq i32 %37, %2
  br i1 %exitcond39.not, label %._crit_edge35, label %.preheader.us, !llvm.loop !11

._crit_edge35:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %4
  %.0.lcssa = phi double [ 0.000000e+00, %4 ], [ 0.000000e+00, %.preheader.lr.ph ], [ %.2.us.lcssa, %._crit_edge.us ]
  ret double %.0.lcssa
}

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

attributes #0 = { 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" }
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 = !{!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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass