; LLVM IR from ncduy0303/Competitive-Programming :: Dynamic Programming/Traveling Salesman Problem (TSP).ll (Z3tspii)

; 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
@adj = external dso_local global [11 x [11 x i32]], align 16
@dp = external dso_local global [2048 x [11 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3tspii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = shl i32 1, %10
  %12 = sub nsw i32 %11, 1
  %13 = icmp eq i32 %9, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [11 x [11 x i32]], ptr @adj, i64 0, i64 %16
  %18 = getelementptr inbounds [11 x i32], ptr %17, i64 0, i64 0
  %19 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %19, ptr %3, align 4
  br label %78

20:                                               ; preds = %2
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2048 x [11 x i32]], ptr @dp, i64 0, i64 %22
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [11 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp ne i32 %27, -1
  br i1 %28, label %29, label %37

29:                                               ; preds = %20
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2048 x [11 x i32]], ptr @dp, i64 0, i64 %31
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [11 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4
  br label %78

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

38:                                               ; preds = %67, %37
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

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

43:                                               ; preds = %38
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = shl i32 1, %45
  %47 = and i32 %44, %46
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %66, label %49

49:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [11 x [11 x i32]], ptr @adj, i64 0, i64 %51
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [11 x i32], ptr %52, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = shl i32 1, %58
  %60 = or i32 %57, %59
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = call noundef i32 @_Z3tspii(i32 noundef %60, i32 noundef %61)
  %63 = add nsw i32 %56, %62
  store i32 %63, ptr %8, align 4, !tbaa !5
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %65 = load i32, ptr %64, align 4, !tbaa !5
  store i32 %65, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %66

66:                                               ; preds = %49, %43
  br label %67

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

70:                                               ; preds = %42
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [2048 x [11 x i32]], ptr @dp, i64 0, i64 %73
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [11 x i32], ptr %74, i64 0, i64 %76
  store i32 %71, ptr %77, align 4, !tbaa !5
  store i32 %71, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %78

78:                                               ; preds = %70, %29, %14
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = !{!"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
@adj = external dso_local local_unnamed_addr global [11 x [11 x i32]], align 16
@dp = external dso_local local_unnamed_addr global [2048 x [11 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3tspii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %5
  %6 = xor i32 %notmask, %0
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %8, label %12

8:                                                ; preds = %2
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds [11 x [11 x i32]], ptr @adj, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  br label %38

12:                                               ; preds = %2
  %13 = sext i32 %0 to i64
  %14 = sext i32 %1 to i64
  %15 = getelementptr inbounds [2048 x [11 x i32]], ptr @dp, i64 0, i64 %13, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not = icmp eq i32 %16, -1
  br i1 %.not, label %17, label %38

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 1000000000, ptr %3, align 4, !tbaa !5
  %18 = icmp sgt i32 %5, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %33, %17
  %19 = phi i32 [ 1000000000, %17 ], [ %34, %33 ]
  store i32 %19, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %38

.lr.ph:                                           ; preds = %17, %33
  %20 = phi i32 [ %34, %33 ], [ 1000000000, %17 ]
  %21 = phi i32 [ %35, %33 ], [ %5, %17 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %33 ], [ 0, %17 ]
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  %23 = shl nuw i32 1, %22
  %24 = and i32 %23, %0
  %.not21 = icmp eq i32 %24, 0
  br i1 %.not21, label %25, label %33

25:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %26 = getelementptr inbounds [11 x [11 x i32]], ptr @adj, i64 0, i64 %14, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = or i32 %23, %0
  %29 = call noundef i32 @_Z3tspii(i32 noundef %28, i32 noundef %22)
  %30 = add nsw i32 %29, %27
  store i32 %30, ptr %4, align 4, !tbaa !5
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %.lr.ph, %25
  %34 = phi i32 [ %20, %.lr.ph ], [ %32, %25 ]
  %35 = phi i32 [ %21, %.lr.ph ], [ %.pre, %25 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next, %36
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !9

38:                                               ; preds = %12, %._crit_edge, %8
  %.018 = phi i32 [ %11, %8 ], [ %19, %._crit_edge ], [ %16, %12 ]
  ret i32 %.018
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass