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

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

%struct.Node = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, double, double, double, double, double, double, i8, i8, i8 }

@FirstNode = external dso_local global ptr, align 8
@ProblemType = external dso_local global i32, align 4
@BetterTour = external dso_local global ptr, align 8
@Dimension = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @RecordBetterTour() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  %3 = load ptr, ptr @FirstNode, align 8, !tbaa !9
  store ptr %3, ptr %1, align 8, !tbaa !9
  br label %4

4:                                                ; preds = %71, %0
  %5 = load i32, ptr @ProblemType, align 4, !tbaa !5
  %6 = icmp ne i32 %5, 1
  br i1 %6, label %7, label %16

7:                                                ; preds = %4
  %8 = load ptr, ptr %1, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = load ptr, ptr @BetterTour, align 8, !tbaa !9
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %11, i64 %14
  store i32 %10, ptr %15, align 4, !tbaa !5
  br label %60

16:                                               ; preds = %4
  %17 = load ptr, ptr %1, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr @Dimension, align 4, !tbaa !5
  %21 = sdiv i32 %20, 2
  %22 = icmp sle i32 %19, %21
  br i1 %22, label %23, label %59

23:                                               ; preds = %16
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  %26 = load ptr, ptr %1, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 16
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %1, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr @Dimension, align 4, !tbaa !5
  %35 = sdiv i32 %34, 2
  %36 = add nsw i32 %33, %35
  %37 = icmp ne i32 %30, %36
  br i1 %37, label %38, label %46

38:                                               ; preds = %23
  %39 = load ptr, ptr %1, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = load ptr, ptr @BetterTour, align 8, !tbaa !9
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !5
  br label %58

46:                                               ; preds = %23
  %47 = load ptr, ptr %1, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr @BetterTour, align 8, !tbaa !9
  %51 = load i32, ptr @Dimension, align 4, !tbaa !5
  %52 = sdiv i32 %51, 2
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %50, i64 %56
  store i32 %49, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %46, %38
  br label %59

59:                                               ; preds = %58, %16
  br label %60

60:                                               ; preds = %59, %7
  %61 = load ptr, ptr %1, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.Node, ptr %61, i32 0, i32 19
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load ptr, ptr %1, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.Node, ptr %64, i32 0, i32 20
  store ptr %63, ptr %65, align 8, !tbaa !16
  %66 = load ptr, ptr %1, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.Node, ptr %66, i32 0, i32 16
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = load ptr, ptr %1, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.Node, ptr %69, i32 0, i32 19
  store ptr %68, ptr %70, align 8, !tbaa !15
  br label %71

71:                                               ; preds = %60
  %72 = load ptr, ptr %1, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.Node, ptr %72, i32 0, i32 16
  %74 = load ptr, ptr %73, align 8, !tbaa !14
  store ptr %74, ptr %1, align 8, !tbaa !9
  %75 = load ptr, ptr @FirstNode, align 8, !tbaa !9
  %76 = icmp ne ptr %74, %75
  br i1 %76, label %4, label %77, !llvm.loop !17

77:                                               ; preds = %71
  %78 = load ptr, ptr @BetterTour, align 8, !tbaa !9
  %79 = load i32, ptr @ProblemType, align 4, !tbaa !5
  %80 = icmp ne i32 %79, 1
  br i1 %80, label %81, label %83

81:                                               ; preds = %77
  %82 = load i32, ptr @Dimension, align 4, !tbaa !5
  br label %86

83:                                               ; preds = %77
  %84 = load i32, ptr @Dimension, align 4, !tbaa !5
  %85 = sdiv i32 %84, 2
  br label %86

86:                                               ; preds = %83, %81
  %87 = phi i32 [ %82, %81 ], [ %85, %83 ]
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i32, ptr %78, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = load ptr, ptr @BetterTour, align 8, !tbaa !9
  %92 = getelementptr inbounds i32, ptr %91, i64 0
  store i32 %90, ptr %92, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

