; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/dp/townPlanning.ll (Z20checkTwoRowCollisioniii)

; 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
declare dso_local noundef zeroext i1 @_Z2onii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z20checkTwoRowCollisioniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %44, %3
  %11 = load i32, ptr %8, align 4, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %9, align 4
  br label %47

15:                                               ; preds = %10
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %28

18:                                               ; preds = %15
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = call noundef zeroext i1 @_Z2onii(i32 noundef %19, i32 noundef %20)
  br i1 %21, label %22, label %28

22:                                               ; preds = %18
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = call noundef zeroext i1 @_Z2onii(i32 noundef %24, i32 noundef %25)
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %47

28:                                               ; preds = %22, %18, %15
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %33, label %43

33:                                               ; preds = %28
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = call noundef zeroext i1 @_Z2onii(i32 noundef %34, i32 noundef %35)
  br i1 %36, label %37, label %43

37:                                               ; preds = %33
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = call noundef zeroext i1 @_Z2onii(i32 noundef %39, i32 noundef %40)
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %47

43:                                               ; preds = %37, %33, %28
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !5
  br label %10, !llvm.loop !9

47:                                               ; preds = %42, %27, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %48 = load i32, ptr %9, align 4
  switch i32 %48, label %52 [
    i32 2, label %49
    i32 1, label %50
  ]

49:                                               ; preds = %47
  store i1 true, ptr %4, align 1
  br label %50

50:                                               ; preds = %49, %47
  %51 = load i1, ptr %4, align 1
  ret i1 %51

52:                                               ; preds = %47
  unreachable
}

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 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z2onii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z20checkTwoRowCollisioniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp slt i32 %2, 1
  br i1 %4, label %._crit_edge, label %5

5:                                                ; preds = %3
  %6 = add nsw i32 %2, -1
  %.not = icmp eq i32 %2, 1
  br i1 %.not, label %._crit_edge, label %7

7:                                                ; preds = %5
  %8 = tail call noundef zeroext i1 @_Z2onii(i32 noundef 0, i32 noundef %1)
  br i1 %8, label %9, label %.peel.next.preheader

9:                                                ; preds = %7
  %10 = tail call noundef zeroext i1 @_Z2onii(i32 noundef 1, i32 noundef %0)
  br i1 %10, label %._crit_edge, label %.peel.next.preheader

.peel.next.preheader:                             ; preds = %9, %7
  br label %.peel.next

.peel.next:                                       ; preds = %.peel.next.preheader, %23
  %11 = phi i1 [ %25, %23 ], [ false, %.peel.next.preheader ]
  %.01518 = phi i32 [ %24, %23 ], [ 1, %.peel.next.preheader ]
  %12 = tail call noundef zeroext i1 @_Z2onii(i32 noundef %.01518, i32 noundef %1)
  br i1 %12, label %13, label %16

13:                                               ; preds = %.peel.next
  %14 = add nsw i32 %.01518, -1
  %15 = tail call noundef zeroext i1 @_Z2onii(i32 noundef %14, i32 noundef %0)
  br i1 %15, label %._crit_edge, label %16

16:                                               ; preds = %13, %.peel.next
  %17 = icmp slt i32 %.01518, %6
  br i1 %17, label %18, label %23

18:                                               ; preds = %16
  %19 = tail call noundef zeroext i1 @_Z2onii(i32 noundef %.01518, i32 noundef %1)
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = add nuw nsw i32 %.01518, 1
  %22 = tail call noundef zeroext i1 @_Z2onii(i32 noundef %21, i32 noundef %0)
  br i1 %22, label %._crit_edge, label %23

23:                                               ; preds = %16, %18, %20
  %24 = add nuw nsw i32 %.01518, 1
  %25 = icmp sge i32 %24, %2
  %exitcond = icmp eq i32 %24, %2
  br i1 %exitcond, label %._crit_edge, label %.peel.next, !llvm.loop !5

._crit_edge:                                      ; preds = %23, %13, %20, %5, %9, %3
  %.lcssa = phi i1 [ true, %3 ], [ false, %9 ], [ true, %5 ], [ %25, %23 ], [ %11, %13 ], [ %11, %20 ]
  ret i1 %.lcssa
}

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

!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, !7}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!"llvm.loop.peeled.count", i32 1}


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