; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/MEASURE/src/Algorithms (algorithm_bsort1)

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

@algorithm_bsort1_sa = external dso_local global [10000 x i32], align 16
@algorithm_bsort1_el = external dso_local global i32, align 4
@algorithm_bsort1_b = external dso_local global i8, align 1
@algorithm_bsort1_il = external dso_local global i32, align 4
@algorithm_bsort1_t = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @ALGORITHM_BSORT1_EXECUTE() #0 {
  store i32 0, ptr @algorithm_bsort1_el, align 4, !tbaa !5
  br label %1

1:                                                ; preds = %47, %0
  %2 = load i32, ptr @algorithm_bsort1_el, align 4, !tbaa !5
  %3 = icmp slt i32 %2, 10000
  br i1 %3, label %4, label %50

4:                                                ; preds = %1
  store i8 0, ptr @algorithm_bsort1_b, align 1, !tbaa !9
  store i32 0, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %38, %4
  %6 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 9999
  br i1 %7, label %8, label %41

8:                                                ; preds = %5
  %9 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp sgt i32 %12, %17
  br i1 %18, label %19, label %37

19:                                               ; preds = %8
  %20 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr @algorithm_bsort1_t, align 4, !tbaa !5
  %24 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr @algorithm_bsort1_t, align 4, !tbaa !5
  %33 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %35
  store i32 %32, ptr %36, align 4, !tbaa !5
  store i8 1, ptr @algorithm_bsort1_b, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %19, %8
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  br label %5, !llvm.loop !10

41:                                               ; preds = %5
  %42 = load i8, ptr @algorithm_bsort1_b, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  br label %50

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr @algorithm_bsort1_el, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @algorithm_bsort1_el, align 4, !tbaa !5
  br label %1, !llvm.loop !12

50:                                               ; preds = %45, %1
  ret void
}

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@algorithm_bsort1_sa = external dso_local local_unnamed_addr global [10000 x i32], align 16
@algorithm_bsort1_el = external dso_local local_unnamed_addr global i32, align 4
@algorithm_bsort1_b = external dso_local local_unnamed_addr global i8, align 1
@algorithm_bsort1_il = external dso_local local_unnamed_addr global i32, align 4
@algorithm_bsort1_t = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @ALGORITHM_BSORT1_EXECUTE() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %.thread10
  %storemerge4 = phi i32 [ 0, %0 ], [ %15, %.thread10 ]
  %.pre = load i32, ptr @algorithm_bsort1_sa, align 16, !tbaa !5
  br label %.outer

.outer:                                           ; preds = %._crit_edge, %1
  %.ph = phi i32 [ %.lcssa, %._crit_edge ], [ %.pre, %1 ]
  %indvars.iv.ph = phi i64 [ %indvars.iv.next.lcssa, %._crit_edge ], [ 0, %1 ]
  %.ph11 = phi i8 [ %.lcssa18, %._crit_edge ], [ 0, %1 ]
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv.ph, 1
  %2 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %indvars.iv.next20
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %.ph, %3
  br i1 %4, label %.thread, label %._crit_edge

5:                                                ; preds = %.thread
  %indvars.iv.next = add nuw nsw i64 %indvars.iv.next22, 1
  %6 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %indvars.iv.next
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %.ph, %7
  br i1 %8, label %.thread, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %5
  store i32 %.ph, ptr @algorithm_bsort1_t, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.outer
  %.lcssa18 = phi i8 [ %.ph11, %.outer ], [ 1, %._crit_edge.loopexit ]
  %indvars.iv.next.lcssa = phi i64 [ %indvars.iv.next20, %.outer ], [ %indvars.iv.next, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ %3, %.outer ], [ %7, %._crit_edge.loopexit ]
  %exitcond.not = icmp eq i64 %indvars.iv.next.lcssa, 9999
  br i1 %exitcond.not, label %12, label %.outer, !llvm.loop !9

.thread:                                          ; preds = %.outer, %5
  %9 = phi i32 [ %7, %5 ], [ %3, %.outer ]
  %10 = phi ptr [ %6, %5 ], [ %2, %.outer ]
  %indvars.iv.next22 = phi i64 [ %indvars.iv.next, %5 ], [ %indvars.iv.next20, %.outer ]
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %5 ], [ %indvars.iv.ph, %.outer ]
  %11 = getelementptr inbounds [10000 x i32], ptr @algorithm_bsort1_sa, i64 0, i64 %indvars.iv21
  store i32 %9, ptr %11, align 4, !tbaa !5
  store i32 %.ph, ptr %10, align 4, !tbaa !5
  %exitcond.not9 = icmp eq i64 %indvars.iv.next22, 9999
  br i1 %exitcond.not9, label %.thread10.loopexit, label %5, !llvm.loop !9

12:                                               ; preds = %._crit_edge
  %13 = icmp eq i8 %.lcssa18, 0
  br i1 %13, label %16, label %.thread10

.thread10.loopexit:                               ; preds = %.thread
  store i32 %.ph, ptr @algorithm_bsort1_t, align 4, !tbaa !5
  br label %.thread10

.thread10:                                        ; preds = %.thread10.loopexit, %12
  %14 = phi i8 [ %.lcssa18, %12 ], [ 1, %.thread10.loopexit ]
  %15 = add nuw nsw i32 %storemerge4, 1
  %exitcond8.not = icmp eq i32 %15, 10000
  br i1 %exitcond8.not, label %16, label %1, !llvm.loop !11

16:                                               ; preds = %12, %.thread10
  %.lcssa7.lcssa = phi i8 [ 0, %12 ], [ %14, %.thread10 ]
  %storemerge.lcssa = phi i32 [ %storemerge4, %12 ], [ 10000, %.thread10 ]
  store i8 %.lcssa7.lcssa, ptr @algorithm_bsort1_b, align 1, !tbaa !12
  store i32 9999, ptr @algorithm_bsort1_il, align 4, !tbaa !5
  store i32 %storemerge.lcssa, ptr @algorithm_bsort1_el, align 4, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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 = !{!"int", !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}
!12 = !{!7, !7, i64 0}


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