; LLVM IR from yinqiwen/ardb :: src/common/util/network_helper.ll (ZN4ardb23get_remote_inet_addressEi)

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

%"class.ardb::SocketInetAddress" = type <{ %"class.ardb::Address", %"union.ardb::SocketInetAddress::MyAddrUnion", [2 x i8] }>
%"class.ardb::Address" = type { ptr }
%"union.ardb::SocketInetAddress::MyAddrUnion" = type { %struct.sockaddr, [94 x i8] }
%struct.sockaddr = type { i16, [14 x i8] }

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_un(ptr noundef nonnull align 8 dereferenceable(118), ptr noundef nonnull align 2 dereferenceable(110)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2Ev(ptr noundef nonnull align 8 dereferenceable(118)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_in(ptr noundef nonnull align 8 dereferenceable(118), ptr noundef nonnull align 4 dereferenceable(16)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2ERK12sockaddr_in6(ptr noundef nonnull align 8 dereferenceable(118), ptr noundef nonnull align 4 dereferenceable(28)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb23get_remote_inet_addressEi(ptr dead_on_unwind noalias writable sret(%"class.ardb::SocketInetAddress") align 8 %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [256 x i8], align 16
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %5) #5
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %12 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  store ptr %12, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 256, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = call i32 @getpeername(i32 noundef %13, ptr noundef %14, ptr noundef %7) #5
  %16 = icmp eq i32 0, %15
  br i1 %16, label %17, label %47

17:                                               ; preds = %2
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.sockaddr, ptr %18, i32 0, i32 0
  %20 = load i16, ptr %19, align 2, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %23, label %26

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %24, ptr %8, align 8, !tbaa !9
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_in(ptr noundef nonnull align 8 dereferenceable(118) %0, ptr noundef nonnull align 4 dereferenceable(16) %25)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %48

26:                                               ; preds = %17
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.sockaddr, ptr %27, i32 0, i32 0
  %29 = load i16, ptr %28, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = icmp eq i32 %30, 10
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %33, ptr %10, align 8, !tbaa !9
  %34 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_ZN4ardb17SocketInetAddressC2ERK12sockaddr_in6(ptr noundef nonnull align 8 dereferenceable(118) %0, ptr noundef nonnull align 4 dereferenceable(28) %34)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %48

35:                                               ; preds = %26
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.sockaddr, ptr %36, i32 0, i32 0
  %38 = load i16, ptr %37, align 2, !tbaa !11
  %39 = zext i16 %38 to i32
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %42, ptr %11, align 8, !tbaa !9
  %43 = load ptr, ptr %11, align 8, !tbaa !9
  call void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_un(ptr noundef nonnull align 8 dereferenceable(118) %0, ptr noundef nonnull align 2 dereferenceable(110) %43)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %48

44:                                               ; preds = %35
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46, %2
  call void @_ZN4ardb17SocketInetAddressC2Ev(ptr noundef nonnull align 8 dereferenceable(118) %0)
  store i32 1, ptr %9, align 4
  br label %48

48:                                               ; preds = %47, %41, %32, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 256, ptr %5) #5
  ret void
}

; Function Attrs: nounwind
declare i32 @getpeername(i32 noundef, ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress 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 = { mustprogress 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 "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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS8sockaddr", !13, i64 0, !7, i64 2}
!13 = !{!"short", !7, 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"

%"class.ardb::SocketInetAddress" = type <{ %"class.ardb::Address", %"union.ardb::SocketInetAddress::MyAddrUnion", [2 x i8] }>
%"class.ardb::Address" = type { ptr }
%"union.ardb::SocketInetAddress::MyAddrUnion" = type { %struct.sockaddr, [94 x i8] }
%struct.sockaddr = type { i16, [14 x i8] }

; 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: 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 nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_un(ptr noundef nonnull align 8 dereferenceable(118), ptr noundef nonnull align 2 dereferenceable(110)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2Ev(ptr noundef nonnull align 8 dereferenceable(118)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_in(ptr noundef nonnull align 8 dereferenceable(118), ptr noundef nonnull align 4 dereferenceable(16)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb17SocketInetAddressC2ERK12sockaddr_in6(ptr noundef nonnull align 8 dereferenceable(118), ptr noundef nonnull align 4 dereferenceable(28)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4ardb23get_remote_inet_addressEi(ptr dead_on_unwind noalias writable sret(%"class.ardb::SocketInetAddress") align 8 %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca [256 x i8], align 16
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %3, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 256, ptr %4, align 4, !tbaa !5
  %5 = call i32 @getpeername(i32 noundef %1, ptr noundef nonnull %3, ptr noundef nonnull %4) #4
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %12

7:                                                ; preds = %2
  %8 = load i16, ptr %3, align 16, !tbaa !9
  switch i16 %8, label %12 [
    i16 2, label %9
    i16 10, label %10
    i16 1, label %11
  ]

9:                                                ; preds = %7
  call void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_in(ptr noundef nonnull align 8 dereferenceable(118) %0, ptr noundef nonnull align 4 dereferenceable(16) %3)
  br label %13

10:                                               ; preds = %7
  call void @_ZN4ardb17SocketInetAddressC2ERK12sockaddr_in6(ptr noundef nonnull align 8 dereferenceable(118) %0, ptr noundef nonnull align 4 dereferenceable(28) %3)
  br label %13

11:                                               ; preds = %7
  call void @_ZN4ardb17SocketInetAddressC2ERK11sockaddr_un(ptr noundef nonnull align 8 dereferenceable(118) %0, ptr noundef nonnull align 2 dereferenceable(110) %3)
  br label %13

12:                                               ; preds = %7, %2
  call void @_ZN4ardb17SocketInetAddressC2Ev(ptr noundef nonnull align 8 dereferenceable(118) %0)
  br label %13

13:                                               ; preds = %12, %11, %10, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %3) #4
  ret void
}

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

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


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