; LLVM IR from siconos/siconos :: externals/sort/test (benchmark)

; 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: 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 void @sorter_merge_sort_in_place_aswap(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %20, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %10, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 %12, ptr %13, align 8, !tbaa !9
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %14, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds i64, ptr %16, i32 1
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds i64, ptr %18, i32 1
  store ptr %19, ptr %5, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %8
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = add i64 %21, -1
  store i64 %22, ptr %6, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %8, label %24, !llvm.loop !11

24:                                               ; preds = %20
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @sorter_merge_sort_in_place_aswap(ptr nocapture noundef %0, ptr nocapture noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %min.iters.check = icmp ult i64 %2, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %3
  %4 = shl i64 %2, 3
  %scevgep = getelementptr i8, ptr %0, i64 %4
  %scevgep9 = getelementptr i8, ptr %1, i64 %4
  %bound0 = icmp ugt ptr %scevgep9, %0
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %2, -4
  %5 = shl i64 %n.vec, 3
  %ind.end = getelementptr i8, ptr %1, i64 %5
  %ind.end10 = and i64 %2, 3
  %6 = shl i64 %n.vec, 3
  %ind.end12 = getelementptr i8, ptr %0, i64 %6
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 3
  %next.gep = getelementptr i8, ptr %1, i64 %offset.idx
  %offset.idx15 = shl i64 %index, 3
  %next.gep16 = getelementptr i8, ptr %0, i64 %offset.idx15
  %7 = getelementptr i8, ptr %next.gep16, i64 16
  %wide.load = load <2 x i64>, ptr %next.gep16, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %wide.load18 = load <2 x i64>, ptr %7, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %8 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load19 = load <2 x i64>, ptr %next.gep, align 8, !tbaa !5, !alias.scope !12
  %wide.load20 = load <2 x i64>, ptr %8, align 8, !tbaa !5, !alias.scope !12
  store <2 x i64> %wide.load19, ptr %next.gep16, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  store <2 x i64> %wide.load20, ptr %7, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  store <2 x i64> %wide.load, ptr %next.gep, align 8, !tbaa !5, !alias.scope !12
  store <2 x i64> %wide.load18, ptr %8, align 8, !tbaa !5, !alias.scope !12
  %index.next = add nuw i64 %index, 4
  %9 = icmp eq i64 %index.next, %n.vec
  br i1 %9, label %middle.block, label %vector.body, !llvm.loop !14

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %3
  %.08.ph = phi ptr [ %1, %vector.memcheck ], [ %1, %3 ], [ %ind.end, %middle.block ]
  %.07.ph = phi i64 [ %2, %vector.memcheck ], [ %2, %3 ], [ %ind.end10, %middle.block ]
  %.0.ph = phi ptr [ %0, %vector.memcheck ], [ %0, %3 ], [ %ind.end12, %middle.block ]
  %10 = add i64 %.07.ph, -1
  %xtraiter = and i64 %.07.ph, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.08.prol = phi ptr [ %14, %scalar.ph.prol ], [ %.08.ph, %scalar.ph.preheader ]
  %.07.prol = phi i64 [ %15, %scalar.ph.prol ], [ %.07.ph, %scalar.ph.preheader ]
  %.0.prol = phi ptr [ %13, %scalar.ph.prol ], [ %.0.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %11 = load i64, ptr %.0.prol, align 8, !tbaa !5
  %12 = load i64, ptr %.08.prol, align 8, !tbaa !5
  store i64 %12, ptr %.0.prol, align 8, !tbaa !5
  store i64 %11, ptr %.08.prol, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.0.prol, i64 8
  %14 = getelementptr inbounds i8, ptr %.08.prol, i64 8
  %15 = add i64 %.07.prol, -1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !18

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.08.unr = phi ptr [ %.08.ph, %scalar.ph.preheader ], [ %14, %scalar.ph.prol ]
  %.07.unr = phi i64 [ %.07.ph, %scalar.ph.preheader ], [ %15, %scalar.ph.prol ]
  %.0.unr = phi ptr [ %.0.ph, %scalar.ph.preheader ], [ %13, %scalar.ph.prol ]
  %16 = icmp ult i64 %10, 3
  br i1 %16, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.08 = phi ptr [ %32, %scalar.ph ], [ %.08.unr, %scalar.ph.prol.loopexit ]
  %.07 = phi i64 [ %33, %scalar.ph ], [ %.07.unr, %scalar.ph.prol.loopexit ]
  %.0 = phi ptr [ %31, %scalar.ph ], [ %.0.unr, %scalar.ph.prol.loopexit ]
  %17 = load i64, ptr %.0, align 8, !tbaa !5
  %18 = load i64, ptr %.08, align 8, !tbaa !5
  store i64 %18, ptr %.0, align 8, !tbaa !5
  store i64 %17, ptr %.08, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.0, i64 8
  %20 = getelementptr inbounds i8, ptr %.08, i64 8
  %21 = load i64, ptr %19, align 8, !tbaa !5
  %22 = load i64, ptr %20, align 8, !tbaa !5
  store i64 %22, ptr %19, align 8, !tbaa !5
  store i64 %21, ptr %20, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %.0, i64 16
  %24 = getelementptr inbounds i8, ptr %.08, i64 16
  %25 = load i64, ptr %23, align 8, !tbaa !5
  %26 = load i64, ptr %24, align 8, !tbaa !5
  store i64 %26, ptr %23, align 8, !tbaa !5
  store i64 %25, ptr %24, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.0, i64 24
  %28 = getelementptr inbounds i8, ptr %.08, i64 24
  %29 = load i64, ptr %27, align 8, !tbaa !5
  %30 = load i64, ptr %28, align 8, !tbaa !5
  store i64 %30, ptr %27, align 8, !tbaa !5
  store i64 %29, ptr %28, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.0, i64 32
  %32 = getelementptr inbounds i8, ptr %.08, i64 32
  %33 = add i64 %.07, -4
  %.not.3 = icmp eq i64 %33, 0
  br i1 %.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !20

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !15, !16}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopLoadEliminationPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass