; 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.gconf_t = type { i64, i64, ptr, ptr, ptr, ptr, ptr, i8, i8, i32, i32, i32, i32, ptr, i8, [8 x i8], i64, i64, i64, [8 x i32], [8 x i32] }
%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 }

@buckets = external hidden global ptr, align 8
@buckets6 = external hidden global ptr, align 8
@gconf = external global ptr, align 8
@.str.76 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.77 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.78 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.80 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.81 = external hidden unnamed_addr constant [19 x i8], align 1

; 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare ptr @str_id(ptr noundef) #2

declare ptr @str_addr(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @kad_print_buckets(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load ptr, ptr @gconf, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.gconf_t, ptr %7, i32 0, i32 11
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 2
  br i1 %10, label %11, label %13

11:                                               ; preds = %1
  %12 = load ptr, ptr @buckets, align 8, !tbaa !5
  br label %15

13:                                               ; preds = %1
  %14 = load ptr, ptr @buckets6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %13, %11
  %16 = phi ptr [ %12, %11 ], [ %14, %13 ]
  store ptr %16, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !14
  br label %17

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

20:                                               ; preds = %17
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.bucket, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [20 x i8], ptr %23, i64 0, i64 0
  %25 = call ptr @str_id(ptr noundef %24)
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.76, ptr noundef %25) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.bucket, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  store ptr %29, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !14
  br label %30

30:                                               ; preds = %53, %20
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %56

33:                                               ; preds = %30
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [20 x i8], ptr %36, i64 0, i64 0
  %38 = call ptr @str_id(ptr noundef %37)
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str.77, ptr noundef %38) #4
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 1
  %43 = call ptr @str_addr(ptr noundef %42)
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str.78, ptr noundef %43) #4
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 6
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.79, i32 noundef %48) #4
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 7
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  store ptr %52, ptr %6, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %33
  %54 = load i64, ptr %3, align 8, !tbaa !14
  %55 = add i64 %54, 1
  store i64 %55, ptr %3, align 8, !tbaa !14
  br label %30, !llvm.loop !22

56:                                               ; preds = %30
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = load i64, ptr %3, align 8, !tbaa !14
  %59 = trunc i64 %58 to i32
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.80, i32 noundef %59) #4
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.bucket, ptr %61, i32 0, i32 8
  %63 = load ptr, ptr %62, align 8, !tbaa !24
  store ptr %63, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %64

64:                                               ; preds = %56
  %65 = load i64, ptr %4, align 8, !tbaa !14
  %66 = add i64 %65, 1
  store i64 %66, ptr %4, align 8, !tbaa !14
  br label %17, !llvm.loop !25

67:                                               ; preds = %17
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = load i64, ptr %4, align 8, !tbaa !14
  %70 = trunc i64 %69 to i32
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.81, i32 noundef %70) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #4 = { 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, !13, i64 68}
!10 = !{!"gconf_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 57, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !6, i64 80, !7, i64 88, !7, i64 89, !11, i64 104, !11, i64 112, !11, i64 120, !7, i64 128, !7, i64 160}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !6, i64 40}
!16 = !{!"bucket", !13, i64 0, !7, i64 4, !13, i64 24, !13, i64 28, !11, i64 32, !6, i64 40, !17, i64 48, !13, i64 176, !6, i64 184}
!17 = !{!"sockaddr_storage", !18, i64 0, !7, i64 2, !11, i64 120}
!18 = !{!"short", !7, i64 0}
!19 = !{!20, !13, i64 184}
!20 = !{!"node", !7, i64 0, !17, i64 24, !13, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !13, i64 184, !6, i64 192}
!21 = !{!20, !6, i64 192}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!16, !6, i64 184}
!25 = distinct !{!25, !23}


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

@buckets = external hidden local_unnamed_addr global ptr, align 8
@buckets6 = external hidden local_unnamed_addr global ptr, align 8
@gconf = external local_unnamed_addr global ptr, align 8
@.str.76 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.77 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.78 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.80 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.81 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare ptr @str_id(ptr noundef) local_unnamed_addr #1

declare ptr @str_addr(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @kad_print_buckets(ptr nocapture noundef %0) local_unnamed_addr #2 {
  %2 = load ptr, ptr @gconf, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 68
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = icmp eq i32 %4, 2
  %6 = load ptr, ptr @buckets, align 8
  %7 = load ptr, ptr @buckets6, align 8
  %8 = select i1 %5, ptr %6, ptr %7
  %.not26 = icmp eq ptr %8, null
  br i1 %.not26, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %1, %._crit_edge
  %.01828 = phi ptr [ %25, %._crit_edge ], [ %8, %1 ]
  %.01927 = phi i32 [ %26, %._crit_edge ], [ 0, %1 ]
  %9 = getelementptr inbounds i8, ptr %.01828, i64 4
  %10 = tail call ptr @str_id(ptr noundef nonnull %9) #3
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.76, ptr noundef %10) #3
  %12 = getelementptr inbounds i8, ptr %.01828, i64 40
  %.022 = load ptr, ptr %12, align 8, !tbaa !5
  %.not2123 = icmp eq ptr %.022, null
  br i1 %.not2123, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph30, %.lr.ph
  %.025 = phi ptr [ %.0, %.lr.ph ], [ %.022, %.lr.ph30 ]
  %.02024 = phi i32 [ %22, %.lr.ph ], [ 0, %.lr.ph30 ]
  %13 = tail call ptr @str_id(ptr noundef nonnull %.025) #3
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.77, ptr noundef %13) #3
  %15 = getelementptr inbounds i8, ptr %.025, i64 24
  %16 = tail call ptr @str_addr(ptr noundef nonnull %15) #3
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.78, ptr noundef %16) #3
  %18 = getelementptr inbounds i8, ptr %.025, i64 184
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.79, i32 noundef %19) #3
  %21 = getelementptr inbounds i8, ptr %.025, i64 192
  %22 = add i32 %.02024, 1
  %.0 = load ptr, ptr %21, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.0, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph30
  %.020.lcssa = phi i32 [ 0, %.lr.ph30 ], [ %22, %.lr.ph ]
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.80, i32 noundef %.020.lcssa) #3
  %24 = getelementptr inbounds i8, ptr %.01828, i64 184
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = add i32 %.01927, 1
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !22

._crit_edge31:                                    ; preds = %._crit_edge, %1
  %.019.lcssa = phi i32 [ 0, %1 ], [ %26, %._crit_edge ]
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.81, i32 noundef %.019.lcssa) #3
  ret void
}

attributes #0 = { nofree nounwind "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 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, !13, i64 68}
!10 = !{!"gconf_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 57, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !6, i64 80, !7, i64 88, !7, i64 89, !11, i64 104, !11, i64 112, !11, i64 120, !7, i64 128, !7, i64 160}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 184}
!15 = !{!"node", !7, i64 0, !16, i64 24, !13, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !13, i64 184, !6, i64 192}
!16 = !{!"sockaddr_storage", !17, i64 0, !7, i64 2, !11, i64 120}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !6, i64 184}
!21 = !{!"bucket", !13, i64 0, !7, i64 4, !13, i64 24, !13, i64 28, !11, i64 32, !6, i64 40, !16, i64 48, !13, i64 176, !6, i64 184}
!22 = distinct !{!22, !19}


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