; 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_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.sockaddr_in6 = type { i16, i16, i32, %struct.in6_addr, i32 }
%struct.in6_addr = type { %union.anon }
%union.anon = type { [4 x i32] }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @to_addr(ptr noundef %0, ptr noundef %1, i64 noundef %2, i16 noundef zeroext %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i16 %3, ptr %8, align 2, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 128, i1 false)
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 4
  br i1 %13, label %14, label %25

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.sockaddr_in, ptr %16, i32 0, i32 0
  store i16 2, ptr %17, align 4, !tbaa !13
  %18 = load i16, ptr %8, align 2, !tbaa !11
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sockaddr_in, ptr %19, i32 0, i32 1
  store i16 %18, ptr %20, align 2, !tbaa !17
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sockaddr_in, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds %struct.in_addr, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %23, ptr align 1 %24, i64 4, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %25

25:                                               ; preds = %14, %4
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = icmp eq i64 %26, 16
  br i1 %27, label %28, label %39

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %29, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.sockaddr_in6, ptr %30, i32 0, i32 0
  store i16 10, ptr %31, align 4, !tbaa !18
  %32 = load i16, ptr %8, align 2, !tbaa !11
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sockaddr_in6, ptr %33, i32 0, i32 1
  store i16 %32, ptr %34, align 2, !tbaa !21
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.sockaddr_in6, ptr %35, i32 0, i32 3
  %37 = getelementptr inbounds %struct.in6_addr, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %37, ptr align 1 %38, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %39

39:                                               ; preds = %28, %25
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"sockaddr_in", !12, i64 0, !12, i64 2, !15, i64 4, !7, i64 8}
!15 = !{!"in_addr", !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!14, !12, i64 2}
!18 = !{!19, !12, i64 0}
!19 = !{!"sockaddr_in6", !12, i64 0, !12, i64 2, !16, i64 4, !20, i64 8, !16, i64 24}
!20 = !{!"in6_addr", !7, i64 0}
!21 = !{!19, !12, i64 2}


; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @to_addr(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, i16 noundef zeroext %3) local_unnamed_addr #2 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %0, i8 0, i64 128, i1 false)
  switch i64 %2, label %12 [
    i64 4, label %5
    i64 16, label %9
  ]

5:                                                ; preds = %4
  store i16 2, ptr %0, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %3, ptr %6, align 2, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %1, align 1
  store i32 %8, ptr %7, align 4
  br label %12

9:                                                ; preds = %4
  store i16 10, ptr %0, align 4, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %3, ptr %10, align 2, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %11, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false)
  br label %12

12:                                               ; preds = %5, %4, %9
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 0}
!6 = !{!"sockaddr_in", !7, i64 0, !7, i64 2, !10, i64 4, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"in_addr", !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 2}
!13 = !{!14, !7, i64 0}
!14 = !{!"sockaddr_in6", !7, i64 0, !7, i64 2, !11, i64 4, !15, i64 8, !11, i64 24}
!15 = !{!"in6_addr", !8, i64 0}
!16 = !{!14, !7, i64 2}


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