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

; 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 @stable_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 ptr, 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 = %55, %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %57

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 = %52, %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 %55

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 ptr, ptr %19, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = sub nsw i32 %24, %29
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %32, label %51

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

51:                                               ; preds = %32, %18
  br label %52

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

55:                                               ; preds = %14
  %56 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %56, 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 !15

57:                                               ; 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @stable_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 = %31, %.lr.ph.preheader
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %.1.1, %31 ]
  %.01922.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %.1.1, %31 ]
  %.02021.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %32, %31 ]
  %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 ptr, ptr %0, i64 %.02021.unr
  %4 = getelementptr i8, ptr %3, i64 -8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp sgt i32 %6, %8
  br i1 %9, label %10, label %.loopexit

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

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

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

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

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

.lr.ph:                                           ; preds = %31, %.lr.ph.preheader.new
  %.01922 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %31 ]
  %.02021 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %32, %31 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %31 ]
  %14 = getelementptr ptr, ptr %0, i64 %.02021
  %15 = getelementptr i8, ptr %14, i64 -8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = load ptr, ptr %14, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = icmp sgt i32 %17, %19
  br i1 %20, label %21, label %.lr.ph.1

21:                                               ; preds = %.lr.ph
  store ptr %18, ptr %15, align 8, !tbaa !5
  store ptr %16, ptr %14, align 8, !tbaa !5
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %21
  %.1 = phi i64 [ %.02021, %21 ], [ %.01922, %.lr.ph ]
  %22 = add nuw i64 %.02021, 1
  %23 = getelementptr ptr, ptr %0, i64 %22
  %24 = getelementptr i8, ptr %23, i64 -8
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load ptr, ptr %23, align 8, !tbaa !5
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp sgt i32 %26, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %.lr.ph.1
  store ptr %27, ptr %24, align 8, !tbaa !5
  store ptr %25, ptr %23, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %30, %.lr.ph.1
  %.1.1 = phi i64 [ %22, %30 ], [ %.1, %.lr.ph.1 ]
  %32 = 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 !13

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

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


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