; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/math/sudoku_solver.ll (Z6isSafePA9_iiiii)

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

19:                                               ; preds = %48, %5
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %13, align 4
  br label %51

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [9 x i32], ptr %25, i64 %27
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [9 x i32], ptr %28, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %46, label %35

35:                                               ; preds = %24
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [9 x i32], ptr %36, i64 %38
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [9 x i32], ptr %39, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %35, %24
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %51

47:                                               ; preds = %35
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %12, align 4, !tbaa !9
  br label %19, !llvm.loop !11

51:                                               ; preds = %46, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %52 = load i32, ptr %13, align 4
  switch i32 %52, label %112 [
    i32 2, label %53
    i32 1, label %110
  ]

53:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %54)
  %56 = fptosi double %55 to i32
  store i32 %56, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %14, align 4, !tbaa !9
  %59 = sdiv i32 %57, %58
  %60 = load i32, ptr %14, align 4, !tbaa !9
  %61 = mul nsw i32 %59, %60
  store i32 %61, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = load i32, ptr %14, align 4, !tbaa !9
  %64 = sdiv i32 %62, %63
  %65 = load i32, ptr %14, align 4, !tbaa !9
  %66 = mul nsw i32 %64, %65
  store i32 %66, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %67 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %67, ptr %17, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %103, %53
  %69 = load i32, ptr %17, align 4, !tbaa !9
  %70 = load i32, ptr %15, align 4, !tbaa !9
  %71 = load i32, ptr %14, align 4, !tbaa !9
  %72 = add nsw i32 %70, %71
  %73 = icmp slt i32 %69, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %68
  store i32 5, ptr %13, align 4
  br label %106

75:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %76 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %76, ptr %18, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %97, %75
  %78 = load i32, ptr %18, align 4, !tbaa !9
  %79 = load i32, ptr %16, align 4, !tbaa !9
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = add nsw i32 %79, %80
  %82 = icmp slt i32 %78, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %77
  store i32 8, ptr %13, align 4
  br label %100

84:                                               ; preds = %77
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load i32, ptr %17, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [9 x i32], ptr %85, i64 %87
  %89 = load i32, ptr %18, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [9 x i32], ptr %88, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = load i32, ptr %11, align 4, !tbaa !9
  %94 = icmp eq i32 %92, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %84
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %100

96:                                               ; preds = %84
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %18, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %18, align 4, !tbaa !9
  br label %77, !llvm.loop !13

100:                                              ; preds = %95, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %101 = load i32, ptr %13, align 4
  switch i32 %101, label %106 [
    i32 8, label %102
  ]

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %17, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %17, align 4, !tbaa !9
  br label %68, !llvm.loop !14

106:                                              ; preds = %100, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  %107 = load i32, ptr %13, align 4
  switch i32 %107, label %109 [
    i32 5, label %108
  ]

108:                                              ; preds = %106
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %109

109:                                              ; preds = %108, %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %110

110:                                              ; preds = %109, %51
  %111 = load i1, ptr %6, align 1
  ret i1 %111

112:                                              ; preds = %51
  unreachable
}

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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
define dso_local noundef zeroext i1 @_Z6isSafePA9_iiiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %3, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %7 = sext i32 %2 to i64
  %8 = sext i32 %1 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %10

9:                                                ; preds = %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !5

10:                                               ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %11 = getelementptr inbounds [9 x i32], ptr %0, i64 %indvars.iv, i64 %7
  %12 = load i32, ptr %11, align 4, !tbaa !7
  %13 = icmp eq i32 %12, %4
  br i1 %13, label %.critedge45, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds [9 x i32], ptr %0, i64 %8, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !7
  %17 = icmp eq i32 %16, %4
  br i1 %17, label %.critedge45, label %9

._crit_edge:                                      ; preds = %9, %5
  %18 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %3)
  %19 = fptosi double %18 to i32
  %.not4355.not = icmp sgt i32 %19, 0
  br i1 %.not4355.not, label %.preheader.us.preheader, label %.critedge45

.preheader.us.preheader:                          ; preds = %._crit_edge
  %20 = srem i32 %1, %19
  %21 = sub nsw i32 %1, %20
  %22 = add nsw i32 %21, %19
  %23 = srem i32 %2, %19
  %24 = sub nsw i32 %2, %23
  %25 = add nsw i32 %24, %19
  %26 = sext i32 %24 to i64
  %27 = sext i32 %25 to i64
  %28 = sext i32 %21 to i64
  %29 = sext i32 %22 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %..critedge_crit_edge.us
  %indvars.iv64 = phi i64 [ %28, %.preheader.us.preheader ], [ %indvars.iv.next65, %..critedge_crit_edge.us ]
  br label %31

30:                                               ; preds = %31
  %indvars.iv.next62 = add nsw i64 %indvars.iv61, 1
  %.not.us = icmp slt i64 %indvars.iv.next62, %27
  br i1 %.not.us, label %31, label %..critedge_crit_edge.us, !llvm.loop !11

31:                                               ; preds = %.preheader.us, %30
  %indvars.iv61 = phi i64 [ %26, %.preheader.us ], [ %indvars.iv.next62, %30 ]
  %32 = getelementptr inbounds [9 x i32], ptr %0, i64 %indvars.iv64, i64 %indvars.iv61
  %33 = load i32, ptr %32, align 4, !tbaa !7
  %34 = icmp eq i32 %33, %4
  br i1 %34, label %.critedge45, label %30

..critedge_crit_edge.us:                          ; preds = %30
  %indvars.iv.next65 = add nsw i64 %indvars.iv64, 1
  %.not43.us.not = icmp slt i64 %indvars.iv.next65, %29
  br i1 %.not43.us.not, label %.preheader.us, label %.critedge45, !llvm.loop !12

.critedge45:                                      ; preds = %10, %14, %..critedge_crit_edge.us, %31, %._crit_edge
  %.5 = phi i1 [ true, %._crit_edge ], [ false, %31 ], [ true, %..critedge_crit_edge.us ], [ false, %14 ], [ false, %10 ]
  ret i1 %.5
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #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 = { inlinehint 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}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass