; 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_selection_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 ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = icmp ule i64 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %61

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %57, %11
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %60

16:                                               ; preds = %12
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = add i64 %17, 1
  store i64 %18, ptr %6, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %53, %16
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %23, label %56

23:                                               ; preds = %19
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %24, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = sub nsw i32 %28, %33
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %52

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

52:                                               ; preds = %36, %23
  br label %53

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

56:                                               ; preds = %19
  br label %57

57:                                               ; preds = %56
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = add i64 %58, 1
  store i64 %59, ptr %5, align 8, !tbaa !9
  br label %12, !llvm.loop !15

60:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %61

61:                                               ; preds = %60, %10
  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_selection_sort(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %1, 2
  br i1 %3, label %.loopexit22, label %.preheader

.loopexit:                                        ; preds = %15, %.preheader
  %exitcond.not = icmp eq i64 %4, %1
  br i1 %exitcond.not, label %.loopexit22, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %2, %.loopexit
  %.024 = phi i64 [ %4, %.loopexit ], [ 0, %2 ]
  %4 = add nuw i64 %.024, 1
  %5 = icmp ult i64 %4, %1
  br i1 %5, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds ptr, ptr %0, i64 %.024
  br label %7

7:                                                ; preds = %.lr.ph, %15
  %.02023 = phi i64 [ %4, %.lr.ph ], [ %16, %15 ]
  %8 = getelementptr inbounds ptr, ptr %0, i64 %.02023
  %9 = load ptr, ptr %8, align 8, !tbaa !7
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = load ptr, ptr %6, align 8, !tbaa !7
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %7
  store ptr %9, ptr %6, align 8, !tbaa !7
  store ptr %11, ptr %8, align 8, !tbaa !7
  br label %15

15:                                               ; preds = %7, %14
  %16 = add nuw i64 %.02023, 1
  %17 = icmp ult i64 %16, %1
  br i1 %17, label %7, label %.loopexit, !llvm.loop !13

.loopexit22:                                      ; preds = %.loopexit, %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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = distinct !{!13, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass