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

declare i32 @nn_list_empty(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @nn_priolist_activate(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = 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
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.nn_priolist, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.nn_priolist_data, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = sub nsw i32 %11, 1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [16 x %struct.nn_priolist_slot], ptr %8, i64 0, i64 %13
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.nn_priolist_slot, ptr %15, i32 0, i32 0
  %17 = call i32 @nn_list_empty(ptr noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %27, label %19

19:                                               ; preds = %2
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.nn_priolist_slot, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.nn_priolist_data, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.nn_priolist_slot, ptr %24, i32 0, i32 0
  %26 = call ptr @nn_list_end(ptr noundef %25)
  call void @nn_list_insert(ptr noundef %21, ptr noundef %23, ptr noundef %26)
  store i32 1, ptr %6, align 4
  br label %63

27:                                               ; preds = %2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.nn_priolist_slot, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.nn_priolist_data, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.nn_priolist_slot, ptr %32, i32 0, i32 0
  %34 = call ptr @nn_list_end(ptr noundef %33)
  call void @nn_list_insert(ptr noundef %29, ptr noundef %31, ptr noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.nn_priolist_slot, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.nn_priolist, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = icmp eq i32 %40, -1
  br i1 %41, label %42, label %48

42:                                               ; preds = %27
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.nn_priolist_data, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !9
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.nn_priolist, ptr %46, i32 0, i32 1
  store i32 %45, ptr %47, align 8, !tbaa !16
  store i32 1, ptr %6, align 4
  br label %63

48:                                               ; preds = %27
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.nn_priolist, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.nn_priolist_data, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !9
  %55 = icmp sgt i32 %51, %54
  br i1 %55, label %56, label %62

56:                                               ; preds = %48
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.nn_priolist_data, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.nn_priolist, ptr %60, i32 0, i32 1
  store i32 %59, ptr %61, align 8, !tbaa !16
  store i32 1, ptr %6, align 4
  br label %63

62:                                               ; preds = %48
  store i32 0, ptr %6, align 4
  br label %63

63:                                               ; preds = %62, %56, %42, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %64 = load i32, ptr %6, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
    i32 1, label %65
  ]

65:                                               ; preds = %63, %63
  ret void

66:                                               ; preds = %63
  unreachable
}

declare void @nn_list_insert(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @nn_list_end(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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/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}


; 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 }

declare i32 @nn_list_empty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @nn_priolist_activate(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add nsw i32 %4, -1
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [16 x %struct.nn_priolist_slot], ptr %0, i64 0, i64 %6
  %8 = tail call i32 @nn_list_empty(ptr noundef %7) #2
  %.not = icmp eq i32 %8, 0
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = tail call ptr @nn_list_end(ptr noundef %7) #2
  tail call void @nn_list_insert(ptr noundef %7, ptr noundef nonnull %9, ptr noundef %10) #2
  br i1 %.not, label %18, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %1, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 384
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = icmp eq i32 %14, -1
  %16 = load i32, ptr %3, align 8, !tbaa !5
  %17 = icmp sgt i32 %14, %16
  %or.cond = select i1 %15, i1 true, i1 %17
  br i1 %or.cond, label %.sink.split, label %18

.sink.split:                                      ; preds = %11
  store i32 %16, ptr %13, align 8, !tbaa !15
  br label %18

18:                                               ; preds = %11, %.sink.split, %2
  ret void
}

declare void @nn_list_insert(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @nn_list_end(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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, !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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass