; LLVM IR from mwarning/KadNode :: src (kad)

; 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.bucket = type { i32, [20 x i8], i32, i32, i64, ptr, %struct.sockaddr_storage, i32, ptr }
%struct.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.node = type { [20 x i8], %struct.sockaddr_storage, i32, i64, i64, i64, i32, 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
declare hidden i32 @node_good(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @kad_count_bucket(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %38, %2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %42

10:                                               ; preds = %7
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %32

13:                                               ; preds = %10
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.bucket, ptr %14, i32 0, i32 5
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %5, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %20, %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %31

20:                                               ; preds = %17
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i32 @node_good(ptr noundef %21)
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 1, i32 0
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 7
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %17, !llvm.loop !18

31:                                               ; preds = %17
  br label %38

32:                                               ; preds = %10
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bucket, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !20
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = add nsw i32 %36, %35
  store i32 %37, ptr %6, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %32, %31
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.bucket, ptr %39, i32 0, i32 8
  %41 = load ptr, ptr %40, align 8, !tbaa !21
  store ptr %41, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !22

42:                                               ; preds = %7
  %43 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %43
}

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 = !{!"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 40}
!12 = !{!"bucket", !10, i64 0, !7, i64 4, !10, i64 24, !10, i64 28, !13, i64 32, !6, i64 40, !14, i64 48, !10, i64 176, !6, i64 184}
!13 = !{!"long", !7, i64 0}
!14 = !{!"sockaddr_storage", !15, i64 0, !7, i64 2, !13, i64 120}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !6, i64 192}
!17 = !{!"node", !7, i64 0, !14, i64 24, !10, i64 152, !13, i64 160, !13, i64 168, !13, i64 176, !10, i64 184, !6, i64 192}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !10, i64 24}
!21 = !{!12, !6, i64 184}
!22 = distinct !{!22, !19}


; 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
declare hidden i32 @node_good(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @kad_count_bucket(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not19 = icmp eq ptr %0, null
  br i1 %.not19, label %._crit_edge, label %.lr.ph22

.lr.ph22:                                         ; preds = %2
  %.not12 = icmp eq i32 %1, 0
  br i1 %.not12, label %.lr.ph22.split.us, label %.lr.ph22.split

.lr.ph22.split.us:                                ; preds = %.lr.ph22, %.lr.ph22.split.us
  %.021.us = phi i32 [ %5, %.lr.ph22.split.us ], [ 0, %.lr.ph22 ]
  %.01120.us = phi ptr [ %7, %.lr.ph22.split.us ], [ %0, %.lr.ph22 ]
  %3 = getelementptr inbounds i8, ptr %.01120.us, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add nsw i32 %4, %.021.us
  %6 = getelementptr inbounds i8, ptr %.01120.us, i64 184
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %.not.us = icmp eq ptr %7, null
  br i1 %.not.us, label %._crit_edge, label %.lr.ph22.split.us, !llvm.loop !15

.lr.ph22.split:                                   ; preds = %.lr.ph22, %.loopexit
  %.021 = phi i32 [ %.1.lcssa, %.loopexit ], [ 0, %.lr.ph22 ]
  %.01120 = phi ptr [ %14, %.loopexit ], [ %0, %.lr.ph22 ]
  %8 = getelementptr inbounds i8, ptr %.01120, i64 40
  %.01015 = load ptr, ptr %8, align 8, !tbaa !17
  %.not1316 = icmp eq ptr %.01015, null
  br i1 %.not1316, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph22.split, %.lr.ph
  %.01018 = phi ptr [ %.010, %.lr.ph ], [ %.01015, %.lr.ph22.split ]
  %.117 = phi i32 [ %11, %.lr.ph ], [ %.021, %.lr.ph22.split ]
  %9 = tail call i32 @node_good(ptr noundef nonnull %.01018)
  %.not14 = icmp ne i32 %9, 0
  %10 = zext i1 %.not14 to i32
  %11 = add nsw i32 %.117, %10
  %12 = getelementptr inbounds i8, ptr %.01018, i64 192
  %.010 = load ptr, ptr %12, align 8, !tbaa !17
  %.not13 = icmp eq ptr %.010, null
  br i1 %.not13, label %.loopexit, label %.lr.ph, !llvm.loop !18

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph22.split
  %.1.lcssa = phi i32 [ %.021, %.lr.ph22.split ], [ %11, %.lr.ph ]
  %13 = getelementptr inbounds i8, ptr %.01120, i64 184
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %._crit_edge, label %.lr.ph22.split, !llvm.loop !15

._crit_edge:                                      ; preds = %.loopexit, %.lr.ph22.split.us, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %5, %.lr.ph22.split.us ], [ %.1.lcssa, %.loopexit ]
  ret i32 %.0.lcssa
}

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

!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 24}
!6 = !{!"bucket", !7, i64 0, !8, i64 4, !7, i64 24, !7, i64 28, !10, i64 32, !11, i64 40, !12, i64 48, !7, i64 176, !11, i64 184}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"sockaddr_storage", !13, i64 0, !8, i64 2, !10, i64 120}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !11, i64 184}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass