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

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

17:                                               ; preds = %57, %1
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_lst_vvertice, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %60

23:                                               ; preds = %17
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.s_vvertice, ptr %24, i64 %26
  store ptr %27, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %28 = call ptr @alloc_pocket()
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = call ptr @c_lst_vertices_alloc()
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.s_pocket, ptr %30, i32 0, i32 1
  store ptr %29, ptr %31, align 8, !tbaa !14
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_pocket, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = call ptr @c_lst_vertices_add_last(ptr noundef %34, ptr noundef %35)
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.s_vvertice, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %23
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !9
  br label %47

44:                                               ; preds = %23
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %44, %41
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_pocket, ptr %50, i32 0, i32 7
  store i32 %49, ptr %51, align 4, !tbaa !19
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = call ptr @c_lst_pockets_add_last(ptr noundef %52, ptr noundef %53, i32 noundef %54, i32 noundef %55)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %57

57:                                               ; preds = %47
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !9
  br label %17, !llvm.loop !20

60:                                               ; preds = %17
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.c_lst_pockets, ptr %62, i32 0, i32 4
  store ptr %61, ptr %63, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.c_lst_pockets, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !25
  store ptr %66, ptr %11, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %70, %60
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %86

70:                                               ; preds = %67
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.node_pocket, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !26
  %74 = getelementptr inbounds %struct.s_pocket, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !14
  %76 = getelementptr inbounds %struct.c_lst_vertices, ptr %75, i32 0, i32 3
  %77 = load i64, ptr %76, align 8, !tbaa !28
  %78 = trunc i64 %77 to i32
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.node_pocket, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !26
  %82 = getelementptr inbounds %struct.s_pocket, ptr %81, i32 0, i32 8
  store i32 %78, ptr %82, align 8, !tbaa !30
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.node_pocket, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !31
  store ptr %85, ptr %11, align 8, !tbaa !5
  br label %67, !llvm.loop !32

86:                                               ; preds = %67
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.c_lst_pockets, ptr %87, i32 0, i32 3
  %89 = load i64, ptr %88, align 8, !tbaa !33
  %90 = icmp ugt i64 %89, 0
  br i1 %90, label %91, label %93

91:                                               ; preds = %86
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %92, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %95

93:                                               ; preds = %86
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  call void @my_free(ptr noundef %94)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %95

95:                                               ; preds = %93, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %96 = load ptr, ptr %2, align 8
  ret ptr %96
}

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @c_lst_pockets_alloc() #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @alloc_pocket() #0

declare ptr @c_lst_vertices_alloc() #2

declare ptr @c_lst_vertices_add_last(ptr noundef, ptr noundef) #2

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

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

declare void @my_free(ptr noundef) #2

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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"s_lst_vvertice", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !10, i64 44}
!13 = !{!12, !10, i64 40}
!14 = !{!15, !6, i64 8}
!15 = !{!"s_pocket", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 20, !16, i64 24, !16, i64 28, !7, i64 32, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !10, i64 16}
!18 = !{!"s_vvertice", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !16, i64 20, !16, i64 24, !16, i64 28, !16, i64 32, !10, i64 36, !10, i64 40, !7, i64 44, !7, i64 64, !7, i64 96, !16, i64 108}
!19 = !{!15, !10, i64 44}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !6, i64 32}
!23 = !{!"c_lst_pockets", !6, i64 0, !6, i64 8, !6, i64 16, !24, i64 24, !6, i64 32}
!24 = !{!"long", !7, i64 0}
!25 = !{!23, !6, i64 0}
!26 = !{!27, !6, i64 16}
!27 = !{!"node_pocket", !6, i64 0, !6, i64 8, !6, i64 16}
!28 = !{!29, !24, i64 24}
!29 = !{!"c_lst_vertices", !6, i64 0, !6, i64 8, !6, i64 16, !24, i64 24}
!30 = !{!15, !10, i64 48}
!31 = !{!27, !6, i64 0}
!32 = distinct !{!32, !21}
!33 = !{!23, !24, i64 24}


; 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.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: nounwind uwtable
define dso_local ptr @assign_pockets(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call ptr @c_lst_pockets_alloc()
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %7 = getelementptr inbounds %struct.s_vvertice, ptr %2, i64 %indvars.iv
  %8 = tail call ptr @alloc_pocket()
  %9 = tail call ptr @c_lst_vertices_alloc() #2
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %9, ptr %10, align 8, !tbaa !12
  %11 = tail call ptr @c_lst_vertices_add_last(ptr noundef %9, ptr noundef %7) #2
  %12 = getelementptr inbounds i8, ptr %7, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %14 = icmp eq i32 %13, 0
  %. = zext i1 %14 to i32
  %not. = xor i1 %14, true
  %.33 = zext i1 %not. to i32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = getelementptr inbounds i8, ptr %8, i64 44
  %16 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %16, ptr %15, align 4, !tbaa !17
  %17 = tail call ptr @c_lst_pockets_add_last(ptr noundef %3, ptr noundef %8, i32 noundef %., i32 noundef %.33)
  %18 = load i32, ptr %4, align 8, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %1
  %21 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr %0, ptr %21, align 8, !tbaa !20
  %.035 = load ptr, ptr %3, align 8, !tbaa !23
  %.not36 = icmp eq ptr %.035, null
  br i1 %.not36, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %._crit_edge, %.lr.ph39
  %.037 = phi ptr [ %.0, %.lr.ph39 ], [ %.035, %._crit_edge ]
  %22 = getelementptr inbounds i8, ptr %.037, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !24
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %25, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !26
  %28 = trunc i64 %27 to i32
  %29 = getelementptr inbounds i8, ptr %23, i64 48
  store i32 %28, ptr %29, align 8, !tbaa !28
  %.0 = load ptr, ptr %.037, align 8, !tbaa !23
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge40, label %.lr.ph39, !llvm.loop !29

._crit_edge40:                                    ; preds = %.lr.ph39, %._crit_edge
  %30 = getelementptr inbounds i8, ptr %3, i64 24
  %31 = load i64, ptr %30, align 8, !tbaa !30
  %.not32 = icmp eq i64 %31, 0
  br i1 %.not32, label %32, label %33

32:                                               ; preds = %._crit_edge40
  tail call void @my_free(ptr noundef nonnull %3) #2
  br label %33

33:                                               ; preds = %._crit_edge40, %32
  %.028 = phi ptr [ null, %32 ], [ %3, %._crit_edge40 ]
  ret ptr %.028
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @c_lst_pockets_alloc() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @alloc_pocket() local_unnamed_addr #0

declare ptr @c_lst_vertices_alloc() local_unnamed_addr #1

declare ptr @c_lst_vertices_add_last(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @c_lst_pockets_add_last(ptr noundef, ptr noundef, i32 noundef, i32 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, !7, i64 0}
!6 = !{!"s_lst_vvertice", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !10, i64 44}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 40}
!12 = !{!13, !7, i64 8}
!13 = !{!"s_pocket", !7, i64 0, !7, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !8, i64 32, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56}
!14 = !{!"float", !8, i64 0}
!15 = !{!16, !10, i64 16}
!16 = !{!"s_vvertice", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !10, i64 36, !10, i64 40, !8, i64 44, !8, i64 64, !8, i64 96, !14, i64 108}
!17 = !{!13, !10, i64 44}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !7, i64 32}
!21 = !{!"c_lst_pockets", !7, i64 0, !7, i64 8, !7, i64 16, !22, i64 24, !7, i64 32}
!22 = !{!"long", !8, i64 0}
!23 = !{!7, !7, i64 0}
!24 = !{!25, !7, i64 16}
!25 = !{!"node_pocket", !7, i64 0, !7, i64 8, !7, i64 16}
!26 = !{!27, !22, i64 24}
!27 = !{!"c_lst_vertices", !7, i64 0, !7, i64 8, !7, i64 16, !22, i64 24}
!28 = !{!13, !10, i64 48}
!29 = distinct !{!29, !19}
!30 = !{!21, !22, i64 24}


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