; LLVM IR from yuikns/panther :: ann/src/bd_tree.ll (Z15trySimpleShrinkPPdPiiiRK11ANNorthRectRS2_)

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

%class.ANNorthRect = type { ptr, ptr }

; 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

declare void @_Z11annEnclRectPPdPiiiR11ANNorthRect(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(16)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z15trySimpleShrinkPPdPiiiRK11ANNorthRectRS2_(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_Z11annEnclRectPPdPiiiR11ANNorthRect(ptr noundef %21, ptr noundef %22, i32 noundef %23, i32 noundef %24, ptr noundef nonnull align 8 dereferenceable(16) %25)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store double 0.000000e+00, ptr %15, align 8, !tbaa !11
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %52, %6
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %55

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.ANNorthRect, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.ANNorthRect, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %14, 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 = fsub double %37, %44
  store double %45, ptr %16, align 8, !tbaa !11
  %46 = load double, ptr %16, align 8, !tbaa !11
  %47 = load double, ptr %15, align 8, !tbaa !11
  %48 = fcmp ogt double %46, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %30
  %50 = load double, ptr %16, align 8, !tbaa !11
  store double %50, ptr %15, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %49, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %14, align 4, !tbaa !9
  br label %26, !llvm.loop !16

55:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %135, %55
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %60, label %138

60:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.ANNorthRect, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = load i32, ptr %14, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.ANNorthRect, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  %71 = load i32, ptr %14, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = fsub double %67, %74
  store double %75, ptr %18, align 8, !tbaa !11
  %76 = load double, ptr %18, align 8, !tbaa !11
  %77 = load double, ptr %15, align 8, !tbaa !11
  %78 = fmul double %77, 5.000000e-01
  %79 = fcmp olt double %76, %78
  br i1 %79, label %80, label %94

80:                                               ; preds = %60
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = getelementptr inbounds %class.ANNorthRect, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !13
  %84 = load i32, ptr %14, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds double, ptr %83, i64 %85
  %87 = load double, ptr %86, align 8, !tbaa !11
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = getelementptr inbounds %class.ANNorthRect, ptr %88, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = load i32, ptr %14, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds double, ptr %90, i64 %92
  store double %87, ptr %93, align 8, !tbaa !11
  br label %97

94:                                               ; preds = %60
  %95 = load i32, ptr %17, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %17, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %94, %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = getelementptr inbounds %class.ANNorthRect, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = load i32, ptr %14, align 4, !tbaa !9
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds double, ptr %100, i64 %102
  %104 = load double, ptr %103, align 8, !tbaa !11
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  %106 = getelementptr inbounds %class.ANNorthRect, ptr %105, i32 0, i32 0
  %107 = load ptr, ptr %106, align 8, !tbaa !15
  %108 = load i32, ptr %14, align 4, !tbaa !9
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds double, ptr %107, i64 %109
  %111 = load double, ptr %110, align 8, !tbaa !11
  %112 = fsub double %104, %111
  store double %112, ptr %19, align 8, !tbaa !11
  %113 = load double, ptr %19, align 8, !tbaa !11
  %114 = load double, ptr %15, align 8, !tbaa !11
  %115 = fmul double %114, 5.000000e-01
  %116 = fcmp olt double %113, %115
  br i1 %116, label %117, label %131

117:                                              ; preds = %97
  %118 = load ptr, ptr %12, align 8, !tbaa !5
  %119 = getelementptr inbounds %class.ANNorthRect, ptr %118, i32 0, i32 0
  %120 = load ptr, ptr %119, align 8, !tbaa !15
  %121 = load i32, ptr %14, align 4, !tbaa !9
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds double, ptr %120, i64 %122
  %124 = load double, ptr %123, align 8, !tbaa !11
  %125 = load ptr, ptr %13, align 8, !tbaa !5
  %126 = getelementptr inbounds %class.ANNorthRect, ptr %125, i32 0, i32 0
  %127 = load ptr, ptr %126, align 8, !tbaa !15
  %128 = load i32, ptr %14, align 4, !tbaa !9
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds double, ptr %127, i64 %129
  store double %124, ptr %130, align 8, !tbaa !11
  br label %134

131:                                              ; preds = %97
  %132 = load i32, ptr %17, align 4, !tbaa !9
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %17, align 4, !tbaa !9
  br label %134

134:                                              ; preds = %131, %117
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %14, align 4, !tbaa !9
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %14, align 4, !tbaa !9
  br label %56, !llvm.loop !18

138:                                              ; preds = %56
  %139 = load i32, ptr %17, align 4, !tbaa !9
  %140 = icmp sge i32 %139, 2
  br i1 %140, label %141, label %142

141:                                              ; preds = %138
  store i32 1, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %143

142:                                              ; preds = %138
  store i32 0, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %143

143:                                              ; preds = %142, %141
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %144 = load i32, ptr %7, align 4
  ret i32 %144
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress 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 = !{!14, !6, i64 8}
!14 = !{!"_ZTS11ANNorthRect", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

declare void @_Z11annEnclRectPPdPiiiR11ANNorthRect(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z15trySimpleShrinkPPdPiiiRK11ANNorthRectRS2_(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %5) local_unnamed_addr #1 {
  tail call void @_Z11annEnclRectPPdPiiiR11ANNorthRect(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(16) %5)
  %7 = icmp sgt i32 %3, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !10
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %3, 1
  br i1 %11, label %.preheader.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %25

.preheader.unr-lcssa:                             ; preds = %25, %.lr.ph
  %.145.lcssa.ph = phi double [ poison, %.lr.ph ], [ %.145.1, %25 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %25 ]
  %.04448.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %.145.1, %25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.epilog-lcssa

.preheader.epilog-lcssa:                          ; preds = %.preheader.unr-lcssa
  %12 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.unr
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.unr
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = fsub double %13, %15
  %17 = fcmp ogt double %16, %.04448.unr
  %.145.epil = select i1 %17, double %16, double %.04448.unr
  br label %.preheader

.preheader:                                       ; preds = %.preheader.unr-lcssa, %.preheader.epilog-lcssa
  %.145.lcssa = phi double [ %.145.lcssa.ph, %.preheader.unr-lcssa ], [ %.145.epil, %.preheader.epilog-lcssa ]
  %18 = fmul double %.145.lcssa, 5.000000e-01
  br i1 %7, label %.lr.ph52, label %._crit_edge

.lr.ph52:                                         ; preds = %.preheader
  %19 = getelementptr inbounds i8, ptr %4, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %5, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !10
  %24 = load ptr, ptr %4, align 8, !tbaa !10
  %wide.trip.count58 = zext nneg i32 %3 to i64
  br label %38

25:                                               ; preds = %25, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %25 ]
  %.04448 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %.145.1, %25 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %25 ]
  %26 = getelementptr inbounds double, ptr %9, i64 %indvars.iv
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = fsub double %27, %29
  %31 = fcmp ogt double %30, %.04448
  %.145 = select i1 %31, double %30, double %.04448
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %32 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.next
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = fsub double %33, %35
  %37 = fcmp ogt double %36, %.145
  %.145.1 = select i1 %37, double %36, double %.145
  %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 %.preheader.unr-lcssa, label %25, !llvm.loop !13

38:                                               ; preds = %.lr.ph52, %58
  %indvars.iv55 = phi i64 [ 0, %.lr.ph52 ], [ %indvars.iv.next56, %58 ]
  %.04250 = phi i32 [ 0, %.lr.ph52 ], [ %.2, %58 ]
  %39 = getelementptr inbounds double, ptr %20, i64 %indvars.iv55
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds double, ptr %22, i64 %indvars.iv55
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fsub double %40, %42
  %44 = fcmp olt double %43, %18
  br i1 %44, label %45, label %46

45:                                               ; preds = %38
  store double %40, ptr %41, align 8, !tbaa !11
  br label %48

46:                                               ; preds = %38
  %47 = add nsw i32 %.04250, 1
  br label %48

48:                                               ; preds = %46, %45
  %.143 = phi i32 [ %.04250, %45 ], [ %47, %46 ]
  %49 = getelementptr inbounds double, ptr %23, i64 %indvars.iv55
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds double, ptr %24, i64 %indvars.iv55
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = fsub double %50, %52
  %54 = fcmp olt double %53, %18
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  store double %52, ptr %49, align 8, !tbaa !11
  br label %58

56:                                               ; preds = %48
  %57 = add nsw i32 %.143, 1
  br label %58

58:                                               ; preds = %56, %55
  %.2 = phi i32 [ %.143, %55 ], [ %57, %56 ]
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count58
  br i1 %exitcond59.not, label %._crit_edge.loopexit, label %38, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %58
  %59 = icmp sgt i32 %.2, 1
  %60 = zext i1 %59 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %6, %._crit_edge.loopexit, %.preheader
  %.042.lcssa = phi i32 [ 0, %.preheader ], [ %60, %._crit_edge.loopexit ], [ 0, %6 ]
  ret i32 %.042.lcssa
}

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


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