; LLVM IR from rantala/string-sorting :: external/lcp-quicksort.ll (Z7strsortPPhPiii)

; 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 uwtable
define dso_local void @_Z7strsortPPhPiii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  br label %79

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %19, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %20 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %20, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  store ptr %25, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %12, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %67, %18
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %68

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %35, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  %44 = call noundef i32 @_Z9lcpstrcmpPKhS0_Ri(ptr noundef %34, ptr noundef %39, ptr noundef nonnull align 4 dereferenceable(4) %43)
  store i32 %44, ptr %13, align 4, !tbaa !9
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %54

47:                                               ; preds = %33
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %12, align 4, !tbaa !9
  call void @_Z4exchPPhPiii(ptr noundef %48, ptr noundef %49, i32 noundef %50, i32 noundef %52)
  br label %67

54:                                               ; preds = %33
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = icmp sgt i32 %55, 0
  br i1 %56, label %57, label %63

57:                                               ; preds = %54
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr %10, align 4, !tbaa !9
  call void @_Z4exchPPhPiii(ptr noundef %58, ptr noundef %59, i32 noundef %60, i32 noundef %61)
  br label %66

63:                                               ; preds = %54
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %12, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %63, %57
  br label %67

67:                                               ; preds = %66, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %28, !llvm.loop !11

68:                                               ; preds = %32
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = sub nsw i32 %72, 1
  call void @_Z7lcpsortILb1EEvPPhPiii(ptr noundef %69, ptr noundef %70, i32 noundef %71, i32 noundef %73)
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  %78 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z7lcpsortILb0EEvPPhPiii(ptr noundef %74, ptr noundef %75, i32 noundef %77, i32 noundef %78)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %79

79:                                               ; preds = %68, %17
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9lcpstrcmpPKhS0_Ri(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z4exchPPhPiii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7lcpsortILb1EEvPPhPiii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7lcpsortILb0EEvPPhPiii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

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


; 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 uwtable
define dso_local void @_Z7strsortPPhPiii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp sgt i32 %3, %2
  br i1 %.not, label %.lr.ph.preheader, label %26

.lr.ph.preheader:                                 ; preds = %4
  %5 = sext i32 %2 to i64
  %6 = getelementptr inbounds ptr, ptr %0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = add nsw i32 %2, 1
  br label %.lr.ph

._crit_edge:                                      ; preds = %25
  %9 = add nsw i32 %.1, -1
  tail call void @_Z7lcpsortILb1EEvPPhPiii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %2, i32 noundef %9)
  %10 = add nsw i32 %.135, 1
  tail call void @_Z7lcpsortILb0EEvPPhPiii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %10, i32 noundef %3)
  br label %26

.lr.ph:                                           ; preds = %.lr.ph.preheader, %25
  %.044 = phi i32 [ %.1, %25 ], [ %2, %.lr.ph.preheader ]
  %.03243 = phi i32 [ %.133, %25 ], [ %8, %.lr.ph.preheader ]
  %.03442 = phi i32 [ %.135, %25 ], [ %3, %.lr.ph.preheader ]
  %11 = sext i32 %.03243 to i64
  %12 = getelementptr inbounds ptr, ptr %0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %1, i64 %11
  %15 = tail call noundef i32 @_Z9lcpstrcmpPKhS0_Ri(ptr noundef %7, ptr noundef %13, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %.lr.ph
  %18 = add nsw i32 %.044, 1
  %19 = add nsw i32 %.03243, 1
  tail call void @_Z4exchPPhPiii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %.044, i32 noundef %.03243)
  br label %25

20:                                               ; preds = %.lr.ph
  %.not40 = icmp eq i32 %15, 0
  br i1 %.not40, label %23, label %21

21:                                               ; preds = %20
  %22 = add nsw i32 %.03442, -1
  tail call void @_Z4exchPPhPiii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %.03243, i32 noundef %.03442)
  br label %25

23:                                               ; preds = %20
  %24 = add nsw i32 %.03243, 1
  br label %25

25:                                               ; preds = %21, %23, %17
  %.135 = phi i32 [ %.03442, %17 ], [ %22, %21 ], [ %.03442, %23 ]
  %.133 = phi i32 [ %19, %17 ], [ %.03243, %21 ], [ %24, %23 ]
  %.1 = phi i32 [ %18, %17 ], [ %.044, %21 ], [ %.044, %23 ]
  %.not39 = icmp sgt i32 %.133, %.135
  br i1 %.not39, label %._crit_edge, label %.lr.ph, !llvm.loop !9

26:                                               ; preds = %4, %._crit_edge
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9lcpstrcmpPKhS0_Ri(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z4exchPPhPiii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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