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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@visitTime = external dso_local global [11 x [11 x i32]], align 16
@dr = external dso_local global [8 x i32], align 16
@dc = external dso_local global [8 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9printPathv() #0

; 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: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5validii(i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7solveKTiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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
  store i32 %2, ptr %6, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = load i32, ptr @m, align 4, !tbaa !5
  %13 = mul nsw i32 %11, %12
  %14 = icmp eq i32 %10, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  call void @_Z9printPathv()
  br label %60

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %56, %16
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 8
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %59

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [8 x i32], ptr @dr, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %22, %26
  store i32 %27, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [8 x i32], ptr @dc, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %28, %32
  store i32 %33, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = call noundef zeroext i1 @_Z5validii(i32 noundef %34, i32 noundef %35)
  br i1 %36, label %37, label %55

37:                                               ; preds = %21
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %40
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [11 x i32], ptr %41, i64 0, i64 %43
  store i32 %38, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  call void @_Z7solveKTiii(i32 noundef %45, i32 noundef %46, i32 noundef %48)
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %50
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [11 x i32], ptr %51, i64 0, i64 %53
  store i32 -1, ptr %54, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %37, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !5
  br label %17, !llvm.loop !9

59:                                               ; preds = %20
  br label %60

60:                                               ; preds = %59, %15
  ret void
}

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 = { 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 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@visitTime = external dso_local local_unnamed_addr global [11 x [11 x i32]], align 16
@dr = external dso_local local_unnamed_addr global [8 x i32], align 16
@dc = external dso_local local_unnamed_addr global [8 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9printPathv() local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7solveKTiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = mul nsw i32 %5, %4
  %7 = icmp eq i32 %6, %2
  br i1 %7, label %14, label %.preheader

.preheader:                                       ; preds = %3
  %8 = add nsw i32 %2, 1
  %9 = load i32, ptr @dr, align 16, !tbaa !5
  %10 = add nsw i32 %9, %0
  %11 = load i32, ptr @dc, align 16, !tbaa !5
  %12 = add nsw i32 %11, %1
  %13 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %10, i32 noundef %12)
  br i1 %13, label %15, label %19

14:                                               ; preds = %3
  tail call void @_Z9printPathv()
  br label %common.ret

15:                                               ; preds = %.preheader
  %16 = sext i32 %10 to i64
  %17 = sext i32 %12 to i64
  %18 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %16, i64 %17
  store i32 %2, ptr %18, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %10, i32 noundef %12, i32 noundef %8)
  store i32 -1, ptr %18, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %15, %.preheader
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 4), align 4, !tbaa !5
  %21 = add nsw i32 %20, %0
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 4), align 4, !tbaa !5
  %23 = add nsw i32 %22, %1
  %24 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %21, i32 noundef %23)
  br i1 %24, label %25, label %29

25:                                               ; preds = %19
  %26 = sext i32 %21 to i64
  %27 = sext i32 %23 to i64
  %28 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %26, i64 %27
  store i32 %2, ptr %28, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %21, i32 noundef %23, i32 noundef %8)
  store i32 -1, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %25, %19
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 8), align 8, !tbaa !5
  %31 = add nsw i32 %30, %0
  %32 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 8), align 8, !tbaa !5
  %33 = add nsw i32 %32, %1
  %34 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %31, i32 noundef %33)
  br i1 %34, label %35, label %39

35:                                               ; preds = %29
  %36 = sext i32 %31 to i64
  %37 = sext i32 %33 to i64
  %38 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %36, i64 %37
  store i32 %2, ptr %38, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %31, i32 noundef %33, i32 noundef %8)
  store i32 -1, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %35, %29
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 12), align 4, !tbaa !5
  %41 = add nsw i32 %40, %0
  %42 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 12), align 4, !tbaa !5
  %43 = add nsw i32 %42, %1
  %44 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %41, i32 noundef %43)
  br i1 %44, label %45, label %49

45:                                               ; preds = %39
  %46 = sext i32 %41 to i64
  %47 = sext i32 %43 to i64
  %48 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %46, i64 %47
  store i32 %2, ptr %48, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %41, i32 noundef %43, i32 noundef %8)
  store i32 -1, ptr %48, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %45, %39
  %50 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 16), align 16, !tbaa !5
  %51 = add nsw i32 %50, %0
  %52 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 16), align 16, !tbaa !5
  %53 = add nsw i32 %52, %1
  %54 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %51, i32 noundef %53)
  br i1 %54, label %55, label %59

55:                                               ; preds = %49
  %56 = sext i32 %51 to i64
  %57 = sext i32 %53 to i64
  %58 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %56, i64 %57
  store i32 %2, ptr %58, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %51, i32 noundef %53, i32 noundef %8)
  store i32 -1, ptr %58, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %55, %49
  %60 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 20), align 4, !tbaa !5
  %61 = add nsw i32 %60, %0
  %62 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 20), align 4, !tbaa !5
  %63 = add nsw i32 %62, %1
  %64 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %61, i32 noundef %63)
  br i1 %64, label %65, label %69

65:                                               ; preds = %59
  %66 = sext i32 %61 to i64
  %67 = sext i32 %63 to i64
  %68 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %66, i64 %67
  store i32 %2, ptr %68, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %61, i32 noundef %63, i32 noundef %8)
  store i32 -1, ptr %68, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %65, %59
  %70 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 24), align 8, !tbaa !5
  %71 = add nsw i32 %70, %0
  %72 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 24), align 8, !tbaa !5
  %73 = add nsw i32 %72, %1
  %74 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %71, i32 noundef %73)
  br i1 %74, label %75, label %79

75:                                               ; preds = %69
  %76 = sext i32 %71 to i64
  %77 = sext i32 %73 to i64
  %78 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %76, i64 %77
  store i32 %2, ptr %78, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %71, i32 noundef %73, i32 noundef %8)
  store i32 -1, ptr %78, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %75, %69
  %80 = load i32, ptr getelementptr inbounds (i8, ptr @dr, i64 28), align 4, !tbaa !5
  %81 = add nsw i32 %80, %0
  %82 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 28), align 4, !tbaa !5
  %83 = add nsw i32 %82, %1
  %84 = tail call noundef zeroext i1 @_Z5validii(i32 noundef %81, i32 noundef %83)
  br i1 %84, label %85, label %common.ret

common.ret:                                       ; preds = %14, %79, %85
  ret void

85:                                               ; preds = %79
  %86 = sext i32 %81 to i64
  %87 = sext i32 %83 to i64
  %88 = getelementptr inbounds [11 x [11 x i32]], ptr @visitTime, i64 0, i64 %86, i64 %87
  store i32 %2, ptr %88, align 4, !tbaa !5
  tail call void @_Z7solveKTiii(i32 noundef %81, i32 noundef %83, i32 noundef %8)
  store i32 -1, ptr %88, align 4, !tbaa !5
  br label %common.ret
}

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 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass