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

; 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 }
%struct.s_pocket = type { ptr, ptr, float, float, float, float, [3 x float], i32, i32, i32, i32 }
%struct.c_lst_vertices = type { ptr, ptr, ptr, i64 }
%struct.node_vertice = type { ptr, ptr, ptr }
%struct.s_vvertice = type { i32, i32, i32, i32, i32, float, float, float, float, i32, i32, [4 x i32], [4 x ptr], [3 x float], float }

; 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: nounwind uwtable
define dso_local ptr @searchPocket(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr null, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !9
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %36

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.c_lst_pockets, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %5, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %31, %8
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %29

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.node_pocket, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds %struct.s_pocket, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds %struct.c_lst_vertices, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %struct.node_vertice, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %25 = getelementptr inbounds %struct.s_vvertice, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !23
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = icmp ne i32 %26, %27
  br label %29

29:                                               ; preds = %15, %12
  %30 = phi i1 [ false, %12 ], [ %28, %15 ]
  br i1 %30, label %31, label %35

31:                                               ; preds = %29
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.node_pocket, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !25
  store ptr %34, ptr %5, align 8, !tbaa !9
  br label %12, !llvm.loop !26

35:                                               ; preds = %29
  br label %36

36:                                               ; preds = %35, %2
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret ptr %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"c_lst_pockets", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !10, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"node_pocket", !10, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!17, !10, i64 8}
!17 = !{!"s_pocket", !10, i64 0, !10, i64 8, !18, i64 16, !18, i64 20, !18, i64 24, !18, i64 28, !7, i64 32, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56}
!18 = !{!"float", !7, i64 0}
!19 = !{!20, !10, i64 0}
!20 = !{!"c_lst_vertices", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24}
!21 = !{!22, !10, i64 16}
!22 = !{!"node_vertice", !10, i64 0, !10, i64 8, !10, i64 16}
!23 = !{!24, !6, i64 0}
!24 = !{!"s_vvertice", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !18, i64 20, !18, i64 24, !18, i64 28, !18, i64 32, !6, i64 36, !6, i64 40, !7, i64 44, !7, i64 64, !7, i64 96, !18, i64 108}
!25 = !{!15, !10, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @searchPocket(i32 noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.critedge, label %.preheader

.preheader:                                       ; preds = %2, %3
  %.0.in = phi ptr [ %.0, %3 ], [ %1, %2 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not7 = icmp eq ptr %.0, null
  br i1 %.not7, label %.critedge, label %3

3:                                                ; preds = %.preheader
  %4 = getelementptr inbounds i8, ptr %.0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !18
  %11 = load i32, ptr %10, align 8, !tbaa !20
  %.not8 = icmp eq i32 %11, %0
  br i1 %.not8, label %.critedge, label %.preheader, !llvm.loop !22

.critedge:                                        ; preds = %3, %.preheader, %2
  %.1 = phi ptr [ null, %2 ], [ null, %.preheader ], [ %.0, %3 ]
  ret ptr %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"node_pocket", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !6, i64 8}
!12 = !{!"s_pocket", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !7, i64 32, !14, i64 44, !14, i64 48, !14, i64 52, !14, i64 56}
!13 = !{!"float", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"c_lst_vertices", !6, i64 0, !6, i64 8, !6, i64 16, !17, i64 24}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !6, i64 16}
!19 = !{!"node_vertice", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!21, !14, i64 0}
!21 = !{!"s_vvertice", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !14, i64 36, !14, i64 40, !7, i64 44, !7, i64 64, !7, i64 96, !13, i64 108}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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