; LLVM IR from JamesQuintero/ShiftSort :: C++/main.ll (Z13testMergeSortii)

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

%class.MergeSort = type { ptr, ptr, ptr }

@array = external dso_local global ptr, align 8
@num_items = external dso_local global i32, align 4

; 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: mustprogress uwtable
define dso_local noundef i32 @_Z13testMergeSortii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %class.MergeSort, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  call void @_ZN9MergeSortC1Ev(ptr noundef nonnull align 8 dereferenceable(24) %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %42

18:                                               ; preds = %2
  call void @_Z10createListv()
  %19 = load ptr, ptr @array, align 8, !tbaa !9
  %20 = load i32, ptr @num_items, align 4, !tbaa !5
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef %19, i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %38, %18
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %41

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %27 = call i64 @clock() #5
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %8, align 4, !tbaa !5
  %29 = load ptr, ptr @array, align 8, !tbaa !9
  %30 = load i32, ptr @num_items, align 4, !tbaa !5
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef %29, i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %31 = call i64 @clock() #5
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %9, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = add nsw i32 %36, %35
  store i32 %37, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %38

38:                                               ; preds = %26
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !5
  br label %21, !llvm.loop !11

41:                                               ; preds = %25
  br label %98

42:                                               ; preds = %2
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %67

45:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %63, %45
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %66

51:                                               ; preds = %46
  call void @_Z10createListv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %52 = call i64 @clock() #5
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %11, align 4, !tbaa !5
  %54 = load ptr, ptr @array, align 8, !tbaa !9
  %55 = load i32, ptr @num_items, align 4, !tbaa !5
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef %54, i32 noundef %55)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %56 = call i64 @clock() #5
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr %12, align 4, !tbaa !5
  %58 = load i32, ptr %12, align 4, !tbaa !5
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = sub nsw i32 %58, %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = add nsw i32 %61, %60
  store i32 %62, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %63

63:                                               ; preds = %51
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %10, align 4, !tbaa !5
  br label %46, !llvm.loop !13

66:                                               ; preds = %50
  br label %97

67:                                               ; preds = %42
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = icmp eq i32 %68, 2
  br i1 %69, label %70, label %96

70:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %92, %70
  %72 = load i32, ptr %13, align 4, !tbaa !5
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = icmp slt i32 %72, %73
  br i1 %74, label %76, label %75

75:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %95

76:                                               ; preds = %71
  call void @_Z10createListv()
  %77 = load ptr, ptr @array, align 8, !tbaa !9
  %78 = load i32, ptr @num_items, align 4, !tbaa !5
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef %77, i32 noundef %78)
  %79 = load ptr, ptr @array, align 8, !tbaa !9
  %80 = load i32, ptr @num_items, align 4, !tbaa !5
  call void @_Z12reverseArrayPii(ptr noundef %79, i32 noundef %80)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %81 = call i64 @clock() #5
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %14, align 4, !tbaa !5
  %83 = load ptr, ptr @array, align 8, !tbaa !9
  %84 = load i32, ptr @num_items, align 4, !tbaa !5
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef %83, i32 noundef %84)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %85 = call i64 @clock() #5
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr %15, align 4, !tbaa !5
  %87 = load i32, ptr %15, align 4, !tbaa !5
  %88 = load i32, ptr %14, align 4, !tbaa !5
  %89 = sub nsw i32 %87, %88
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = add nsw i32 %90, %89
  store i32 %91, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %92

92:                                               ; preds = %76
  %93 = load i32, ptr %13, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %13, align 4, !tbaa !5
  br label %71, !llvm.loop !14

95:                                               ; preds = %75
  br label %96

96:                                               ; preds = %95, %67
  br label %97

97:                                               ; preds = %96, %66
  br label %98

98:                                               ; preds = %97, %41
  %99 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  ret i32 %99
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10createListv() #1

; Function Attrs: nounwind
declare i64 @clock() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z12reverseArrayPii(ptr noundef, i32 noundef) #3

declare void @_ZN9MergeSortC1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4

declare void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef) #4

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

%class.MergeSort = type { ptr, ptr, ptr }

@array = external dso_local local_unnamed_addr global ptr, align 8
@num_items = external dso_local local_unnamed_addr global i32, align 4

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z13testMergeSortii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca %class.MergeSort, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @_ZN9MergeSortC1Ev(ptr noundef nonnull align 8 dereferenceable(24) %3)
  switch i32 %0, label %.loopexit [
    i32 0, label %6
    i32 1, label %.preheader
    i32 2, label %.preheader29
  ]

.preheader29:                                     ; preds = %2
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph, label %.loopexit

.preheader:                                       ; preds = %2
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph35, label %.loopexit

6:                                                ; preds = %2
  call void @_Z10createListv()
  %7 = load ptr, ptr @array, align 8, !tbaa !5
  %8 = load i32, ptr @num_items, align 4, !tbaa !9
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef %7, i32 noundef %8)
  %9 = icmp sgt i32 %1, 0
  br i1 %9, label %.lr.ph39, label %.loopexit

.lr.ph39:                                         ; preds = %6, %.lr.ph39
  %.038 = phi i32 [ %17, %.lr.ph39 ], [ 0, %6 ]
  %.02237 = phi i32 [ %18, %.lr.ph39 ], [ 0, %6 ]
  %10 = call i64 @clock() #5
  %11 = trunc i64 %10 to i32
  %12 = load ptr, ptr @array, align 8, !tbaa !5
  %13 = load i32, ptr @num_items, align 4, !tbaa !9
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef %12, i32 noundef %13)
  %14 = call i64 @clock() #5
  %15 = trunc i64 %14 to i32
  %16 = sub i32 %.038, %11
  %17 = add i32 %16, %15
  %18 = add nuw nsw i32 %.02237, 1
  %exitcond46.not = icmp eq i32 %18, %1
  br i1 %exitcond46.not, label %.loopexit, label %.lr.ph39, !llvm.loop !11

.lr.ph35:                                         ; preds = %.preheader, %.lr.ph35
  %.134 = phi i32 [ %26, %.lr.ph35 ], [ 0, %.preheader ]
  %.02433 = phi i32 [ %27, %.lr.ph35 ], [ 0, %.preheader ]
  call void @_Z10createListv()
  %19 = call i64 @clock() #5
  %20 = trunc i64 %19 to i32
  %21 = load ptr, ptr @array, align 8, !tbaa !5
  %22 = load i32, ptr @num_items, align 4, !tbaa !9
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef %21, i32 noundef %22)
  %23 = call i64 @clock() #5
  %24 = trunc i64 %23 to i32
  %25 = sub i32 %.134, %20
  %26 = add i32 %25, %24
  %27 = add nuw nsw i32 %.02433, 1
  %exitcond45.not = icmp eq i32 %27, %1
  br i1 %exitcond45.not, label %.loopexit, label %.lr.ph35, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader29, %.lr.ph
  %.232 = phi i32 [ %39, %.lr.ph ], [ 0, %.preheader29 ]
  %.02331 = phi i32 [ %40, %.lr.ph ], [ 0, %.preheader29 ]
  call void @_Z10createListv()
  %28 = load ptr, ptr @array, align 8, !tbaa !5
  %29 = load i32, ptr @num_items, align 4, !tbaa !9
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef %28, i32 noundef %29)
  %30 = load ptr, ptr @array, align 8, !tbaa !5
  %31 = load i32, ptr @num_items, align 4, !tbaa !9
  call void @_Z12reverseArrayPii(ptr noundef %30, i32 noundef %31)
  %32 = call i64 @clock() #5
  %33 = trunc i64 %32 to i32
  %34 = load ptr, ptr @array, align 8, !tbaa !5
  %35 = load i32, ptr @num_items, align 4, !tbaa !9
  call void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef %34, i32 noundef %35)
  %36 = call i64 @clock() #5
  %37 = trunc i64 %36 to i32
  %38 = sub i32 %.232, %33
  %39 = add i32 %38, %37
  %40 = add nuw nsw i32 %.02331, 1
  %exitcond.not = icmp eq i32 %40, %1
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph35, %.lr.ph39, %.preheader29, %.preheader, %6, %2
  %.3 = phi i32 [ 0, %2 ], [ 0, %6 ], [ 0, %.preheader ], [ 0, %.preheader29 ], [ %17, %.lr.ph39 ], [ %26, %.lr.ph35 ], [ %39, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret i32 %.3
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10createListv() local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z12reverseArrayPii(ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @_ZN9MergeSortC1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4

declare void @_ZN9MergeSort4sortEPii(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef) local_unnamed_addr #4

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


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