; LLVM IR from Muhammad-Magdi/problem-solving :: Backtracking/Backtracking - Suduku1.ll (Z6solve1St4pairIiiE)

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

%"struct.std::pair" = type { i32, i32 }

@grid = external dso_local global [10 x [10 x i8]], align 16
@ops = external dso_local global i32, align 4

; 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 @_Z7isValidii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8)) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z10isAllValidv() #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"struct.std::pair", align 4
  %8 = alloca i8, align 1
  %9 = alloca %"struct.std::pair", align 4
  store i64 %0, ptr %3, align 4
  %10 = load i32, ptr @ops, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @ops, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %12 = getelementptr inbounds %"struct.std::pair", ptr %3, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = getelementptr inbounds %"struct.std::pair", ptr %3, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  store i32 %15, ptr %5, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 9
  br i1 %17, label %18, label %20

18:                                               ; preds = %1
  %19 = call noundef zeroext i1 @_Z10isAllValidv()
  store i1 %19, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %85

20:                                               ; preds = %1
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10 x [10 x i8]], ptr @grid, i64 0, i64 %22
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x i8], ptr %23, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !12
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %28, 120
  br i1 %29, label %30, label %38

30:                                               ; preds = %20
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %31, i32 noundef %32)
  br i1 %33, label %34, label %38

34:                                               ; preds = %30
  %35 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %3)
  store i64 %35, ptr %7, align 4
  %36 = load i64, ptr %7, align 4
  %37 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %36)
  store i1 %37, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %85

38:                                               ; preds = %30, %20
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10 x [10 x i8]], ptr @grid, i64 0, i64 %40
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10 x i8], ptr %41, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !12
  %46 = sext i8 %45 to i32
  %47 = icmp ne i32 %46, 120
  br i1 %47, label %48, label %49

48:                                               ; preds = %38
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %85

49:                                               ; preds = %38
  br label %50

50:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 49, ptr %8, align 1, !tbaa !12
  br label %51

51:                                               ; preds = %79, %50
  %52 = load i8, ptr %8, align 1, !tbaa !12
  %53 = sext i8 %52 to i32
  %54 = icmp sle i32 %53, 57
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 2, ptr %6, align 4
  br label %82

56:                                               ; preds = %51
  %57 = load i8, ptr %8, align 1, !tbaa !12
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10 x [10 x i8]], ptr @grid, i64 0, i64 %59
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10 x i8], ptr %60, i64 0, i64 %62
  store i8 %57, ptr %63, align 1, !tbaa !12
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %64, i32 noundef %65)
  br i1 %66, label %67, label %72

67:                                               ; preds = %56
  %68 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %3)
  store i64 %68, ptr %9, align 4
  %69 = load i64, ptr %9, align 4
  %70 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %69)
  br i1 %70, label %71, label %72

71:                                               ; preds = %67
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %82

72:                                               ; preds = %67, %56
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [10 x [10 x i8]], ptr @grid, i64 0, i64 %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [10 x i8], ptr %75, i64 0, i64 %77
  store i8 120, ptr %78, align 1, !tbaa !12
  br label %79

79:                                               ; preds = %72
  %80 = load i8, ptr %8, align 1, !tbaa !12
  %81 = add i8 %80, 1
  store i8 %81, ptr %8, align 1, !tbaa !12
  br label %51, !llvm.loop !13

82:                                               ; preds = %71, %55
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %83 = load i32, ptr %6, align 4
  switch i32 %83, label %85 [
    i32 2, label %84
  ]

84:                                               ; preds = %82
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %85

85:                                               ; preds = %84, %82, %48, %34, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %86 = load i1, ptr %2, align 1
  ret i1 %86
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"struct.std::pair" = type { i32, i32 }

@grid = external dso_local local_unnamed_addr global [10 x [10 x i8]], align 16
@ops = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %0) local_unnamed_addr #1 {
  %2 = alloca %"struct.std::pair", align 8
  store i64 %0, ptr %2, align 8
  %3 = load i32, ptr @ops, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @ops, align 4, !tbaa !5
  %5 = trunc i64 %0 to i32
  %6 = lshr i64 %0, 32
  %7 = trunc nuw i64 %6 to i32
  %8 = icmp eq i32 %5, 9
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  %10 = tail call noundef zeroext i1 @_Z10isAllValidv()
  br label %.loopexit

11:                                               ; preds = %1
  %sext = shl i64 %0, 32
  %12 = ashr exact i64 %sext, 32
  %13 = ashr i64 %0, 32
  %14 = getelementptr inbounds [10 x [10 x i8]], ptr @grid, i64 0, i64 %12, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %.not = icmp eq i8 %15, 120
  br i1 %.not, label %.critedge.preheader, label %16

16:                                               ; preds = %11
  %17 = tail call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %17, label %18, label %thread-pre-split

18:                                               ; preds = %16
  %19 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %20 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %19)
  br label %.loopexit

thread-pre-split:                                 ; preds = %16
  %.pr = load i8, ptr %14, align 1, !tbaa !9
  %21 = icmp eq i8 %.pr, 120
  br i1 %21, label %.critedge.preheader, label %.loopexit

.critedge.preheader:                              ; preds = %thread-pre-split, %11
  store i8 49, ptr %14, align 1, !tbaa !9
  %22 = tail call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %22, label %23, label %.critedge

23:                                               ; preds = %.critedge.preheader
  %24 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %25 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %24)
  br i1 %25, label %.loopexit, label %.critedge

.critedge:                                        ; preds = %23, %.critedge.preheader
  store i8 50, ptr %14, align 1, !tbaa !9
  %26 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %26, label %27, label %.critedge.1

27:                                               ; preds = %.critedge
  %28 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %29 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %28)
  br i1 %29, label %.loopexit, label %.critedge.1

.critedge.1:                                      ; preds = %27, %.critedge
  store i8 51, ptr %14, align 1, !tbaa !9
  %30 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %30, label %31, label %.critedge.2

31:                                               ; preds = %.critedge.1
  %32 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %33 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %32)
  br i1 %33, label %.loopexit, label %.critedge.2

.critedge.2:                                      ; preds = %31, %.critedge.1
  store i8 52, ptr %14, align 1, !tbaa !9
  %34 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %34, label %35, label %.critedge.3

35:                                               ; preds = %.critedge.2
  %36 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %37 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %36)
  br i1 %37, label %.loopexit, label %.critedge.3

.critedge.3:                                      ; preds = %35, %.critedge.2
  store i8 53, ptr %14, align 1, !tbaa !9
  %38 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %38, label %39, label %.critedge.4

39:                                               ; preds = %.critedge.3
  %40 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %41 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %40)
  br i1 %41, label %.loopexit, label %.critedge.4

.critedge.4:                                      ; preds = %39, %.critedge.3
  store i8 54, ptr %14, align 1, !tbaa !9
  %42 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %42, label %43, label %.critedge.5

43:                                               ; preds = %.critedge.4
  %44 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %45 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %44)
  br i1 %45, label %.loopexit, label %.critedge.5

.critedge.5:                                      ; preds = %43, %.critedge.4
  store i8 55, ptr %14, align 1, !tbaa !9
  %46 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %46, label %47, label %.critedge.6

47:                                               ; preds = %.critedge.5
  %48 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %49 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %48)
  br i1 %49, label %.loopexit, label %.critedge.6

.critedge.6:                                      ; preds = %47, %.critedge.5
  store i8 56, ptr %14, align 1, !tbaa !9
  %50 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %50, label %51, label %.critedge.7

51:                                               ; preds = %.critedge.6
  %52 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %53 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %52)
  br i1 %53, label %.loopexit, label %.critedge.7

.critedge.7:                                      ; preds = %51, %.critedge.6
  store i8 57, ptr %14, align 1, !tbaa !9
  %54 = call noundef zeroext i1 @_Z7isValidii(i32 noundef %5, i32 noundef %7)
  br i1 %54, label %55, label %.critedge.8

55:                                               ; preds = %.critedge.7
  %56 = call i64 @_Z8nextCellRSt4pairIiiE(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %57 = call noundef zeroext i1 @_Z6solve1St4pairIiiE(i64 %56)
  br i1 %57, label %.loopexit, label %.critedge.8

.critedge.8:                                      ; preds = %55, %.critedge.7
  store i8 120, ptr %14, align 1, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %23, %27, %31, %35, %39, %43, %47, %51, %55, %.critedge.8, %thread-pre-split, %18, %9
  %.1 = phi i1 [ %10, %9 ], [ %20, %18 ], [ false, %thread-pre-split ], [ true, %23 ], [ true, %27 ], [ true, %31 ], [ true, %35 ], [ true, %39 ], [ true, %43 ], [ true, %47 ], [ true, %51 ], [ true, %55 ], [ false, %.critedge.8 ]
  ret i1 %.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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass