; 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_bubble_sort(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %9 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %9, ptr %5, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %53, %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %55

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  store i64 1, ptr %6, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %50, %13
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %53

18:                                               ; preds = %14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = sub i64 %20, 1
  %22 = getelementptr inbounds i64, ptr %19, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = sub nsw i64 %23, %27
  %29 = icmp sgt i64 %28, 0
  br i1 %29, label %30, label %49

30:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = sub i64 %32, 1
  %34 = getelementptr inbounds i64, ptr %31, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  store i64 %35, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds i64, ptr %36, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = sub i64 %41, 1
  %43 = getelementptr inbounds i64, ptr %40, i64 %42
  store i64 %39, ptr %43, align 8, !tbaa !9
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds i64, ptr %45, i64 %46
  store i64 %44, ptr %47, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %48 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %48, ptr %7, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %30, %18
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %6, align 8, !tbaa !9
  br label %14, !llvm.loop !11

53:                                               ; preds = %14
  %54 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %54, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %10, !llvm.loop !13

55:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  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"}
!13 = distinct !{!13, !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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @sorter_bubble_sort(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not23 = icmp eq i64 %1, 0
  br i1 %.not23, label %._crit_edge, label %.preheader

.loopexit.unr-lcssa:                              ; preds = %25, %.lr.ph.preheader
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %.1.1, %25 ]
  %.01922.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %.1.1, %25 ]
  %.02021.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %26, %25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.unr-lcssa
  %3 = getelementptr i64, ptr %0, i64 %.02021.unr
  %4 = getelementptr i8, ptr %3, i64 -8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp sgt i64 %5, %6
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %.lr.ph.epil
  store i64 %6, ptr %4, align 8, !tbaa !5
  store i64 %5, ptr %3, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %8, %.loopexit.unr-lcssa
  %.1.lcssa = phi i64 [ %.1.lcssa.ph, %.loopexit.unr-lcssa ], [ %.02021.unr, %8 ], [ %.01922.unr, %.lr.ph.epil ]
  %.not = icmp eq i64 %.1.lcssa, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %2, %.loopexit
  %.024 = phi i64 [ %.1.lcssa, %.loopexit ], [ %1, %2 ]
  %9 = icmp ugt i64 %.024, 1
  br i1 %9, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %10 = add i64 %.024, -1
  %xtraiter = and i64 %10, 1
  %11 = icmp eq i64 %.024, 2
  br i1 %11, label %.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %10, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %25, %.lr.ph.preheader.new
  %.01922 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %25 ]
  %.02021 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %26, %25 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %25 ]
  %12 = getelementptr i64, ptr %0, i64 %.02021
  %13 = getelementptr i8, ptr %12, i64 -8
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = load i64, ptr %12, align 8, !tbaa !5
  %16 = icmp sgt i64 %14, %15
  br i1 %16, label %17, label %.lr.ph.1

17:                                               ; preds = %.lr.ph
  store i64 %15, ptr %13, align 8, !tbaa !5
  store i64 %14, ptr %12, align 8, !tbaa !5
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %17
  %.1 = phi i64 [ %.02021, %17 ], [ %.01922, %.lr.ph ]
  %18 = add nuw i64 %.02021, 1
  %19 = getelementptr i64, ptr %0, i64 %18
  %20 = getelementptr i8, ptr %19, i64 -8
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = load i64, ptr %19, align 8, !tbaa !5
  %23 = icmp sgt i64 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %.lr.ph.1
  store i64 %22, ptr %20, align 8, !tbaa !5
  store i64 %21, ptr %19, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %24, %.lr.ph.1
  %.1.1 = phi i64 [ %18, %24 ], [ %.1, %.lr.ph.1 ]
  %26 = add nuw i64 %.02021, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %.preheader, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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