; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Backtracking/Hamiltonian Cycle.ll (Z15HamiltonUtilityi)

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

@V = external dso_local global i32, align 4
@Path = external dso_local global [100 x i32], align 16
@Graph = external dso_local global [100 x [100 x i32]], align 16
@Valid = external dso_local global [100 x i8], 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 @_Z15HamiltonUtilityi(i32 noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr @V, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %24

9:                                                ; preds = %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sub nsw i32 %10, 1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100 x i32], ptr @Path, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100 x [100 x i32]], ptr @Graph, i64 0, i64 %15
  %17 = load i32, ptr @Path, align 16, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100 x i32], ptr %16, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %9
  store i1 true, ptr %2, align 1
  br label %61

23:                                               ; preds = %9
  store i1 false, ptr %2, align 1
  br label %61

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

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

29:                                               ; preds = %25
  store i32 2, ptr %5, align 4
  br label %58

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

34:                                               ; preds = %30
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x i32], ptr @Path, i64 0, i64 %37
  store i32 %35, ptr %38, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100 x i8], ptr @Valid, i64 0, i64 %40
  store i8 1, ptr %41, align 1, !tbaa !9
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = call noundef zeroext i1 @_Z15HamiltonUtilityi(i32 noundef %43)
  br i1 %44, label %45, label %46

45:                                               ; preds = %34
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %58

46:                                               ; preds = %34
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x i32], ptr @Path, i64 0, i64 %48
  store i32 -1, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100 x i8], ptr @Valid, i64 0, i64 %51
  store i8 0, ptr %52, align 1, !tbaa !9
  br label %53

53:                                               ; preds = %46
  br label %54

54:                                               ; preds = %53, %30
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %4, align 4, !tbaa !5
  br label %25, !llvm.loop !11

58:                                               ; preds = %45, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %59 = load i32, ptr %5, align 4
  switch i32 %59, label %63 [
    i32 2, label %60
    i32 1, label %61
  ]

60:                                               ; preds = %58
  store i1 false, ptr %2, align 1
  br label %61

61:                                               ; preds = %60, %58, %23, %22
  %62 = load i1, ptr %2, align 1
  ret i1 %62

63:                                               ; preds = %58
  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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@V = external dso_local local_unnamed_addr global i32, align 4
@Path = external dso_local local_unnamed_addr global [100 x i32], align 16
@Graph = external dso_local local_unnamed_addr global [100 x [100 x i32]], align 16
@Valid = external dso_local local_unnamed_addr global [100 x i8], 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 @_Z15HamiltonUtilityi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @V, align 4, !tbaa !5
  %3 = icmp eq i32 %2, %0
  br i1 %3, label %7, label %.preheader

.preheader:                                       ; preds = %1
  %.not1718 = icmp sgt i32 %2, 1
  br i1 %.not1718, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [100 x i32], ptr @Path, i64 0, i64 %4
  %6 = add nsw i32 %0, 1
  br label %17

7:                                                ; preds = %1
  %8 = add nsw i32 %0, -1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100 x i32], ptr @Path, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr @Path, align 16, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100 x [100 x i32]], ptr @Graph, i64 0, i64 %12, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not = icmp ne i32 %16, 0
  br label %.loopexit

17:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  %19 = tail call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %18, i32 noundef %0)
  br i1 %19, label %20, label %24

20:                                               ; preds = %17
  store i32 %18, ptr %5, align 4, !tbaa !5
  %21 = getelementptr inbounds [100 x i8], ptr @Valid, i64 0, i64 %indvars.iv
  store i8 1, ptr %21, align 1, !tbaa !9
  %22 = tail call noundef zeroext i1 @_Z15HamiltonUtilityi(i32 noundef %6)
  br i1 %22, label %.loopexit, label %23

23:                                               ; preds = %20
  store i32 -1, ptr %5, align 4, !tbaa !5
  store i8 0, ptr %21, align 1, !tbaa !9
  br label %24

24:                                               ; preds = %17, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr @V, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %.not17 = icmp slt i64 %indvars.iv.next, %26
  br i1 %.not17, label %17, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %20, %24, %.preheader, %7
  %.1 = phi i1 [ %.not, %7 ], [ false, %.preheader ], [ true, %20 ], [ false, %24 ]
  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" }

!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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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