; 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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !13, i64 312, !13, i64 320, !13, i64 328, !13, i64 336, !13, i64 344, !13, i64 352, !7, i64 360, !7, i64 361, !7, i64 362}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !10, i64 72}
!15 = !{!12, !10, i64 96}
!16 = !{!12, !10, i64 104}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@FirstNode = external dso_local local_unnamed_addr global ptr, align 8
@ProblemType = external dso_local local_unnamed_addr global i32, align 4
@BetterTour = external dso_local local_unnamed_addr global ptr, align 8
@Dimension = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @RecordBetterTour() local_unnamed_addr #0 {
  %1 = load ptr, ptr @FirstNode, align 8, !tbaa !5
  %2 = load ptr, ptr @BetterTour, align 8
  br label %3

3:                                                ; preds = %19, %0
  %.014 = phi ptr [ %1, %0 ], [ %24, %19 ]
  %.0 = phi i32 [ 0, %0 ], [ %.1, %19 ]
  %4 = load i32, ptr @ProblemType, align 4, !tbaa !9
  %.not = icmp eq i32 %4, 1
  %5 = load i32, ptr %.014, align 8, !tbaa !11
  br i1 %.not, label %8, label %6

6:                                                ; preds = %3
  %7 = add nsw i32 %.0, 1
  br label %.sink.split

8:                                                ; preds = %3
  %9 = load i32, ptr @Dimension, align 4, !tbaa !9
  %10 = sdiv i32 %9, 2
  %.not18 = icmp sgt i32 %5, %10
  br i1 %.not18, label %19, label %11

11:                                               ; preds = %8
  %12 = add nsw i32 %.0, 1
  %13 = getelementptr inbounds i8, ptr %.014, i64 72
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = add nsw i32 %10, %5
  %.not19 = icmp eq i32 %15, %16
  %17 = sub nsw i32 %10, %12
  %spec.select = select i1 %.not19, i32 %17, i32 %12
  %spec.select23.idx = select i1 %.not19, i64 4, i64 0
  %spec.select23 = getelementptr i8, ptr %2, i64 %spec.select23.idx
  br label %.sink.split

.sink.split:                                      ; preds = %11, %6
  %.sink22 = phi i32 [ %7, %6 ], [ %spec.select, %11 ]
  %invariant.gep.sink = phi ptr [ %2, %6 ], [ %spec.select23, %11 ]
  %.1.ph = phi i32 [ %7, %6 ], [ %12, %11 ]
  %18 = sext i32 %.sink22 to i64
  %gep = getelementptr i32, ptr %invariant.gep.sink, i64 %18
  store i32 %5, ptr %gep, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %.sink.split, %8
  %.1 = phi i32 [ %.0, %8 ], [ %.1.ph, %.sink.split ]
  %20 = getelementptr inbounds i8, ptr %.014, i64 96
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %.014, i64 104
  store ptr %21, ptr %22, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %.014, i64 72
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  store ptr %24, ptr %20, align 8, !tbaa !15
  %.not20 = icmp eq ptr %24, %1
  br i1 %.not20, label %25, label %3, !llvm.loop !17

25:                                               ; preds = %19
  %26 = load i32, ptr @ProblemType, align 4, !tbaa !9
  %.not21 = icmp eq i32 %26, 1
  %27 = load i32, ptr @Dimension, align 4, !tbaa !9
  %28 = sdiv i32 %27, 2
  %29 = select i1 %.not21, i32 %28, i32 %27
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %2, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  store i32 %32, ptr %2, align 4, !tbaa !9
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"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, !10, i64 0}
!12 = !{!"Node", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !13, i64 312, !13, i64 320, !13, i64 328, !13, i64 336, !13, i64 344, !13, i64 352, !7, i64 360, !7, i64 361, !7, i64 362}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 72}
!15 = !{!12, !6, i64 96}
!16 = !{!12, !6, i64 104}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass