; LLVM IR from Discngine/fpocket :: src (psorting)

; 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.c_lst_pockets = type { ptr, ptr, ptr, i64, ptr }
%struct.node_pocket = type { ptr, ptr, ptr }

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

15:                                               ; preds = %26, %2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %24

18:                                               ; preds = %15
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.c_lst_pockets, ptr %20, i32 0, i32 3
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = icmp ult i64 %19, %22
  br label %24

24:                                               ; preds = %18, %15
  %25 = phi i1 [ false, %15 ], [ %23, %18 ]
  br i1 %25, label %26, label %36

26:                                               ; preds = %24
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds ptr, ptr %28, i64 %29
  store ptr %27, ptr %30, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.node_pocket, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  store ptr %33, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = add i64 %34, 1
  store i64 %35, ptr %5, align 8, !tbaa !9
  br label %15, !llvm.loop !16

36:                                               ; preds = %24
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = sub i64 %39, 1
  %41 = trunc i64 %40 to i32
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @pock_qsort_rec(ptr noundef %37, ptr noundef %38, i32 noundef 0, i32 noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void @my_free(ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

declare ptr @my_calloc(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @pock_qsort_rec(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #0

declare void @my_free(ptr noundef) #2

; 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"c_lst_pockets", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"node_pocket", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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: nounwind uwtable
define dso_local void @sort_pockets(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = tail call ptr @my_calloc(i64 noundef %4, i64 noundef 8) #2
  %.015 = load ptr, ptr %0, align 8, !tbaa !11
  %.not16 = icmp eq ptr %.015, null
  br i1 %.not16, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = load i64, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %.lr.ph, %8
  %.018 = phi ptr [ %.015, %.lr.ph ], [ %.0, %8 ]
  %.01417 = phi i64 [ 0, %.lr.ph ], [ %10, %8 ]
  %exitcond.not = icmp eq i64 %.01417, %6
  br i1 %exitcond.not, label %.critedge.loopexit, label %8

8:                                                ; preds = %7
  %9 = getelementptr inbounds ptr, ptr %5, i64 %.01417
  store ptr %.018, ptr %9, align 8, !tbaa !11
  %10 = add i64 %.01417, 1
  %.0 = load ptr, ptr %.018, align 8, !tbaa !11
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.critedge.loopexit, label %7, !llvm.loop !12

.critedge.loopexit:                               ; preds = %8, %7
  %.014.lcssa.ph = phi i64 [ %6, %7 ], [ %10, %8 ]
  %11 = trunc i64 %.014.lcssa.ph to i32
  %12 = add i32 %11, -1
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %2
  %.014.lcssa = phi i32 [ -1, %2 ], [ %12, %.critedge.loopexit ]
  tail call void @pock_qsort_rec(ptr noundef nonnull %0, ptr noundef %5, i32 noundef 0, i32 noundef %.014.lcssa, ptr noundef %1)
  tail call void @my_free(ptr noundef %5) #2
  ret void
}

declare ptr @my_calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @pock_qsort_rec(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @my_free(ptr noundef) local_unnamed_addr #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 = { "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 }

!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, !10, i64 24}
!6 = !{!"c_lst_pockets", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass