; LLVM IR from h-ssiqueira/Sort_Algorithms :: src/hybrids (timSort)

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

; Function Attrs: nounwind uwtable
define dso_local void @insertionSortTim(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i64, ptr %10, i64 %12
  %14 = getelementptr inbounds i64, ptr %13, i64 1
  store ptr %14, ptr %8, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %52, %3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i64, ptr %17, i64 %19
  %21 = icmp ule ptr %16, %20
  br i1 %21, label %22, label %55

22:                                               ; preds = %15
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load i64, ptr %23, align 8, !tbaa !11
  store i64 %24, ptr %7, align 8, !tbaa !11
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds i64, ptr %25, i64 -1
  store ptr %26, ptr %9, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %41, %22
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds i64, ptr %30, i64 %31
  %33 = icmp uge ptr %28, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %27
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = load i64, ptr %7, align 8, !tbaa !11
  %38 = icmp sgt i64 %36, %37
  br label %39

39:                                               ; preds = %34, %27
  %40 = phi i1 [ false, %27 ], [ %38, %34 ]
  br i1 %40, label %41, label %48

41:                                               ; preds = %39
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds i64, ptr %44, i64 1
  store i64 %43, ptr %45, align 8, !tbaa !11
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds i64, ptr %46, i32 -1
  store ptr %47, ptr %9, align 8, !tbaa !5
  br label %27, !llvm.loop !13

48:                                               ; preds = %39
  %49 = load i64, ptr %7, align 8, !tbaa !11
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds i64, ptr %50, i64 1
  store i64 %49, ptr %51, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %48
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds i64, ptr %53, i32 1
  store ptr %54, ptr %8, align 8, !tbaa !5
  br label %15, !llvm.loop !15

55:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

; 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

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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @insertionSortTim(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds i64, ptr %0, i64 %4
  %6 = sext i32 %2 to i64
  %7 = getelementptr inbounds i64, ptr %0, i64 %6
  %.01724 = getelementptr inbounds i8, ptr %5, i64 8
  %.not25 = icmp ugt ptr %.01724, %7
  br i1 %.not25, label %._crit_edge, label %.lr.ph28

.lr.ph28:                                         ; preds = %3, %.critedge
  %.01727 = phi ptr [ %.017, %.critedge ], [ %.01724, %3 ]
  %.pn26 = phi ptr [ %.01727, %.critedge ], [ %5, %3 ]
  %8 = load i64, ptr %.01727, align 8, !tbaa !5
  %.not1920 = icmp ult ptr %.pn26, %5
  br i1 %.not1920, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph28, %11
  %.021 = phi ptr [ %13, %11 ], [ %.pn26, %.lr.ph28 ]
  %9 = load i64, ptr %.021, align 8, !tbaa !5
  %10 = icmp sgt i64 %9, %8
  br i1 %10, label %11, label %.critedge

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %.021, i64 8
  store i64 %9, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.021, i64 -8
  %.not19 = icmp ult ptr %13, %5
  br i1 %.not19, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %11, %.lr.ph28
  %.0.lcssa = phi ptr [ %.pn26, %.lr.ph28 ], [ %13, %11 ], [ %.021, %.lr.ph ]
  %14 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  store i64 %8, ptr %14, align 8, !tbaa !5
  %.017 = getelementptr inbounds i8, ptr %.01727, i64 8
  %.not = icmp ugt ptr %.017, %7
  br i1 %.not, label %._crit_edge, label %.lr.ph28, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %3
  ret void
}

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


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