; LLVM IR from fcimeson/cbTSP :: cbLKH/SRC (BestKOptMove)

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

@Swaps = external dso_local global i32, align 4
@MoveType = external dso_local global i32, align 4
@SubsequentMoveType = external dso_local global i32, align 4
@K = external dso_local global i32, align 4
@t = external dso_local global ptr, align 8
@T = external dso_local global ptr, align 8
@BestG2 = external hidden global i64, align 8
@incl = external dso_local global ptr, align 8

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

13:                                               ; preds = %4
  %14 = load i32, ptr @MoveType, align 4, !tbaa !9
  br label %17

15:                                               ; preds = %4
  %16 = load i32, ptr @SubsequentMoveType, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %15, %13
  %18 = phi i32 [ %14, %13 ], [ %16, %15 ]
  store i32 %18, ptr @K, align 4, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr @t, align 8, !tbaa !5
  %22 = getelementptr inbounds ptr, ptr %21, i64 1
  store ptr %20, ptr %22, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr @t, align 8, !tbaa !5
  %25 = getelementptr inbounds ptr, ptr %24, i64 2
  store ptr %23, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr @T, align 8, !tbaa !5
  %27 = load i32, ptr @K, align 4, !tbaa !9
  %28 = mul nsw i32 2, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %26, i64 %29
  store ptr null, ptr %30, align 8, !tbaa !5
  store i64 -9223372036854775808, ptr @BestG2, align 8, !tbaa !11
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  call void @MarkDeleted(ptr noundef %31, ptr noundef %32)
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = call i64 @BestKOptMoveRec(i32 noundef 2, i64 noundef %34)
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %35, ptr %36, align 8, !tbaa !11
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  call void @UnmarkDeleted(ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = icmp sle i64 %40, 0
  br i1 %41, label %42, label %116

42:                                               ; preds = %17
  %43 = load ptr, ptr @T, align 8, !tbaa !5
  %44 = load i32, ptr @K, align 4, !tbaa !9
  %45 = mul nsw i32 2, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds ptr, ptr %43, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %116

50:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %51 = load ptr, ptr @t, align 8, !tbaa !5
  %52 = getelementptr inbounds ptr, ptr %51, i64 1
  %53 = load ptr, ptr @T, align 8, !tbaa !5
  %54 = getelementptr inbounds ptr, ptr %53, i64 1
  %55 = load i32, ptr @K, align 4, !tbaa !9
  %56 = mul nsw i32 2, %55
  %57 = sext i32 %56 to i64
  %58 = mul i64 %57, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %52, ptr align 8 %54, i64 %58, i1 false)
  store i32 2, ptr %10, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %75, %50
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = load i32, ptr @K, align 4, !tbaa !9
  %62 = mul nsw i32 2, %61
  %63 = icmp slt i32 %60, %62
  br i1 %63, label %64, label %78

64:                                               ; preds = %59
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = load ptr, ptr @incl, align 8, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  %69 = load ptr, ptr @incl, align 8, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  store i32 %68, ptr %72, align 4, !tbaa !9
  %73 = sext i32 %68 to i64
  %74 = getelementptr inbounds i32, ptr %66, i64 %73
  store i32 %65, ptr %74, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %64
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = add nsw i32 %76, 2
  store i32 %77, ptr %10, align 4, !tbaa !9
  br label %59, !llvm.loop !13

78:                                               ; preds = %59
  %79 = load ptr, ptr @incl, align 8, !tbaa !5
  %80 = load i32, ptr @K, align 4, !tbaa !9
  %81 = mul nsw i32 2, %80
  %82 = load ptr, ptr @incl, align 8, !tbaa !5
  %83 = getelementptr inbounds i32, ptr %82, i64 1
  store i32 %81, ptr %83, align 4, !tbaa !9
  %84 = sext i32 %81 to i64
  %85 = getelementptr inbounds i32, ptr %79, i64 %84
  store i32 1, ptr %85, align 4, !tbaa !9
  %86 = load i32, ptr @K, align 4, !tbaa !9
  call void @MakeKOptMove(i32 noundef %86)
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %104, %78
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = load i32, ptr @K, align 4, !tbaa !9
  %90 = mul nsw i32 2, %89
  %91 = icmp slt i32 %88, %90
  br i1 %91, label %92, label %107

