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

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

@str_addr.addrbuf = external hidden global [54 x i8], align 16
@.str.8 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 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: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @str_addr(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [46 x i8], align 16
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 46, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.sockaddr_storage, ptr %8, i32 0, i32 0
  %10 = load i16, ptr %9, align 8, !tbaa !9
  %11 = zext i16 %10 to i32
  switch i32 %11, label %30 [
    i32 10, label %12
    i32 2, label %21
  ]

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.sockaddr_in6, ptr %13, i32 0, i32 1
  %15 = load i16, ptr %14, align 2, !tbaa !13
  %16 = zext i16 %15 to i32
  store i32 %16, ptr %6, align 4, !tbaa !17
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sockaddr_in6, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds [46 x i8], ptr %4, i64 0, i64 0
  %20 = call ptr @inet_ntop(i32 noundef 10, ptr noundef %18, ptr noundef %19, i32 noundef 46) #4
  store ptr @.str.8, ptr %5, align 8, !tbaa !5
  br label %31

21:                                               ; preds = %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.sockaddr_in, ptr %22, i32 0, i32 1
  %24 = load i16, ptr %23, align 2, !tbaa !18
  %25 = zext i16 %24 to i32
  store i32 %25, ptr %6, align 4, !tbaa !17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.sockaddr_in, ptr %26, i32 0, i32 2
  %28 = getelementptr inbounds [46 x i8], ptr %4, i64 0, i64 0
  %29 = call ptr @inet_ntop(i32 noundef 2, ptr noundef %27, ptr noundef %28, i32 noundef 46) #4
  store ptr @.str.9, ptr %5, align 8, !tbaa !5
  br label %31

30:                                               ; preds = %1
  store ptr @.str.10, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %39

31:                                               ; preds = %21, %12
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds [46 x i8], ptr %4, i64 0, i64 0
  %34 = load i32, ptr %6, align 4, !tbaa !17
  %35 = trunc i32 %34 to i16
  %36 = call zeroext i16 @__bswap_16(i16 noundef zeroext %35)
  %37 = zext i16 %36 to i32
  %38 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @str_addr.addrbuf, ptr noundef %32, ptr noundef %33, i32 noundef %37) #4
  store ptr @str_addr.addrbuf, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %39

39:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 46, ptr %4) #4
  %40 = load ptr, ptr %2, align 8
  ret ptr %40
}

; Function Attrs: nounwind
declare ptr @inet_ntop(i32 noundef, ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

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


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

@str_addr.addrbuf = external hidden global [54 x i8], align 16
@.str.8 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1

; 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: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @str_addr(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [46 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 46, ptr nonnull %2) #5
  %3 = load i16, ptr %0, align 8, !tbaa !5
  switch i16 %3, label %13 [
    i16 10, label %5
    i16 2, label %4
  ]

4:                                                ; preds = %1
  br label %5

5:                                                ; preds = %1, %4
  %.sink10 = phi i64 [ 4, %4 ], [ 8, %1 ]
  %.sink = phi i32 [ 2, %4 ], [ 10, %1 ]
  %.07 = phi ptr [ @.str.9, %4 ], [ @.str.8, %1 ]
  %6 = getelementptr inbounds i8, ptr %0, i64 2
  %7 = load i16, ptr %6, align 2, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 %.sink10
  %9 = call ptr @inet_ntop(i32 noundef %.sink, ptr noundef nonnull %8, ptr noundef nonnull %2, i32 noundef 46) #5
  %10 = call zeroext i16 @__bswap_16(i16 noundef zeroext %7)
  %11 = zext i16 %10 to i32
  %12 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @str_addr.addrbuf, ptr noundef nonnull dereferenceable(1) %.07, ptr noundef nonnull %2, i32 noundef %11) #5
  br label %13

13:                                               ; preds = %1, %5
  %.08 = phi ptr [ @str_addr.addrbuf, %5 ], [ @.str.10, %1 ]
  call void @llvm.lifetime.end.p0(i64 46, ptr nonnull %2) #5
  ret ptr %.08
}

; Function Attrs: nounwind
declare ptr @inet_ntop(i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 "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 = { 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 #5 = { 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, !7, i64 0}
!6 = !{!"sockaddr_storage", !7, i64 0, !8, i64 2, !10, i64 120}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!7, !7, i64 0}


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