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

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

; Function Attrs: nounwind uwtable
define dso_local void @swapfunc(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp sle i32 %17, 1
  br i1 %18, label %19, label %40

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = udiv i64 %21, 8
  store i64 %22, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %24, ptr %11, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %35, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !11
  store i64 %27, ptr %12, align 8, !tbaa !11
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %30, i32 1
  store ptr %31, ptr %10, align 8, !tbaa !5
  store i64 %29, ptr %30, align 8, !tbaa !11
  %32 = load i64, ptr %12, align 8, !tbaa !11
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds i64, ptr %33, i32 1
  store ptr %34, ptr %11, align 8, !tbaa !5
  store i64 %32, ptr %33, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %35

35:                                               ; preds = %25
  %36 = load i64, ptr %9, align 8, !tbaa !11
  %37 = add nsw i64 %36, -1
  store i64 %37, ptr %9, align 8, !tbaa !11
  %38 = icmp sgt i64 %37, 0
  br i1 %38, label %25, label %39, !llvm.loop !13

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %61

40:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = udiv i64 %42, 1
  store i64 %43, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %44, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %45, ptr %15, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %56, %40
  call void @llvm.lifetime.start.p0(i64 1, ptr %16) #2
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !15
  store i8 %48, ptr %16, align 1, !tbaa !15
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = load i8, ptr %49, align 1, !tbaa !15
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %14, align 8, !tbaa !5
  store i8 %50, ptr %51, align 1, !tbaa !15
  %53 = load i8, ptr %16, align 1, !tbaa !15
  %54 = load ptr, ptr %15, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %15, align 8, !tbaa !5
  store i8 %53, ptr %54, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 1, ptr %16) #2
  br label %56

56:                                               ; preds = %46
  %57 = load i64, ptr %13, align 8, !tbaa !11
  %58 = add nsw i64 %57, -1
  store i64 %58, ptr %13, align 8, !tbaa !11
  %59 = icmp sgt i64 %58, 0
  br i1 %59, label %46, label %60, !llvm.loop !16

60:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %61

61:                                               ; preds = %60, %39
  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 = !{!"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", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @swapfunc(ptr nocapture noundef %0, ptr nocapture noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %3, 2
  %6 = sext i32 %2 to i64
  br i1 %5, label %12, label %iter.check

iter.check:                                       ; preds = %4
  %7 = tail call i64 @llvm.smax.i64(i64 %6, i64 1)
  %min.iters.check = icmp slt i32 %2, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %iter.check
  %scevgep = getelementptr i8, ptr %0, i64 %6
  %scevgep27 = getelementptr i8, ptr %1, i64 %6
  %bound0 = icmp ugt ptr %scevgep27, %0
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %vec.epilog.scalar.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check29 = icmp slt i32 %2, 32
  br i1 %min.iters.check29, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %7, 2147483616
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %0, i64 %index
  %next.gep31 = getelementptr i8, ptr %1, i64 %index
  %8 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <16 x i8>, ptr %next.gep, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  %wide.load33 = load <16 x i8>, ptr %8, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  %9 = getelementptr i8, ptr %next.gep31, i64 16
  %wide.load34 = load <16 x i8>, ptr %next.gep31, align 1, !tbaa !5, !alias.scope !11
  %wide.load35 = load <16 x i8>, ptr %9, align 1, !tbaa !5, !alias.scope !11
  store <16 x i8> %wide.load34, ptr %next.gep, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  store <16 x i8> %wide.load35, ptr %8, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  store <16 x i8> %wide.load, ptr %next.gep31, align 1, !tbaa !5, !alias.scope !11
  store <16 x i8> %wide.load33, ptr %9, align 1, !tbaa !5, !alias.scope !11
  %index.next = add nuw i64 %index, 32
  %10 = icmp eq i64 %index.next, %n.vec
  br i1 %10, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %7, %n.vec
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end43 = getelementptr i8, ptr %1, i64 %n.vec
  %ind.end40 = getelementptr i8, ptr %0, i64 %n.vec
  %ind.end38 = sub nsw i64 %6, %n.vec
  %n.vec.remaining = and i64 %7, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %vector.memcheck, %iter.check, %vec.epilog.iter.check
  %.020.ph = phi i64 [ %6, %iter.check ], [ %6, %vector.memcheck ], [ %ind.end38, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.019.ph = phi ptr [ %0, %iter.check ], [ %0, %vector.memcheck ], [ %ind.end40, %vec.epilog.iter.check ], [ %ind.end39, %vec.epilog.middle.block ]
  %.018.ph = phi ptr [ %1, %iter.check ], [ %1, %vector.memcheck ], [ %ind.end43, %vec.epilog.iter.check ], [ %ind.end42, %vec.epilog.middle.block ]
  br label %vec.epilog.scalar.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec37 = and i64 %7, 2147483640
  %ind.end = sub nsw i64 %6, %n.vec37
  %ind.end39 = getelementptr i8, ptr %0, i64 %n.vec37
  %ind.end42 = getelementptr i8, ptr %1, i64 %n.vec37
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index45 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next50, %vec.epilog.vector.body ]
  %next.gep46 = getelementptr i8, ptr %0, i64 %index45
  %next.gep47 = getelementptr i8, ptr %1, i64 %index45
  %wide.load48 = load <8 x i8>, ptr %next.gep46, align 1, !tbaa !5, !alias.scope !17, !noalias !20
  %wide.load49 = load <8 x i8>, ptr %next.gep47, align 1, !tbaa !5, !alias.scope !20
  store <8 x i8> %wide.load49, ptr %next.gep46, align 1, !tbaa !5, !alias.scope !17, !noalias !20
  store <8 x i8> %wide.load48, ptr %next.gep47, align 1, !tbaa !5, !alias.scope !20
  %index.next50 = add nuw i64 %index45, 8
  %11 = icmp eq i64 %index.next50, %n.vec37
  br i1 %11, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !22

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n51 = icmp eq i64 %7, %n.vec37
  br i1 %cmp.n51, label %.loopexit, label %vec.epilog.scalar.ph.preheader

12:                                               ; preds = %4
  %13 = lshr i64 %6, 3
  %14 = add nuw nsw i64 %13, 1
  %15 = icmp ugt i32 %2, 7
  %umin58.neg = sext i1 %15 to i64
  %16 = add nsw i64 %14, %umin58.neg
  %min.iters.check60 = icmp ult i64 %16, 14
  br i1 %min.iters.check60, label %scalar.ph.preheader, label %vector.memcheck52

vector.memcheck52:                                ; preds = %12
  %17 = and i64 %6, -8
  %18 = icmp ugt i32 %2, 7
  %19 = select i1 %18, i64 %17, i64 8
  %scevgep53 = getelementptr i8, ptr %0, i64 %19
  %scevgep54 = getelementptr i8, ptr %1, i64 %19
  %bound055 = icmp ugt ptr %scevgep54, %0
  %bound156 = icmp ugt ptr %scevgep53, %1
  %found.conflict57 = and i1 %bound055, %bound156
  br i1 %found.conflict57, label %scalar.ph.preheader, label %vector.ph61

vector.ph61:                                      ; preds = %vector.memcheck52
  %n.vec63 = and i64 %16, -4
  %20 = shl i64 %n.vec63, 3
  %ind.end64 = getelementptr i8, ptr %1, i64 %20
  %21 = shl i64 %n.vec63, 3
  %ind.end66 = getelementptr i8, ptr %0, i64 %21
  %ind.end68 = sub i64 %13, %n.vec63
  br label %vector.body70

vector.body70:                                    ; preds = %vector.body70, %vector.ph61
  %index71 = phi i64 [ 0, %vector.ph61 ], [ %index.next81, %vector.body70 ]
  %offset.idx = shl i64 %index71, 3
  %next.gep72 = getelementptr i8, ptr %1, i64 %offset.idx
  %offset.idx74 = shl i64 %index71, 3
  %next.gep75 = getelementptr i8, ptr %0, i64 %offset.idx74
  %22 = getelementptr i8, ptr %next.gep75, i64 16
  %wide.load77 = load <2 x i64>, ptr %next.gep75, align 8, !tbaa !23, !alias.scope !25, !noalias !28
  %wide.load78 = load <2 x i64>, ptr %22, align 8, !tbaa !23, !alias.scope !25, !noalias !28
  %23 = getelementptr i8, ptr %next.gep72, i64 16
  %wide.load79 = load <2 x i64>, ptr %next.gep72, align 8, !tbaa !23, !alias.scope !28
  %wide.load80 = load <2 x i64>, ptr %23, align 8, !tbaa !23, !alias.scope !28
  store <2 x i64> %wide.load79, ptr %next.gep75, align 8, !tbaa !23, !alias.scope !25, !noalias !28
  store <2 x i64> %wide.load80, ptr %22, align 8, !tbaa !23, !alias.scope !25, !noalias !28
  store <2 x i64> %wide.load77, ptr %next.gep72, align 8, !tbaa !23, !alias.scope !28
  store <2 x i64> %wide.load78, ptr %23, align 8, !tbaa !23, !alias.scope !28
  %index.next81 = add nuw i64 %index71, 4
  %24 = icmp eq i64 %index.next81, %n.vec63
  br i1 %24, label %middle.block59, label %vector.body70, !llvm.loop !30

middle.block59:                                   ; preds = %vector.body70
  %cmp.n82 = icmp eq i64 %16, %n.vec63
  br i1 %cmp.n82, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block59, %vector.memcheck52, %12
  %.022.ph = phi ptr [ %1, %vector.memcheck52 ], [ %1, %12 ], [ %ind.end64, %middle.block59 ]
  %.021.ph = phi ptr [ %0, %vector.memcheck52 ], [ %0, %12 ], [ %ind.end66, %middle.block59 ]
  %.0.ph = phi i64 [ %13, %vector.memcheck52 ], [ %13, %12 ], [ %ind.end68, %middle.block59 ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.022 = phi ptr [ %28, %scalar.ph ], [ %.022.ph, %scalar.ph.preheader ]
  %.021 = phi ptr [ %27, %scalar.ph ], [ %.021.ph, %scalar.ph.preheader ]
  %.0 = phi i64 [ %29, %scalar.ph ], [ %.0.ph, %scalar.ph.preheader ]
  %25 = load i64, ptr %.021, align 8, !tbaa !23
  %26 = load i64, ptr %.022, align 8, !tbaa !23
  %27 = getelementptr inbounds i8, ptr %.021, i64 8
  store i64 %26, ptr %.021, align 8, !tbaa !23
  %28 = getelementptr inbounds i8, ptr %.022, i64 8
  store i64 %25, ptr %.022, align 8, !tbaa !23
  %29 = add nsw i64 %.0, -1
  %30 = icmp ugt i64 %.0, 1
  br i1 %30, label %scalar.ph, label %.loopexit, !llvm.loop !31

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph
  %.020 = phi i64 [ %35, %vec.epilog.scalar.ph ], [ %.020.ph, %vec.epilog.scalar.ph.preheader ]
  %.019 = phi ptr [ %33, %vec.epilog.scalar.ph ], [ %.019.ph, %vec.epilog.scalar.ph.preheader ]
  %.018 = phi ptr [ %34, %vec.epilog.scalar.ph ], [ %.018.ph, %vec.epilog.scalar.ph.preheader ]
  %31 = load i8, ptr %.019, align 1, !tbaa !5
  %32 = load i8, ptr %.018, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.019, i64 1
  store i8 %32, ptr %.019, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.018, i64 1
  store i8 %31, ptr %.018, align 1, !tbaa !5
  %35 = add nsw i64 %.020, -1
  %36 = icmp sgt i64 %.020, 1
  br i1 %36, label %vec.epilog.scalar.ph, label %.loopexit, !llvm.loop !32

.loopexit:                                        ; preds = %vec.epilog.scalar.ph, %scalar.ph, %middle.block, %vec.epilog.middle.block, %middle.block59
  ret void
}

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

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) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9}
!9 = distinct !{!9, !10}
!10 = distinct !{!10, !"LVerDomain"}
!11 = !{!12}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = !{!18}
!18 = distinct !{!18, !19}
!19 = distinct !{!19, !"LVerDomain"}
!20 = !{!21}
!21 = distinct !{!21, !19}
!22 = distinct !{!22, !14, !15, !16}
!23 = !{!24, !24, i64 0}
!24 = !{!"long", !6, i64 0}
!25 = !{!26}
!26 = distinct !{!26, !27}
!27 = distinct !{!27, !"LVerDomain"}
!28 = !{!29}
!29 = distinct !{!29, !27}
!30 = distinct !{!30, !14, !15, !16}
!31 = distinct !{!31, !14, !15}
!32 = distinct !{!32, !14, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass