; LLVM IR from godzilla-foundation/godzilla-community :: core/deps/nanomsg-1.1.5/src/protocols/utils (priolist)

; 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.nn_priolist_data = type { ptr, i32, %struct.nn_list_item }
%struct.nn_list_item = type { ptr, ptr }
%struct.nn_priolist = type { [16 x %struct.nn_priolist_slot], i32 }
%struct.nn_priolist_slot = type { %struct.nn_list, ptr }
%struct.nn_list = type { ptr, ptr }

; 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 void @nn_priolist_rm(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.nn_priolist_data, ptr %8, i32 0, i32 2
  %10 = call i32 @nn_list_item_isinlist(ptr noundef %9)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.nn_priolist_data, ptr %13, i32 0, i32 2
  call void @nn_list_item_term(ptr noundef %14)
  store i32 1, ptr %7, align 4
  br label %109

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.nn_priolist, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.nn_priolist_data, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [16 x %struct.nn_priolist_slot], ptr %17, i64 0, i64 %22
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.nn_priolist_slot, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = icmp ne ptr %26, %27
  br i1 %28, label %29, label %37

29:                                               ; preds = %15
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.nn_priolist_slot, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.nn_priolist_data, ptr %32, i32 0, i32 2
  %34 = call ptr @nn_list_erase(ptr noundef %31, ptr noundef %33)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.nn_priolist_data, ptr %35, i32 0, i32 2
  call void @nn_list_item_term(ptr noundef %36)
  store i32 1, ptr %7, align 4
  br label %109

37:                                               ; preds = %15
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.nn_priolist_slot, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.nn_priolist_data, ptr %40, i32 0, i32 2
  %42 = call ptr @nn_list_erase(ptr noundef %39, ptr noundef %41)
  store ptr %42, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %37
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 -16
  br label %49

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48, %45
  %50 = phi ptr [ %47, %45 ], [ null, %48 ]
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.nn_priolist_slot, ptr %51, i32 0, i32 1
  store ptr %50, ptr %52, align 8, !tbaa !13
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.nn_priolist_data, ptr %53, i32 0, i32 2
  call void @nn_list_item_term(ptr noundef %54)
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.nn_priolist_slot, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = icmp ne ptr %57, null
  br i1 %58, label %73, label %59

59:                                               ; preds = %49
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.nn_priolist_slot, ptr %60, i32 0, i32 0
  %62 = call ptr @nn_list_begin(ptr noundef %61)
  store ptr %62, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %68

65:                                               ; preds = %59
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 -16
  br label %69

68:                                               ; preds = %59
  br label %69

69:                                               ; preds = %68, %65
  %70 = phi ptr [ %67, %65 ], [ null, %68 ]
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.nn_priolist_slot, ptr %71, i32 0, i32 1
  store ptr %70, ptr %72, align 8, !tbaa !13
  br label %73

73:                                               ; preds = %69, %49
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.nn_priolist, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !16
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.nn_priolist_data, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 8, !tbaa !9
  %80 = icmp ne i32 %76, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %73
  store i32 1, ptr %7, align 4
  br label %109

82:                                               ; preds = %73
  br label %83

83:                                               ; preds = %107, %82
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.nn_priolist, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.nn_priolist, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 8, !tbaa !16
  %89 = sub nsw i32 %88, 1
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [16 x %struct.nn_priolist_slot], ptr %85, i64 0, i64 %90
  %92 = getelementptr inbounds %struct.nn_priolist_slot, ptr %91, i32 0, i32 0
  %93 = call i32 @nn_list_empty(ptr noundef %92)
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %108

95:                                               ; preds = %83
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.nn_priolist, ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 8, !tbaa !16
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %97, align 8, !tbaa !16
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.nn_priolist, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 8, !tbaa !16
  %103 = icmp sgt i32 %102, 16
  br i1 %103, label %104, label %107

104:                                              ; preds = %95
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.nn_priolist, ptr %105, i32 0, i32 1
  store i32 -1, ptr %106, align 8, !tbaa !16
  store i32 1, ptr %7, align 4
  br label %109

107:                                              ; preds = %95
  br label %83, !llvm.loop !18

108:                                              ; preds = %83
  store i32 0, ptr %7, align 4
  br label %109

109:                                              ; preds = %108, %104, %81, %29, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %110 = load i32, ptr %7, align 4
  switch i32 %110, label %112 [
    i32 0, label %111
    i32 1, label %111
  ]

111:                                              ; preds = %109, %109
  ret void

112:                                              ; preds = %109
  unreachable
}

declare i32 @nn_list_item_isinlist(ptr noundef) #2

declare void @nn_list_item_term(ptr noundef) #2

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

declare ptr @nn_list_begin(ptr noundef) #2

declare i32 @nn_list_empty(ptr noundef) #2

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 = { "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, !11, i64 8}
!10 = !{!"nn_priolist_data", !6, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"nn_list_item", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 16}
!14 = !{!"nn_priolist_slot", !15, i64 0, !6, i64 16}
!15 = !{!"nn_list", !6, i64 0, !6, i64 8}
!16 = !{!17, !11, i64 384}
!17 = !{!"nn_priolist", !7, i64 0, !11, i64 384}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.nn_priolist_slot = type { %struct.nn_list, ptr }
%struct.nn_list = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @nn_priolist_rm(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = tail call i32 @nn_list_item_isinlist(ptr noundef nonnull %3) #2
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %6

5:                                                ; preds = %2
  tail call void @nn_list_item_term(ptr noundef nonnull %3) #2
  br label %.loopexit

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = add nsw i32 %8, -1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [16 x %struct.nn_priolist_slot], ptr %0, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %.not27 = icmp eq ptr %13, %1
  %14 = tail call ptr @nn_list_erase(ptr noundef nonnull %11, ptr noundef nonnull %3) #2
  br i1 %.not27, label %16, label %15

15:                                               ; preds = %6
  tail call void @nn_list_item_term(ptr noundef nonnull %3) #2
  br label %.loopexit

16:                                               ; preds = %6
  %.not28 = icmp eq ptr %14, null
  %17 = getelementptr inbounds i8, ptr %14, i64 -16
  %18 = select i1 %.not28, ptr null, ptr %17
  store ptr %18, ptr %12, align 8, !tbaa !12
  tail call void @nn_list_item_term(ptr noundef nonnull %3) #2
  %19 = load ptr, ptr %12, align 8, !tbaa !12
  %.not29 = icmp eq ptr %19, null
  br i1 %.not29, label %20, label %24

20:                                               ; preds = %16
  %21 = tail call ptr @nn_list_begin(ptr noundef nonnull %11) #2
  %.not30 = icmp eq ptr %21, null
  %22 = getelementptr inbounds i8, ptr %21, i64 -16
  %23 = select i1 %.not30, ptr null, ptr %22
  store ptr %23, ptr %12, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %20, %16
  %25 = getelementptr inbounds i8, ptr %0, i64 384
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = load i32, ptr %7, align 8, !tbaa !5
  %.not31 = icmp eq i32 %26, %27
  br i1 %.not31, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %24
  %28 = add nsw i32 %26, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %33
  %29 = phi i32 [ %28, %.preheader.preheader ], [ %34, %33 ]
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [16 x %struct.nn_priolist_slot], ptr %0, i64 0, i64 %30
  %32 = tail call i32 @nn_list_empty(ptr noundef %31) #2
  %.not32 = icmp eq i32 %32, 0
  br i1 %.not32, label %.loopexit, label %33

33:                                               ; preds = %.preheader
  %34 = load i32, ptr %25, align 8, !tbaa !15
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %25, align 8, !tbaa !15
  %36 = icmp sgt i32 %34, 15
  br i1 %36, label %37, label %.preheader, !llvm.loop !17

37:                                               ; preds = %33
  store i32 -1, ptr %25, align 8, !tbaa !15
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %24, %37, %15, %5
  ret void
}

declare i32 @nn_list_item_isinlist(ptr noundef) local_unnamed_addr #1

declare void @nn_list_item_term(ptr noundef) local_unnamed_addr #1

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

declare ptr @nn_list_begin(ptr noundef) local_unnamed_addr #1

declare i32 @nn_list_empty(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 8}
!6 = !{!"nn_priolist_data", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"nn_list_item", !7, i64 0, !7, i64 8}
!12 = !{!13, !7, i64 16}
!13 = !{!"nn_priolist_slot", !14, i64 0, !7, i64 16}
!14 = !{!"nn_list", !7, i64 0, !7, i64 8}
!15 = !{!16, !10, i64 384}
!16 = !{!"nn_priolist", !8, i64 0, !10, i64 384}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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