; LLVM IR from yinqiwen/ardb :: src/common/util/datagram_packet.ll (ZN4ardb14DatagramPacketC2Ej)

; 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::DatagramPacket" = type <{ %"class.ardb::SocketInetAddress", ptr, i8, [7 x i8] }>
%"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] }

@_ZTISt9bad_alloc = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb14DatagramPacketC2Ej(ptr noundef nonnull align 8 dereferenceable(129) %0, i32 noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"class.ardb::DatagramPacket", ptr %8, i32 0, i32 0
  call void @_ZN4ardb17SocketInetAddressC2Ev(ptr noundef nonnull align 8 dereferenceable(118) %9)
  %10 = getelementptr inbounds %"class.ardb::DatagramPacket", ptr %8, i32 0, i32 1
  store ptr null, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.ardb::DatagramPacket", ptr %8, i32 0, i32 2
  store i8 1, ptr %11, align 8, !tbaa !16
  br label %12

12:                                               ; preds = %2
  %13 = invoke noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #7
          to label %14 unwind label %19

14:                                               ; preds = %12
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  invoke void @_ZN4ardb6BufferC2Em(ptr noundef nonnull align 8 dereferenceable(33) %13, i64 noundef %16)
          to label %17 unwind label %23

17:                                               ; preds = %14
  %18 = getelementptr inbounds %"class.ardb::DatagramPacket", ptr %8, i32 0, i32 1
  store ptr %13, ptr %18, align 8, !tbaa !11
  br label %36

19:                                               ; preds = %12
  %20 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTISt9bad_alloc
  %21 = extractvalue { ptr, i32 } %20, 0
  store ptr %21, ptr %5, align 8
  %22 = extractvalue { ptr, i32 } %20, 1
  store i32 %22, ptr %6, align 4
  br label %27

23:                                               ; preds = %14
  %24 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTISt9bad_alloc
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %5, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %13, i64 noundef 40) #8
  br label %27

27:                                               ; preds = %23, %19
  %28 = load i32, ptr %6, align 4
  %29 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTISt9bad_alloc) #9
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %43

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #9
  %32 = load ptr, ptr %5, align 8
  %33 = call ptr @__cxa_begin_catch(ptr %32) #9
  store ptr %33, ptr %7, align 8
  %34 = getelementptr inbounds %"class.ardb::DatagramPacket", ptr %8, i32 0, i32 1
  store ptr null, ptr %34, align 8, !tbaa !11
  invoke void @__cxa_end_catch()
          to label %35 unwind label %39

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #9
  br label %36

36:                                               ; preds = %35, %17
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  ret void

39:                                               ; preds = %31
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %5, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #9
  br label %43

43:                                               ; preds = %39, %27
  call void @_ZN4ardb7AddressD2Ev(ptr noundef nonnull align 8 dereferenceable(118) %9) #9
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %5, align 8
  %46 = load i32, ptr %6, align 4
  %47 = insertvalue { ptr, i32 } poison, ptr %45, 0
  %48 = insertvalue { ptr, i32 } %47, i32 %46, 1
  resume { ptr, i32 } %48
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4ardb6BufferC2Em(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) unnamed_addr #3 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; Function Attrs: nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #5

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

declare ptr @__cxa_begin_catch(ptr)

declare void @__cxa_end_catch()

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

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

attributes #0 = { 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 #1 = { 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 #2 = { nobuiltin allocsize(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 = { inlinehint 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 = { nobuiltin 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 memory(none) }
attributes #6 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin nounwind }
attributes #9 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 120}
!12 = !{!"_ZTSN4ardb14DatagramPacketE", !13, i64 0, !6, i64 120, !15, i64 128}
!13 = !{!"_ZTSN4ardb17SocketInetAddressE", !14, i64 0, !7, i64 8}
!14 = !{!"_ZTSN4ardb7AddressE"}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !15, i64 128}


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

@_ZTISt9bad_alloc = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb14DatagramPacketC2Ej(ptr noundef nonnull align 8 dereferenceable(129) %0, i32 noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN4ardb17SocketInetAddressC2Ev(ptr noundef nonnull align 8 dereferenceable(118) %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  store i8 1, ptr %4, align 8, !tbaa !13
  %5 = invoke noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #6
          to label %6 unwind label %9

6:                                                ; preds = %2
  %7 = zext i32 %1 to i64
  invoke void @_ZN4ardb6BufferC2Em(ptr noundef nonnull align 8 dereferenceable(33) %5, i64 noundef %7)
          to label %8 unwind label %11

8:                                                ; preds = %6
  store ptr %5, ptr %3, align 8, !tbaa !5
  br label %18

9:                                                ; preds = %2
  %10 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTISt9bad_alloc
  br label %13

11:                                               ; preds = %6
  %12 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTISt9bad_alloc
  tail call void @_ZdlPvm(ptr noundef nonnull %5, i64 noundef 40) #7
  br label %13

13:                                               ; preds = %11, %9
  %.pn = phi { ptr, i32 } [ %12, %11 ], [ %10, %9 ]
  %.05 = extractvalue { ptr, i32 } %.pn, 1
  %14 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTISt9bad_alloc) #8
  %15 = icmp eq i32 %.05, %14
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %.0 = extractvalue { ptr, i32 } %.pn, 0
  %17 = tail call ptr @__cxa_begin_catch(ptr %.0) #8
  store ptr null, ptr %3, align 8, !tbaa !5
  invoke void @__cxa_end_catch()
          to label %18 unwind label %19

18:                                               ; preds = %16, %8
  ret void

19:                                               ; preds = %16
  %20 = landingpad { ptr, i32 }
          cleanup
  br label %21

21:                                               ; preds = %19, %13
  %.merged = phi { ptr, i32 } [ %20, %19 ], [ %.pn, %13 ]
  tail call void @_ZN4ardb7AddressD2Ev(ptr noundef nonnull align 8 dereferenceable(118) %0) #8
  resume { ptr, i32 } %.merged
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4ardb6BufferC2Em(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) unnamed_addr #3 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #5

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

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

attributes #0 = { 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 #1 = { 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 #2 = { nobuiltin allocsize(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 = { inlinehint 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 = { nobuiltin 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 = { nofree nosync nounwind memory(none) }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin nounwind }
attributes #8 = { 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, !11, i64 120}
!6 = !{!"_ZTSN4ardb14DatagramPacketE", !7, i64 0, !11, i64 120, !12, i64 128}
!7 = !{!"_ZTSN4ardb17SocketInetAddressE", !8, i64 0, !9, i64 8}
!8 = !{!"_ZTSN4ardb7AddressE"}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!6, !12, i64 128}


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