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

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

%struct.Test = type { i32, i32 }

@__const.benchmark_mergesort.test_cases = external hidden unnamed_addr constant [9 x ptr], align 16
@array1 = external dso_local global [100 x %struct.Test], align 16

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @TestCompare(i64, i64) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; 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

; Function Attrs: nounwind uwtable
declare dso_local void @MergeSort(ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_mergesort() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [9 x ptr], align 16
  %6 = alloca %struct.Test, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr @TestCompare, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr %5) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.benchmark_mergesort.test_cases, i64 72, i1 false)
  store i64 100, ptr %1, align 8, !tbaa !9
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %35, %0
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 9
  br i1 %9, label %10, label %38

10:                                               ; preds = %7
  store i64 0, ptr %2, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %29, %10
  %12 = load i64, ptr %2, align 8, !tbaa !9
  %13 = load i64, ptr %1, align 8, !tbaa !9
  %14 = icmp slt i64 %12, %13
  br i1 %14, label %15, label %32

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = load i64, ptr %3, align 8, !tbaa !9
  %17 = getelementptr inbounds [9 x ptr], ptr %5, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = load i64, ptr %2, align 8, !tbaa !9
  %20 = load i64, ptr %1, align 8, !tbaa !9
  %21 = call i64 %18(i64 noundef %19, i64 noundef %20)
  %22 = trunc i64 %21 to i32
  %23 = getelementptr inbounds %struct.Test, ptr %6, i32 0, i32 0
  store i32 %22, ptr %23, align 4, !tbaa !11
  %24 = load i64, ptr %2, align 8, !tbaa !9
  %25 = trunc i64 %24 to i32
  %26 = getelementptr inbounds %struct.Test, ptr %6, i32 0, i32 1
  store i32 %25, ptr %26, align 4, !tbaa !14
  %27 = load i64, ptr %2, align 8, !tbaa !9
  %28 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %27
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %28, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %29

29:                                               ; preds = %15
  %30 = load i64, ptr %2, align 8, !tbaa !9
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %2, align 8, !tbaa !9
  br label %11, !llvm.loop !17

32:                                               ; preds = %11
  %33 = load i64, ptr %1, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @MergeSort(ptr noundef @array1, i64 noundef %33, ptr noundef %34)
  br label %35

35:                                               ; preds = %32
  %36 = load i64, ptr %3, align 8, !tbaa !9
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %3, align 8, !tbaa !9
  br label %7, !llvm.loop !19

38:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 72, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret i32 0
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{i64 0, i64 4, !16, i64 4, i64 4, !16}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

%struct.Test = type { i32, i32 }

@__const.benchmark_mergesort.test_cases = external hidden unnamed_addr constant [9 x ptr], align 16
@array1 = external dso_local global [100 x %struct.Test], align 16

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @TestCompare(i64, i64) #0

; Function Attrs: nounwind uwtable
declare dso_local void @MergeSort(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @benchmark_mergesort() local_unnamed_addr #0 {
.preheader:
  %0 = load ptr, ptr @__const.benchmark_mergesort.test_cases, align 16, !tbaa !5
  br label %1

1:                                                ; preds = %.preheader, %1
  %.012 = phi i64 [ 0, %.preheader ], [ %6, %1 ]
  %2 = tail call i64 %0(i64 noundef %.012, i64 noundef 100) #1
  %3 = trunc i64 %2 to i32
  %4 = trunc nuw i64 %.012 to i32
  %5 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012
  store i32 %3, ptr %5, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 4
  store i32 %4, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !9
  %6 = add nuw nsw i64 %.012, 1
  %exitcond.not = icmp eq i64 %6, 100
  br i1 %exitcond.not, label %.preheader.1, label %1, !llvm.loop !11

.preheader.1:                                     ; preds = %1
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 8), align 8, !tbaa !5
  br label %8

8:                                                ; preds = %8, %.preheader.1
  %.012.1 = phi i64 [ 0, %.preheader.1 ], [ %13, %8 ]
  %9 = tail call i64 %7(i64 noundef %.012.1, i64 noundef 100) #1
  %10 = trunc i64 %9 to i32
  %11 = trunc nuw i64 %.012.1 to i32
  %12 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.1
  store i32 %10, ptr %12, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.1 = getelementptr inbounds i8, ptr %12, i64 4
  store i32 %11, ptr %.sroa.4.0..sroa_idx.1, align 4, !tbaa !9
  %13 = add nuw nsw i64 %.012.1, 1
  %exitcond.1.not = icmp eq i64 %13, 100
  br i1 %exitcond.1.not, label %.preheader.2, label %8, !llvm.loop !11

.preheader.2:                                     ; preds = %8
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 16), align 16, !tbaa !5
  br label %15

15:                                               ; preds = %15, %.preheader.2
  %.012.2 = phi i64 [ 0, %.preheader.2 ], [ %20, %15 ]
  %16 = tail call i64 %14(i64 noundef %.012.2, i64 noundef 100) #1
  %17 = trunc i64 %16 to i32
  %18 = trunc nuw i64 %.012.2 to i32
  %19 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.2
  store i32 %17, ptr %19, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.2 = getelementptr inbounds i8, ptr %19, i64 4
  store i32 %18, ptr %.sroa.4.0..sroa_idx.2, align 4, !tbaa !9
  %20 = add nuw nsw i64 %.012.2, 1
  %exitcond.2.not = icmp eq i64 %20, 100
  br i1 %exitcond.2.not, label %.preheader.3, label %15, !llvm.loop !11

.preheader.3:                                     ; preds = %15
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 24), align 8, !tbaa !5
  br label %22

22:                                               ; preds = %22, %.preheader.3
  %.012.3 = phi i64 [ 0, %.preheader.3 ], [ %27, %22 ]
  %23 = tail call i64 %21(i64 noundef %.012.3, i64 noundef 100) #1
  %24 = trunc i64 %23 to i32
  %25 = trunc nuw i64 %.012.3 to i32
  %26 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.3
  store i32 %24, ptr %26, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.3 = getelementptr inbounds i8, ptr %26, i64 4
  store i32 %25, ptr %.sroa.4.0..sroa_idx.3, align 4, !tbaa !9
  %27 = add nuw nsw i64 %.012.3, 1
  %exitcond.3.not = icmp eq i64 %27, 100
  br i1 %exitcond.3.not, label %.preheader.4, label %22, !llvm.loop !11

.preheader.4:                                     ; preds = %22
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 32), align 16, !tbaa !5
  br label %29

29:                                               ; preds = %29, %.preheader.4
  %.012.4 = phi i64 [ 0, %.preheader.4 ], [ %34, %29 ]
  %30 = tail call i64 %28(i64 noundef %.012.4, i64 noundef 100) #1
  %31 = trunc i64 %30 to i32
  %32 = trunc nuw i64 %.012.4 to i32
  %33 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.4
  store i32 %31, ptr %33, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.4 = getelementptr inbounds i8, ptr %33, i64 4
  store i32 %32, ptr %.sroa.4.0..sroa_idx.4, align 4, !tbaa !9
  %34 = add nuw nsw i64 %.012.4, 1
  %exitcond.4.not = icmp eq i64 %34, 100
  br i1 %exitcond.4.not, label %.preheader.5, label %29, !llvm.loop !11

.preheader.5:                                     ; preds = %29
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %35 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 40), align 8, !tbaa !5
  br label %36

36:                                               ; preds = %36, %.preheader.5
  %.012.5 = phi i64 [ 0, %.preheader.5 ], [ %41, %36 ]
  %37 = tail call i64 %35(i64 noundef %.012.5, i64 noundef 100) #1
  %38 = trunc i64 %37 to i32
  %39 = trunc nuw i64 %.012.5 to i32
  %40 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.5
  store i32 %38, ptr %40, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.5 = getelementptr inbounds i8, ptr %40, i64 4
  store i32 %39, ptr %.sroa.4.0..sroa_idx.5, align 4, !tbaa !9
  %41 = add nuw nsw i64 %.012.5, 1
  %exitcond.5.not = icmp eq i64 %41, 100
  br i1 %exitcond.5.not, label %.preheader.6, label %36, !llvm.loop !11

.preheader.6:                                     ; preds = %36
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %42 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 48), align 16, !tbaa !5
  br label %43

43:                                               ; preds = %43, %.preheader.6
  %.012.6 = phi i64 [ 0, %.preheader.6 ], [ %48, %43 ]
  %44 = tail call i64 %42(i64 noundef %.012.6, i64 noundef 100) #1
  %45 = trunc i64 %44 to i32
  %46 = trunc nuw i64 %.012.6 to i32
  %47 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.6
  store i32 %45, ptr %47, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.6 = getelementptr inbounds i8, ptr %47, i64 4
  store i32 %46, ptr %.sroa.4.0..sroa_idx.6, align 4, !tbaa !9
  %48 = add nuw nsw i64 %.012.6, 1
  %exitcond.6.not = icmp eq i64 %48, 100
  br i1 %exitcond.6.not, label %.preheader.7, label %43, !llvm.loop !11

.preheader.7:                                     ; preds = %43
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %49 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 56), align 8, !tbaa !5
  br label %50

50:                                               ; preds = %50, %.preheader.7
  %.012.7 = phi i64 [ 0, %.preheader.7 ], [ %55, %50 ]
  %51 = tail call i64 %49(i64 noundef %.012.7, i64 noundef 100) #1
  %52 = trunc i64 %51 to i32
  %53 = trunc nuw i64 %.012.7 to i32
  %54 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.7
  store i32 %52, ptr %54, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.7 = getelementptr inbounds i8, ptr %54, i64 4
  store i32 %53, ptr %.sroa.4.0..sroa_idx.7, align 4, !tbaa !9
  %55 = add nuw nsw i64 %.012.7, 1
  %exitcond.7.not = icmp eq i64 %55, 100
  br i1 %exitcond.7.not, label %.preheader.8, label %50, !llvm.loop !11

.preheader.8:                                     ; preds = %50
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  %56 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.benchmark_mergesort.test_cases, i64 64), align 16, !tbaa !5
  br label %57

57:                                               ; preds = %57, %.preheader.8
  %.012.8 = phi i64 [ 0, %.preheader.8 ], [ %62, %57 ]
  %58 = tail call i64 %56(i64 noundef %.012.8, i64 noundef 100) #1
  %59 = trunc i64 %58 to i32
  %60 = trunc nuw i64 %.012.8 to i32
  %61 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %.012.8
  store i32 %59, ptr %61, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx.8 = getelementptr inbounds i8, ptr %61, i64 4
  store i32 %60, ptr %.sroa.4.0..sroa_idx.8, align 4, !tbaa !9
  %62 = add nuw nsw i64 %.012.8, 1
  %exitcond.8.not = icmp eq i64 %62, 100
  br i1 %exitcond.8.not, label %63, label %57, !llvm.loop !11

63:                                               ; preds = %57
  tail call void @MergeSort(ptr noundef nonnull @array1, i64 noundef 100, ptr noundef nonnull @TestCompare)
  ret i32 0
}

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" }
attributes #1 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass