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

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

@p = external dso_local global ptr, align 8
@q = external dso_local global ptr, align 8
@incl = external dso_local global ptr, align 8
@cycle = external dso_local global ptr, align 8

; 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: nounwind uwtable
define dso_local i32 @Cycles(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %16, %1
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = mul nsw i32 2, %8
  %10 = icmp sle i32 %7, %9
  br i1 %10, label %11, label %19

11:                                               ; preds = %6
  %12 = load ptr, ptr @cycle, align 8, !tbaa !9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %12, i64 %14
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !11

19:                                               ; preds = %6
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %85, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = mul nsw i32 2, %22
  %24 = icmp sle i32 %21, %23
  br i1 %24, label %25, label %88

25:                                               ; preds = %20
  %26 = load ptr, ptr @cycle, align 8, !tbaa !9
  %27 = load ptr, ptr @p, align 8, !tbaa !9
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %26, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %84, label %36

36:                                               ; preds = %25
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %39, ptr %4, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %79, %36
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load ptr, ptr @cycle, align 8, !tbaa !9
  %43 = load ptr, ptr @p, align 8, !tbaa !9
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %42, i64 %48
  store i32 %41, ptr %49, align 4, !tbaa !5
  %50 = load ptr, ptr @q, align 8, !tbaa !9
  %51 = load ptr, ptr @incl, align 8, !tbaa !9
  %52 = load ptr, ptr @p, align 8, !tbaa !9
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %51, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %50, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  store i32 %62, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = load ptr, ptr @cycle, align 8, !tbaa !9
  %65 = load ptr, ptr @p, align 8, !tbaa !9
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i32, ptr %64, i64 %70
  store i32 %63, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = xor i32 %72, 1
  store i32 %73, ptr %4, align 4, !tbaa !5
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = mul nsw i32 2, %74
  %76 = icmp sgt i32 %73, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %40
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %77, %40
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = icmp ne i32 %80, %81
  br i1 %82, label %40, label %83, !llvm.loop !13

83:                                               ; preds = %79
  br label %84

84:                                               ; preds = %83, %25
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !14

88:                                               ; preds = %20
  %89 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %89
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@p = external dso_local local_unnamed_addr global ptr, align 8
@q = external dso_local local_unnamed_addr global ptr, align 8
@incl = external dso_local local_unnamed_addr global ptr, align 8
@cycle = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @Cycles(i32 noundef %0) local_unnamed_addr #0 {
  %2 = shl i32 %0, 1
  %.not27 = icmp slt i32 %0, 1
  br i1 %.not27, label %._crit_edge, label %.lr.ph32

.lr.ph32:                                         ; preds = %1
  %3 = load ptr, ptr @cycle, align 8, !tbaa !5
  %scevgep = getelementptr i8, ptr %3, i64 4
  %smax = tail call i32 @llvm.smax.i32(i32 %2, i32 1)
  %4 = zext nneg i32 %smax to i64
  %5 = shl nuw nsw i64 %4, 2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %scevgep, i8 0, i64 %5, i1 false), !tbaa !9
  %6 = load ptr, ptr @p, align 8, !tbaa !5
  %7 = load ptr, ptr @q, align 8
  %8 = load ptr, ptr @incl, align 8
  %smax36 = tail call i32 @llvm.smax.i32(i32 %2, i32 1)
  %9 = add nuw nsw i32 %smax36, 1
  %wide.trip.count = zext nneg i32 %9 to i64
  br label %10

10:                                               ; preds = %.lr.ph32, %.loopexit
  %indvars.iv = phi i64 [ 1, %.lr.ph32 ], [ %indvars.iv.next, %.loopexit ]
  %.031 = phi i32 [ 0, %.lr.ph32 ], [ %.1, %.loopexit ]
  %11 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr %3, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not25 = icmp eq i32 %15, 0
  br i1 %.not25, label %16, label %.loopexit

16:                                               ; preds = %10
  %17 = add nsw i32 %.031, 1
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  br label %19

19:                                               ; preds = %19, %16
  %.020 = phi i32 [ %18, %16 ], [ %spec.store.select, %19 ]
  %20 = sext i32 %.020 to i64
  %21 = getelementptr inbounds i32, ptr %6, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %3, i64 %23
  store i32 %17, ptr %24, align 4, !tbaa !9
  %25 = load i32, ptr %21, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %8, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %7, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %6, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %3, i64 %35
  store i32 %17, ptr %36, align 4, !tbaa !9
  %37 = xor i32 %31, 1
  %38 = icmp sgt i32 %37, %2
  %spec.store.select = select i1 %38, i32 1, i32 %37
  %39 = zext i32 %spec.store.select to i64
  %.not26 = icmp eq i64 %indvars.iv, %39
  br i1 %.not26, label %.loopexit, label %19, !llvm.loop !11

.loopexit:                                        ; preds = %19, %10
  %.1 = phi i32 [ %.031, %10 ], [ %17, %19 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !13

._crit_edge:                                      ; preds = %.loopexit, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ %.1, %.loopexit ]
  ret i32 %.0.lcssa
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


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