; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/bubblesort (libbubblesort)

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

@Array = external dso_local global [101 x i32], align 16
@__const.verify_benchmark_bubblesort.expected = external hidden unnamed_addr constant [100 x i32], align 16

; 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 i32 @verify_benchmark_bubblesort(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [100 x i32], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 400, ptr %4) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.verify_benchmark_bubblesort.expected, i64 400, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %22, %1
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 100
  br i1 %9, label %10, label %25

10:                                               ; preds = %7
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [101 x i32], ptr @Array, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100 x i32], ptr %4, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp ne i32 %14, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %10
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %26

21:                                               ; preds = %10
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %5, align 4, !tbaa !5
  br label %7, !llvm.loop !9

25:                                               ; preds = %7
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %26

26:                                               ; preds = %25, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 400, ptr %4) #3
  %27 = load i32, ptr %2, align 4
  ret i32 %27
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@Array = external dso_local local_unnamed_addr global [101 x i32], align 16
@__const.verify_benchmark_bubblesort.expected = external hidden unnamed_addr constant [100 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @verify_benchmark_bubblesort(i32 noundef %0) local_unnamed_addr #0 {
  br label %23

2:                                                ; preds = %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %3 = getelementptr inbounds [101 x i32], ptr @Array, i64 0, i64 %indvars.iv.next
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_bubblesort.expected, i64 0, i64 %indvars.iv.next
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %4, %6
  br i1 %.not.1, label %7, label %28

7:                                                ; preds = %2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %8 = getelementptr inbounds [101 x i32], ptr @Array, i64 0, i64 %indvars.iv.next.1
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_bubblesort.expected, i64 0, i64 %indvars.iv.next.1
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not.2 = icmp eq i32 %9, %11
  br i1 %.not.2, label %12, label %28

12:                                               ; preds = %7
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %13 = getelementptr inbounds [101 x i32], ptr @Array, i64 0, i64 %indvars.iv.next.2
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_bubblesort.expected, i64 0, i64 %indvars.iv.next.2
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not.3 = icmp eq i32 %14, %16
  br i1 %.not.3, label %17, label %28

17:                                               ; preds = %12
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %18 = getelementptr inbounds [101 x i32], ptr @Array, i64 0, i64 %indvars.iv.next.3
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_bubblesort.expected, i64 0, i64 %indvars.iv.next.3
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not.4 = icmp eq i32 %19, %21
  br i1 %.not.4, label %22, label %28

22:                                               ; preds = %17
  %indvars.iv.next.4 = add nuw nsw i64 %indvars.iv, 5
  %exitcond.not.4 = icmp eq i64 %indvars.iv.next.4, 100
  br i1 %exitcond.not.4, label %28, label %23, !llvm.loop !9

23:                                               ; preds = %22, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.4, %22 ]
  %24 = getelementptr inbounds [101 x i32], ptr @Array, i64 0, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_bubblesort.expected, i64 0, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not = icmp eq i32 %25, %27
  br i1 %.not, label %2, label %28

28:                                               ; preds = %22, %17, %12, %7, %2, %23
  %.05 = phi i32 [ 0, %23 ], [ 0, %2 ], [ 0, %7 ], [ 0, %12 ], [ 0, %17 ], [ 1, %22 ]
  ret i32 %.05
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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"}


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