92:                                               ; preds = %87
  %93 = load ptr, ptr @T, align 8, !tbaa !5
  %94 = load i32, ptr %10, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds ptr, ptr %93, i64 %95
  %97 = load ptr, ptr %96, align 8, !tbaa !5
  %98 = load ptr, ptr @T, align 8, !tbaa !5
  %99 = load i32, ptr %10, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds ptr, ptr %98, i64 %101
  %103 = load ptr, ptr %102, align 8, !tbaa !5
  call void @Exclude(ptr noundef %97, ptr noundef %103)
  br label %104

104:                                              ; preds = %92
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = add nsw i32 %105, 2
  store i32 %106, ptr %10, align 4, !tbaa !9
  br label %87, !llvm.loop !15

107:                                              ; preds = %87
  %108 = load i64, ptr @BestG2, align 8, !tbaa !11
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %108, ptr %109, align 8, !tbaa !11
  %110 = load ptr, ptr @T, align 8, !tbaa !5
  %111 = load i32, ptr @K, align 4, !tbaa !9
  %112 = mul nsw i32 2, %111
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds ptr, ptr %110, i64 %113
  %115 = load ptr, ptr %114, align 8, !tbaa !5
  store ptr %115, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %117

116:                                              ; preds = %42, %17
  store ptr null, ptr %5, align 8
  br label %117

117:                                              ; preds = %116, %107
  %118 = load ptr, ptr %5, align 8
  ret ptr %118
}

declare void @MarkDeleted(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @BestKOptMoveRec(i32 noundef, i64 noundef) #0

declare void @UnmarkDeleted(ptr noundef, ptr noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare void @MakeKOptMove(i32 noundef) #1

declare void @Exclude(ptr noundef, ptr noundef) #1

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

attributes #0 = { 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@Swaps = external dso_local local_unnamed_addr global i32, align 4
@MoveType = external dso_local local_unnamed_addr global i32, align 4
@SubsequentMoveType = external dso_local local_unnamed_addr global i32, align 4
@K = external dso_local local_unnamed_addr global i32, align 4
@t = external dso_local local_unnamed_addr global ptr, align 8
@T = external dso_local local_unnamed_addr global ptr, align 8
@BestG2 = external hidden local_unnamed_addr global i64, align 8
@incl = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @BestKOptMove(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr @Swaps, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 0
  %7 = load i32, ptr @MoveType, align 4
  %8 = load i32, ptr @SubsequentMoveType, align 4
  %9 = select i1 %6, i32 %7, i32 %8
  store i32 %9, ptr @K, align 4, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !9
  %10 = load ptr, ptr @t, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %0, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %1, ptr %12, align 8, !tbaa !11
  %13 = load ptr, ptr @T, align 8, !tbaa !11
  %14 = shl nsw i32 %9, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds ptr, ptr %13, i64 %15
  store ptr null, ptr %16, align 8, !tbaa !11
  store i64 -9223372036854775808, ptr @BestG2, align 8, !tbaa !9
  tail call void @MarkDeleted(ptr noundef %0, ptr noundef %1) #3
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = tail call i64 @BestKOptMoveRec(i32 noundef 2, i64 noundef %17)
  store i64 %18, ptr %3, align 8, !tbaa !9
  tail call void @UnmarkDeleted(ptr noundef %0, ptr noundef %1) #3
  %19 = load i64, ptr %3, align 8, !tbaa !9
  %20 = icmp slt i64 %19, 1
  br i1 %20, label %21, label %62

21:                                               ; preds = %4
  %22 = load ptr, ptr @T, align 8, !tbaa !11
  %23 = load i32, ptr @K, align 4, !tbaa !5
  %24 = shl nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %22, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %.not = icmp eq ptr %27, null
  br i1 %.not, label %62, label %28

28:                                               ; preds = %21
  %29 = load ptr, ptr @t, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = getelementptr inbounds i8, ptr %22, i64 8
  %32 = shl nsw i64 %25, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %30, ptr nonnull align 8 %31, i64 %32, i1 false)
  %33 = icmp sgt i32 %23, 1
  %.pre = load ptr, ptr @incl, align 8, !tbaa !11
  br i1 %33, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %28, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 2, %28 ]
  %34 = or disjoint i64 %indvars.iv, 1
  %35 = getelementptr inbounds i32, ptr %.pre, i64 %indvars.iv
  %36 = trunc nuw nsw i64 %34 to i32
  store i32 %36, ptr %35, align 4, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %.pre, i64 %34
  %38 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %38, ptr %37, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %39 = load i32, ptr @K, align 4, !tbaa !5
  %40 = shl nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = icmp slt i64 %indvars.iv.next, %41
  br i1 %42, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %28
  %.pre-phi = phi i64 [ %25, %28 ], [ %41, %.lr.ph ]
  %.lcssa22 = phi i32 [ %24, %28 ], [ %40, %.lr.ph ]
  %43 = getelementptr inbounds i8, ptr %.pre, i64 4
  store i32 %.lcssa22, ptr %43, align 4, !tbaa !5
  %44 = getelementptr inbounds i32, ptr %.pre, i64 %.pre-phi
  store i32 1, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr @K, align 4, !tbaa !5
  tail call void @MakeKOptMove(i32 noundef %45) #3
  %46 = load i32, ptr @K, align 4, !tbaa !5
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %.lr.ph26, label %._crit_edge.._crit_edge27_crit_edge

._crit_edge.._crit_edge27_crit_edge:              ; preds = %._crit_edge
  %48 = shl nsw i32 %46, 1
  %.pre35 = sext i32 %48 to i64
  br label %._crit_edge27

.lr.ph26:                                         ; preds = %._crit_edge, %.lr.ph26
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph26 ], [ 1, %._crit_edge ]
  %49 = load ptr, ptr @T, align 8, !tbaa !11
  %50 = getelementptr inbounds ptr, ptr %49, i64 %indvars.iv32
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds i8, ptr %50, i64 8
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  tail call void @Exclude(ptr noundef %51, ptr noundef %53) #3
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 2
  %54 = load i32, ptr @K, align 4, !tbaa !5
  %55 = shl nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = icmp slt i64 %indvars.iv.next33, %56
  br i1 %57, label %.lr.ph26, label %._crit_edge27, !llvm.loop !15

._crit_edge27:                                    ; preds = %.lr.ph26, %._crit_edge.._crit_edge27_crit_edge
  %.pre-phi36 = phi i64 [ %.pre35, %._crit_edge.._crit_edge27_crit_edge ], [ %56, %.lr.ph26 ]
  %58 = load i64, ptr @BestG2, align 8, !tbaa !9
  store i64 %58, ptr %2, align 8, !tbaa !9
  %59 = load ptr, ptr @T, align 8, !tbaa !11
  %60 = getelementptr inbounds ptr, ptr %59, i64 %.pre-phi36
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  br label %62

62:                                               ; preds = %4, %21, %._crit_edge27
  %.020 = phi ptr [ %61, %._crit_edge27 ], [ null, %21 ], [ null, %4 ]
  ret ptr %.020
}

declare void @MarkDeleted(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @BestKOptMoveRec(i32 noundef, i64 noundef) local_unnamed_addr #0

declare void @UnmarkDeleted(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare void @MakeKOptMove(i32 noundef) local_unnamed_addr #1

declare void @Exclude(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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