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

@array1 = external dso_local global [100 x %struct.Test], align 16
@__const.verify_benchmark_mergesort.exp_val = external hidden unnamed_addr constant [100 x i32], align 16
@__const.verify_benchmark_mergesort.exp_index = 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: 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) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @verify_benchmark_mergesort(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [100 x i32], align 16
  %6 = alloca [100 x i32], align 16
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 400, ptr %5) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.verify_benchmark_mergesort.exp_val, i64 400, i1 false)
  call void @llvm.lifetime.start.p0(i64 400, ptr %6) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.verify_benchmark_mergesort.exp_index, i64 400, i1 false)
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %26, %1
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = icmp slt i64 %10, 100
  br i1 %11, label %12, label %29

12:                                               ; preds = %8
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.Test, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100 x i32], ptr %5, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp ne i32 %17, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %12
  %24 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %24, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %51

25:                                               ; preds = %12
  br label %26

26:                                               ; preds = %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !11

29:                                               ; preds = %8
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %47, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %32, 100
  br i1 %33, label %34, label %50

34:                                               ; preds = %30
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Test, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp ne i32 %39, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %34
  store i32 3, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %51

46:                                               ; preds = %34
  br label %47

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

50:                                               ; preds = %30
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %51

51:                                               ; preds = %50, %45, %23
  call void @llvm.lifetime.end.p0(i64 400, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 400, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %52 = load i32, ptr %2, align 4
  ret i32 %52
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 4}
!14 = distinct !{!14, !12}


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

@array1 = external dso_local local_unnamed_addr global [100 x %struct.Test], align 16
@__const.verify_benchmark_mergesort.exp_val = external hidden unnamed_addr constant [100 x i32], align 16
@__const.verify_benchmark_mergesort.exp_index = 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 i32 @verify_benchmark_mergesort(i32 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %27, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.4, %27 ]
  %3 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_val, i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !10
  %.not13 = icmp eq i32 %4, %6
  br i1 %.not13, label %7, label %.loopexit.loopexit18

7:                                                ; preds = %2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_val, i64 0, i64 %indvars.iv.next
  %11 = load i32, ptr %10, align 4, !tbaa !10
  %.not13.1 = icmp eq i32 %9, %11
  br i1 %.not13.1, label %12, label %.loopexit.loopexit18

12:                                               ; preds = %7
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %13 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next.1
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_val, i64 0, i64 %indvars.iv.next.1
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %.not13.2 = icmp eq i32 %14, %16
  br i1 %.not13.2, label %17, label %.loopexit.loopexit18

17:                                               ; preds = %12
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %18 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next.2
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_val, i64 0, i64 %indvars.iv.next.2
  %21 = load i32, ptr %20, align 4, !tbaa !10
  %.not13.3 = icmp eq i32 %19, %21
  br i1 %.not13.3, label %22, label %.loopexit.loopexit18

22:                                               ; preds = %17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %23 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next.3
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_val, i64 0, i64 %indvars.iv.next.3
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %.not13.4 = icmp eq i32 %24, %26
  br i1 %.not13.4, label %27, label %.loopexit.loopexit18

27:                                               ; preds = %22
  %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 %.preheader, label %2, !llvm.loop !11

.preheader.1:                                     ; preds = %.preheader
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %28 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next22, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_index, i64 0, i64 %indvars.iv.next22
  %31 = load i32, ptr %30, align 4, !tbaa !10
  %.not.1 = icmp eq i32 %29, %31
  br i1 %.not.1, label %.preheader.2, label %.loopexit

.preheader.2:                                     ; preds = %.preheader.1
  %indvars.iv.next22.1 = add nuw nsw i64 %indvars.iv21, 2
  %32 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next22.1, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_index, i64 0, i64 %indvars.iv.next22.1
  %35 = load i32, ptr %34, align 4, !tbaa !10
  %.not.2 = icmp eq i32 %33, %35
  br i1 %.not.2, label %.preheader.3, label %.loopexit

.preheader.3:                                     ; preds = %.preheader.2
  %indvars.iv.next22.2 = add nuw nsw i64 %indvars.iv21, 3
  %36 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next22.2, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_index, i64 0, i64 %indvars.iv.next22.2
  %39 = load i32, ptr %38, align 4, !tbaa !10
  %.not.3 = icmp eq i32 %37, %39
  br i1 %.not.3, label %.preheader.4, label %.loopexit

.preheader.4:                                     ; preds = %.preheader.3
  %indvars.iv.next22.3 = add nuw nsw i64 %indvars.iv21, 4
  %40 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv.next22.3, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_index, i64 0, i64 %indvars.iv.next22.3
  %43 = load i32, ptr %42, align 4, !tbaa !10
  %.not.4 = icmp eq i32 %41, %43
  br i1 %.not.4, label %44, label %.loopexit

44:                                               ; preds = %.preheader.4
  %indvars.iv.next22.4 = add nuw nsw i64 %indvars.iv21, 5
  %exitcond24.not.4 = icmp eq i64 %indvars.iv.next22.4, 100
  br i1 %exitcond24.not.4, label %.loopexit, label %.preheader, !llvm.loop !14

.preheader:                                       ; preds = %27, %44
  %indvars.iv21 = phi i64 [ %indvars.iv.next22.4, %44 ], [ 0, %27 ]
  %45 = getelementptr inbounds [100 x %struct.Test], ptr @array1, i64 0, i64 %indvars.iv21, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = getelementptr inbounds [100 x i32], ptr @__const.verify_benchmark_mergesort.exp_index, i64 0, i64 %indvars.iv21
  %48 = load i32, ptr %47, align 4, !tbaa !10
  %.not = icmp eq i32 %46, %48
  br i1 %.not, label %.preheader.1, label %.loopexit

.loopexit.loopexit18:                             ; preds = %22, %17, %12, %7, %2
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %2 ], [ %indvars.iv.next, %7 ], [ %indvars.iv.next.1, %12 ], [ %indvars.iv.next.2, %17 ], [ %indvars.iv.next.3, %22 ]
  %49 = trunc nuw nsw i64 %indvars.iv.lcssa to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %44, %.loopexit.loopexit18
  %.010 = phi i32 [ %49, %.loopexit.loopexit18 ], [ 3, %.preheader ], [ 3, %.preheader.1 ], [ 3, %.preheader.2 ], [ 3, %.preheader.3 ], [ 3, %.preheader.4 ], [ 1, %44 ]
  ret i32 %.010
}

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


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