; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/DP/Bitmask DP/TravellingSalesman.ll (Z5solvexxx)

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

@dis = external dso_local global [21 x [21 x i64]], align 16
@dp = external dso_local global [21 x [2097152 x i64]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvexxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  %11 = load i64, ptr %6, align 8, !tbaa !5
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %22

13:                                               ; preds = %3
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds [21 x [21 x i64]], ptr @dis, i64 0, i64 %14
  %16 = getelementptr inbounds [21 x i64], ptr %15, i64 0, i64 0
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds [21 x [2097152 x i64]], ptr @dp, i64 0, i64 %18
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds [2097152 x i64], ptr %19, i64 0, i64 %20
  store i64 %17, ptr %21, align 8, !tbaa !5
  store i64 %17, ptr %4, align 8
  br label %73

22:                                               ; preds = %3
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds [21 x [2097152 x i64]], ptr @dp, i64 0, i64 %23
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds [2097152 x i64], ptr %24, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = icmp ne i64 %27, -1
  br i1 %28, label %29, label %35

29:                                               ; preds = %22
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds [21 x [2097152 x i64]], ptr @dp, i64 0, i64 %30
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds [2097152 x i64], ptr %31, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  store i64 %34, ptr %4, align 8
  br label %73

35:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 2147483647, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %68, %35
  %37 = load i64, ptr %9, align 8, !tbaa !5
  %38 = load i64, ptr %7, align 8, !tbaa !5
  %39 = icmp slt i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %71

41:                                               ; preds = %36
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %9, align 8, !tbaa !5
  %44 = trunc i64 %43 to i32
  %45 = shl i32 1, %44
  %46 = sext i32 %45 to i64
  %47 = and i64 %42, %46
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %67

49:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds [21 x [21 x i64]], ptr @dis, i64 0, i64 %50
  %52 = load i64, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds [21 x i64], ptr %51, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = load i64, ptr %9, align 8, !tbaa !5
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %9, align 8, !tbaa !5
  %58 = trunc i64 %57 to i32
  %59 = shl i32 1, %58
  %60 = sext i32 %59 to i64
  %61 = xor i64 %56, %60
  %62 = load i64, ptr %7, align 8, !tbaa !5
  %63 = call noundef i64 @_Z5solvexxx(i64 noundef %55, i64 noundef %61, i64 noundef %62)
  %64 = add nsw i64 %54, %63
  store i64 %64, ptr %10, align 8, !tbaa !5
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %66 = load i64, ptr %65, align 8, !tbaa !5
  store i64 %66, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %67

67:                                               ; preds = %49, %41
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %9, align 8, !tbaa !5
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %9, align 8, !tbaa !5
  br label %36, !llvm.loop !9

71:                                               ; preds = %40
  %72 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %72, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %73

73:                                               ; preds = %71, %29, %13
  %74 = load i64, ptr %4, align 8
  ret i64 %74
}

; 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 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = !{!"long long", !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"

@dis = external dso_local local_unnamed_addr global [21 x [21 x i64]], align 16
@dp = external dso_local local_unnamed_addr global [21 x [2097152 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5solvexxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %7, label %11

7:                                                ; preds = %3
  %8 = getelementptr inbounds [21 x [21 x i64]], ptr @dis, i64 0, i64 %0
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds [21 x [2097152 x i64]], ptr @dp, i64 0, i64 %0
  store i64 %9, ptr %10, align 16, !tbaa !5
  br label %33

11:                                               ; preds = %3
  %12 = getelementptr inbounds [21 x [2097152 x i64]], ptr @dp, i64 0, i64 %0, i64 %1
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %.not = icmp eq i64 %13, -1
  br i1 %.not, label %14, label %33

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 2147483647, ptr %4, align 8, !tbaa !5
  %15 = icmp sgt i64 %2, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %30, %14
  %16 = phi i64 [ 2147483647, %14 ], [ %31, %30 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %33

.lr.ph:                                           ; preds = %14, %30
  %17 = phi i64 [ %31, %30 ], [ 2147483647, %14 ]
  %.025 = phi i64 [ %32, %30 ], [ 0, %14 ]
  %18 = trunc i64 %.025 to i32
  %19 = shl nuw i32 1, %18
  %20 = sext i32 %19 to i64
  %21 = and i64 %20, %1
  %.not24 = icmp eq i64 %21, 0
  br i1 %.not24, label %30, label %22

22:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %23 = getelementptr inbounds [21 x [21 x i64]], ptr @dis, i64 0, i64 %0, i64 %.025
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = xor i64 %20, %1
  %26 = call noundef i64 @_Z5solvexxx(i64 noundef %.025, i64 noundef %25, i64 noundef %2)
  %27 = add nsw i64 %26, %24
  store i64 %27, ptr %5, align 8, !tbaa !5
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %29 = load i64, ptr %28, align 8, !tbaa !5
  store i64 %29, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %30

30:                                               ; preds = %.lr.ph, %22
  %31 = phi i64 [ %17, %.lr.ph ], [ %29, %22 ]
  %32 = add nuw nsw i64 %.025, 1
  %exitcond.not = icmp eq i64 %32, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

33:                                               ; preds = %11, %._crit_edge, %7
  %.020 = phi i64 [ %9, %7 ], [ %16, %._crit_edge ], [ %13, %11 ]
  ret i64 %.020
}

; 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 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = !{!"long long", !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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass