; 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.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.dht_addr4_t = type { [4 x i8], i16 }
%struct.dht_addr6_t = type { [16 x i8], i16 }

; 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 dso_local void @to_addr(ptr noundef, ptr noundef, i64 noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @dht_callback_func(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.sockaddr_storage, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %14) #3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call ptr @searches_find_by_id(ptr noundef %18)
  store ptr %19, ptr %11, align 8, !tbaa !5
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %5
  store i32 1, ptr %15, align 4
  br label %75

23:                                               ; preds = %5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %24, label %74 [
    i32 1, label %25
    i32 2, label %48
    i32 3, label %71
    i32 4, label %71
    i32 5, label %72
  ]

25:                                               ; preds = %23
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %26, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %44, %25
  %28 = load i64, ptr %16, align 8, !tbaa !11
  %29 = load i64, ptr %10, align 8, !tbaa !11
  %30 = udiv i64 %29, 6
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 3, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %47

33:                                               ; preds = %27
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = load i64, ptr %16, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.dht_addr4_t, ptr %34, i64 %35
  %37 = getelementptr inbounds %struct.dht_addr4_t, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = load i64, ptr %16, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.dht_addr4_t, ptr %38, i64 %39
  %41 = getelementptr inbounds %struct.dht_addr4_t, ptr %40, i32 0, i32 1
  %42 = load i16, ptr %41, align 2, !tbaa !13
  call void @to_addr(ptr noundef %14, ptr noundef %37, i64 noundef 4, i16 noundef zeroext %42)
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  call void @searches_add_addr(ptr noundef %43, ptr noundef %14)
  br label %44

44:                                               ; preds = %33
  %45 = load i64, ptr %16, align 8, !tbaa !11
  %46 = add i64 %45, 1
  store i64 %46, ptr %16, align 8, !tbaa !11
  br label %27, !llvm.loop !16

47:                                               ; preds = %32
  br label %74

48:                                               ; preds = %23
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %49, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %67, %48
  %51 = load i64, ptr %17, align 8, !tbaa !11
  %52 = load i64, ptr %10, align 8, !tbaa !11
  %53 = udiv i64 %52, 18
  %54 = icmp ult i64 %51, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %50
  store i32 6, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %70

56:                                               ; preds = %50
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = load i64, ptr %17, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.dht_addr6_t, ptr %57, i64 %58
  %60 = getelementptr inbounds %struct.dht_addr6_t, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = load i64, ptr %17, align 8, !tbaa !11
  %63 = getelementptr inbounds %struct.dht_addr6_t, ptr %61, i64 %62
  %64 = getelementptr inbounds %struct.dht_addr6_t, ptr %63, i32 0, i32 1
  %65 = load i16, ptr %64, align 2, !tbaa !18
  call void @to_addr(ptr noundef %14, ptr noundef %60, i64 noundef 16, i16 noundef zeroext %65)
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  call void @searches_add_addr(ptr noundef %66, ptr noundef %14)
  br label %67

67:                                               ; preds = %56
  %68 = load i64, ptr %17, align 8, !tbaa !11
  %69 = add i64 %68, 1
  store i64 %69, ptr %17, align 8, !tbaa !11
  br label %50, !llvm.loop !20

70:                                               ; preds = %55
  br label %74

71:                                               ; preds = %23, %23
  br label %74

72:                                               ; preds = %23
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  call void @searches_remove_by_id(ptr noundef %73)
  br label %74

74:                                               ; preds = %72, %71, %70, %47, %23
  store i32 0, ptr %15, align 4
  br label %75

75:                                               ; preds = %74, %22
  call void @llvm.lifetime.end.p0(i64 128, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %76 = load i32, ptr %15, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

declare ptr @searches_find_by_id(ptr noundef) #2

declare void @searches_add_addr(ptr noundef, ptr noundef) #2

declare void @searches_remove_by_id(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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !15, i64 4}
!14 = !{!"", !7, i64 0, !15, i64 4}
!15 = !{!"short", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !15, i64 16}
!19 = !{!"", !7, i64 0, !15, i64 16}
!20 = distinct !{!20, !17}


; 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.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.dht_addr4_t = type { [4 x i8], i16 }
%struct.dht_addr6_t = type { [16 x i8], i16 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @to_addr(ptr noundef, ptr noundef, i64 noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dht_callback_func(ptr nocapture noundef readnone %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %struct.sockaddr_storage, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #3
  %7 = tail call ptr @searches_find_by_id(ptr noundef %2) #3
  %8 = icmp eq ptr %7, null
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %5
  switch i32 %1, label %.loopexit [
    i32 1, label %.preheader
    i32 2, label %.preheader23
    i32 5, label %20
  ]

.preheader23:                                     ; preds = %9
  %10 = udiv i64 %4, 18
  %.not = icmp ult i64 %4, 18
  br i1 %.not, label %.loopexit, label %.lr.ph

.preheader:                                       ; preds = %9
  %11 = udiv i64 %4, 6
  %.not28 = icmp ult i64 %4, 6
  br i1 %.not28, label %.loopexit, label %.lr.ph27

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %.02126 = phi i64 [ %15, %.lr.ph27 ], [ 0, %.preheader ]
  %12 = getelementptr inbounds %struct.dht_addr4_t, ptr %3, i64 %.02126
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %14 = load i16, ptr %13, align 2, !tbaa !5
  call void @to_addr(ptr noundef nonnull %6, ptr noundef %12, i64 noundef 4, i16 noundef zeroext %14)
  call void @searches_add_addr(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %15 = add nuw nsw i64 %.02126, 1
  %exitcond30.not = icmp eq i64 %15, %11
  br i1 %exitcond30.not, label %.loopexit, label %.lr.ph27, !llvm.loop !10

.lr.ph:                                           ; preds = %.preheader23, %.lr.ph
  %.025 = phi i64 [ %19, %.lr.ph ], [ 0, %.preheader23 ]
  %16 = getelementptr inbounds %struct.dht_addr6_t, ptr %3, i64 %.025
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load i16, ptr %17, align 2, !tbaa !12
  call void @to_addr(ptr noundef nonnull %6, ptr noundef %16, i64 noundef 16, i16 noundef zeroext %18)
  call void @searches_add_addr(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %19 = add nuw nsw i64 %.025, 1
  %exitcond.not = icmp eq i64 %19, %10
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

20:                                               ; preds = %9
  tail call void @searches_remove_by_id(ptr noundef %2) #3
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph27, %.preheader23, %.preheader, %9, %20, %5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #3
  ret void
}

declare ptr @searches_find_by_id(ptr noundef) local_unnamed_addr #2

declare void @searches_add_addr(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @searches_remove_by_id(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !9, i64 4}
!6 = !{!"", !7, i64 0, !9, i64 4}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !9, i64 16}
!13 = !{!"", !7, i64 0, !9, i64 16}
!14 = distinct !{!14, !11}


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