; LLVM IR from albertobsd/keyhunt :: bsgsd.ll (Z14bsgs_introsortP11bsgs_xvaluejl)

; 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.bsgs_xvalue = type { [6 x i8], i64 }

; 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 void @_Z14bsgs_introsortP11bsgs_xvaluejl(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load i64, ptr %6, align 8, !tbaa !11
  %9 = icmp sgt i64 %8, 1
  br i1 %9, label %10, label %51

10:                                               ; preds = %3
  %11 = load i64, ptr %6, align 8, !tbaa !11
  %12 = icmp sle i64 %11, 16
  br i1 %12, label %13, label %16

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !11
  call void @_Z18bsgs_insertionsortP11bsgs_xvaluel(ptr noundef %14, i64 noundef %15)
  br label %50

16:                                               ; preds = %10
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %6, align 8, !tbaa !11
  call void @_Z15bsgs_myheapsortP11bsgs_xvaluel(ptr noundef %20, i64 noundef %21)
  br label %49

22:                                               ; preds = %16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !11
  %25 = call noundef i64 @_Z14bsgs_partitionP11bsgs_xvaluel(ptr noundef %23, i64 noundef %24)
  store i64 %25, ptr %7, align 8, !tbaa !11
  %26 = load i64, ptr %7, align 8, !tbaa !11
  %27 = icmp sgt i64 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sub i32 %30, 1
  %32 = load i64, ptr %7, align 8, !tbaa !11
  call void @_Z14bsgs_introsortP11bsgs_xvaluejl(ptr noundef %29, i32 noundef %31, i64 noundef %32)
  br label %33

33:                                               ; preds = %28, %22
  %34 = load i64, ptr %7, align 8, !tbaa !11
  %35 = load i64, ptr %6, align 8, !tbaa !11
  %36 = icmp slt i64 %34, %35
  br i1 %36, label %37, label %48

37:                                               ; preds = %33
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !11
  %40 = add nsw i64 %39, 1
  %41 = getelementptr inbounds %struct.bsgs_xvalue, ptr %38, i64 %40
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sub i32 %42, 1
  %44 = load i64, ptr %6, align 8, !tbaa !11
  %45 = load i64, ptr %7, align 8, !tbaa !11
  %46 = add nsw i64 %45, 1
  %47 = sub nsw i64 %44, %46
  call void @_Z14bsgs_introsortP11bsgs_xvaluejl(ptr noundef %41, i32 noundef %43, i64 noundef %47)
  br label %48

48:                                               ; preds = %37, %33
  br label %49

49:                                               ; preds = %48, %19
  br label %50

50:                                               ; preds = %49, %13
  br label %51

51:                                               ; preds = %50, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z14bsgs_partitionP11bsgs_xvaluel(ptr noundef, i64 noundef) #2

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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

%struct.bsgs_xvalue = type { [6 x i8], i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14bsgs_introsortP11bsgs_xvaluejl(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i64 %2, 1
  br i1 %4, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %3, %tailrecurse
  %.tr2229 = phi i64 [ %20, %tailrecurse ], [ %2, %3 ]
  %.tr2128 = phi i32 [ %19, %tailrecurse ], [ %1, %3 ]
  %.tr27 = phi ptr [ %18, %tailrecurse ], [ %0, %3 ]
  %5 = icmp ult i64 %.tr2229, 17
  br i1 %5, label %6, label %7

6:                                                ; preds = %.lr.ph
  tail call void @_Z18bsgs_insertionsortP11bsgs_xvaluel(ptr noundef %.tr27, i64 noundef %.tr2229)
  br label %.loopexit

7:                                                ; preds = %.lr.ph
  %8 = icmp eq i32 %.tr2128, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %7
  tail call void @_Z15bsgs_myheapsortP11bsgs_xvaluel(ptr noundef %.tr27, i64 noundef %.tr2229)
  br label %.loopexit

10:                                               ; preds = %7
  %11 = tail call noundef i64 @_Z14bsgs_partitionP11bsgs_xvaluel(ptr noundef %.tr27, i64 noundef %.tr2229)
  %12 = icmp sgt i64 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = add i32 %.tr2128, -1
  tail call void @_Z14bsgs_introsortP11bsgs_xvaluejl(ptr noundef %.tr27, i32 noundef %14, i64 noundef %11)
  br label %15

15:                                               ; preds = %13, %10
  %16 = icmp slt i64 %11, %.tr2229
  br i1 %16, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %15
  %17 = add nsw i64 %11, 1
  %18 = getelementptr inbounds %struct.bsgs_xvalue, ptr %.tr27, i64 %17
  %19 = add i32 %.tr2128, -1
  %20 = sub nsw i64 %.tr2229, %17
  %21 = icmp sgt i64 %20, 1
  br i1 %21, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %15, %3, %6, %9
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z14bsgs_partitionP11bsgs_xvaluel(ptr noundef, i64 noundef) local_unnamed_addr #1

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 = { 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)"}


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