; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Backtracking/Rat In A Maze.ll (Z16MazeSolveUtilityii)

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

@DestX = external dso_local global i32, align 4
@DestY = external dso_local global i32, align 4
@Sol = external dso_local global [100 x [100 x i32]], align 16
@MoveX = external dso_local global [4 x i32], align 16
@MoveY = external dso_local global [4 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %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 %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr @DestX, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %13, label %24

13:                                               ; preds = %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr @DestY, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %24

17:                                               ; preds = %13
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %19
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i32], ptr %20, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  store i1 true, ptr %3, align 1
  br label %74

24:                                               ; preds = %13, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %68, %24
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 4
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 2, ptr %7, align 4
  br label %71

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4 x i32], ptr @MoveX, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %30, %34
  store i32 %35, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [4 x i32], ptr @MoveY, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = add nsw i32 %36, %40
  store i32 %41, ptr %9, align 4, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %42, i32 noundef %43)
  br i1 %44, label %45, label %64

45:                                               ; preds = %29
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %47
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100 x i32], ptr %48, i64 0, i64 %50
  store i32 1, ptr %51, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = call noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %52, i32 noundef %53)
  br i1 %54, label %55, label %56

55:                                               ; preds = %45
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %65

56:                                               ; preds = %45
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %58
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100 x i32], ptr %59, i64 0, i64 %61
  store i32 0, ptr %62, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %56
  br label %64

64:                                               ; preds = %63, %29
  store i32 0, ptr %7, align 4
  br label %65

65:                                               ; preds = %64, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %66 = load i32, ptr %7, align 4
  switch i32 %66, label %71 [
    i32 0, label %67
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %6, align 4, !tbaa !5
  br label %25, !llvm.loop !9

71:                                               ; preds = %65, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %72 = load i32, ptr %7, align 4
  switch i32 %72, label %76 [
    i32 2, label %73
    i32 1, label %74
  ]

73:                                               ; preds = %71
  store i1 false, ptr %3, align 1
  br label %74

74:                                               ; preds = %73, %71, %17
  %75 = load i1, ptr %3, align 1
  ret i1 %75

76:                                               ; preds = %71
  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 = { 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 = 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"

@DestX = external dso_local local_unnamed_addr global i32, align 4
@DestY = external dso_local local_unnamed_addr global i32, align 4
@Sol = external dso_local local_unnamed_addr global [100 x [100 x i32]], align 16
@MoveX = external dso_local local_unnamed_addr global [4 x i32], align 16
@MoveY = external dso_local local_unnamed_addr global [4 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @DestX, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %0
  %5 = load i32, ptr @DestY, align 4
  %6 = icmp eq i32 %5, %1
  %or.cond = select i1 %4, i1 %6, i1 false
  br i1 %or.cond, label %12, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %7 = load i32, ptr @MoveX, align 16, !tbaa !5
  %8 = add nsw i32 %7, %0
  %9 = load i32, ptr @MoveY, align 16, !tbaa !5
  %10 = add nsw i32 %9, %1
  %11 = tail call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %8, i32 noundef %10)
  br i1 %11, label %16, label %.preheader.1

12:                                               ; preds = %2
  %13 = sext i32 %0 to i64
  %14 = sext i32 %1 to i64
  %15 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %13, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !5
  br label %.critedge

16:                                               ; preds = %.preheader.preheader
  %17 = sext i32 %8 to i64
  %18 = sext i32 %10 to i64
  %19 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %17, i64 %18
  store i32 1, ptr %19, align 4, !tbaa !5
  %20 = tail call noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %8, i32 noundef %10)
  br i1 %20, label %.critedge, label %21

21:                                               ; preds = %16
  store i32 0, ptr %19, align 4, !tbaa !5
  br label %.preheader.1

.preheader.1:                                     ; preds = %21, %.preheader.preheader
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @MoveX, i64 4), align 4, !tbaa !5
  %23 = add nsw i32 %22, %0
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @MoveY, i64 4), align 4, !tbaa !5
  %25 = add nsw i32 %24, %1
  %26 = tail call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %23, i32 noundef %25)
  br i1 %26, label %27, label %.preheader.2

27:                                               ; preds = %.preheader.1
  %28 = sext i32 %23 to i64
  %29 = sext i32 %25 to i64
  %30 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %28, i64 %29
  store i32 1, ptr %30, align 4, !tbaa !5
  %31 = tail call noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %23, i32 noundef %25)
  br i1 %31, label %.critedge, label %32

32:                                               ; preds = %27
  store i32 0, ptr %30, align 4, !tbaa !5
  br label %.preheader.2

.preheader.2:                                     ; preds = %32, %.preheader.1
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @MoveX, i64 8), align 8, !tbaa !5
  %34 = add nsw i32 %33, %0
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @MoveY, i64 8), align 8, !tbaa !5
  %36 = add nsw i32 %35, %1
  %37 = tail call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %34, i32 noundef %36)
  br i1 %37, label %38, label %.preheader.3

38:                                               ; preds = %.preheader.2
  %39 = sext i32 %34 to i64
  %40 = sext i32 %36 to i64
  %41 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %39, i64 %40
  store i32 1, ptr %41, align 4, !tbaa !5
  %42 = tail call noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %34, i32 noundef %36)
  br i1 %42, label %.critedge, label %43

43:                                               ; preds = %38
  store i32 0, ptr %41, align 4, !tbaa !5
  br label %.preheader.3

.preheader.3:                                     ; preds = %43, %.preheader.2
  %44 = load i32, ptr getelementptr inbounds (i8, ptr @MoveX, i64 12), align 4, !tbaa !5
  %45 = add nsw i32 %44, %0
  %46 = load i32, ptr getelementptr inbounds (i8, ptr @MoveY, i64 12), align 4, !tbaa !5
  %47 = add nsw i32 %46, %1
  %48 = tail call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %45, i32 noundef %47)
  br i1 %48, label %49, label %.critedge

49:                                               ; preds = %.preheader.3
  %50 = sext i32 %45 to i64
  %51 = sext i32 %47 to i64
  %52 = getelementptr inbounds [100 x [100 x i32]], ptr @Sol, i64 0, i64 %50, i64 %51
  store i32 1, ptr %52, align 4, !tbaa !5
  %53 = tail call noundef zeroext i1 @_Z16MazeSolveUtilityii(i32 noundef %45, i32 noundef %47)
  br i1 %53, label %.critedge, label %54

54:                                               ; preds = %49
  store i32 0, ptr %52, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %16, %27, %38, %49, %54, %.preheader.3, %12
  %.3 = phi i1 [ true, %12 ], [ true, %16 ], [ true, %27 ], [ true, %38 ], [ true, %49 ], [ false, %54 ], [ false, %.preheader.3 ]
  ret i1 %.3
}

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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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