; LLVM IR from codemistic/Data-Structures-and-Algorithms :: CPP/sorting/intro_sort.ll (Z9introsortPiS_S_i)

; 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: mustprogress nounwind uwtable
declare dso_local void @_Z13insertionsortPiii(ptr noundef, i32 noundef, i32 noundef) #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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z13randPartitionPiii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8heapsortPiS_(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9introsortPiS_S_i(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = ptrtoint ptr %10 to i64
  %13 = ptrtoint ptr %11 to i64
  %14 = sub i64 %12, %13
  %15 = sdiv exact i64 %14, 4
  %16 = icmp slt i64 %15, 16
  br i1 %16, label %17, label %33

17:                                               ; preds = %4
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = ptrtoint ptr %19 to i64
  %22 = ptrtoint ptr %20 to i64
  %23 = sub i64 %21, %22
  %24 = sdiv exact i64 %23, 4
  %25 = trunc i64 %24 to i32
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = ptrtoint ptr %26 to i64
  %29 = ptrtoint ptr %27 to i64
  %30 = sub i64 %28, %29
  %31 = sdiv exact i64 %30, 4
  %32 = trunc i64 %31 to i32
  call void @_Z13insertionsortPiii(ptr noundef %18, i32 noundef %25, i32 noundef %32)
  br label %76

33:                                               ; preds = %4
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %40

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %38, i64 1
  call void @_Z8heapsortPiS_(ptr noundef %37, ptr noundef %39)
  br label %75

40:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = ptrtoint ptr %42 to i64
  %45 = ptrtoint ptr %43 to i64
  %46 = sub i64 %44, %45
  %47 = sdiv exact i64 %46, 4
  %48 = trunc i64 %47 to i32
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = ptrtoint ptr %49 to i64
  %52 = ptrtoint ptr %50 to i64
  %53 = sub i64 %51, %52
  %54 = sdiv exact i64 %53, 4
  %55 = trunc i64 %54 to i32
  %56 = call noundef i32 @_Z13randPartitionPiii(ptr noundef %41, i32 noundef %48, i32 noundef %55)
  store i32 %56, ptr %9, align 4, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  %63 = getelementptr inbounds i32, ptr %62, i64 -1
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  call void @_Z9introsortPiS_S_i(ptr noundef %57, ptr noundef %58, ptr noundef %63, i32 noundef %65)
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  %71 = getelementptr inbounds i32, ptr %70, i64 1
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = sub nsw i32 %73, 1
  call void @_Z9introsortPiS_S_i(ptr noundef %66, ptr noundef %71, ptr noundef %72, i32 noundef %74)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %75

75:                                               ; preds = %40, %36
  br label %76

76:                                               ; preds = %75, %17
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; 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: mustprogress nounwind uwtable
declare dso_local void @_Z13insertionsortPiii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z13randPartitionPiii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8heapsortPiS_(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9introsortPiS_S_i(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = ptrtoint ptr %2 to i64
  %6 = ptrtoint ptr %1 to i64
  %7 = sub i64 %5, %6
  %8 = icmp slt i64 %7, 64
  %.pre = ptrtoint ptr %0 to i64
  %.pre36 = sub i64 %5, %.pre
  %.pre38 = lshr exact i64 %.pre36, 2
  %.pre40 = trunc i64 %.pre38 to i32
  br i1 %8, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %.lcssa = phi i64 [ %6, %4 ], [ %25, %tailrecurse ]
  %9 = sub i64 %.lcssa, %.pre
  %10 = lshr exact i64 %9, 2
  %11 = trunc i64 %10 to i32
  tail call void @_Z13insertionsortPiii(ptr noundef %0, i32 noundef %11, i32 noundef %.pre40)
  br label %28

.lr.ph:                                           ; preds = %4, %tailrecurse
  %12 = phi i64 [ %25, %tailrecurse ], [ %6, %4 ]
  %.tr2632 = phi i32 [ %23, %tailrecurse ], [ %3, %4 ]
  %.tr2431 = phi ptr [ %24, %tailrecurse ], [ %1, %4 ]
  %13 = icmp eq i32 %.tr2632, 0
  br i1 %13, label %14, label %tailrecurse

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %2, i64 4
  tail call void @_Z8heapsortPiS_(ptr noundef %.tr2431, ptr noundef nonnull %15)
  br label %28

tailrecurse:                                      ; preds = %.lr.ph
  %16 = sub i64 %12, %.pre
  %17 = lshr exact i64 %16, 2
  %18 = trunc i64 %17 to i32
  %19 = tail call noundef i32 @_Z13randPartitionPiii(ptr noundef %0, i32 noundef %18, i32 noundef %.pre40)
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 -4
  %23 = add nsw i32 %.tr2632, -1
  tail call void @_Z9introsortPiS_S_i(ptr noundef %0, ptr noundef %.tr2431, ptr noundef nonnull %22, i32 noundef %23)
  %24 = getelementptr inbounds i8, ptr %21, i64 4
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %5, %25
  %27 = icmp slt i64 %26, 64
  br i1 %27, label %tailrecurse._crit_edge, label %.lr.ph

28:                                               ; preds = %14, %tailrecurse._crit_edge
  ret void
}

attributes #0 = { 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 #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" }

!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)"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass