; LLVM IR from chensoft/libsocket :: src/ip/ip_address.ll (ZNK4chen10ip_address7maxhostEv)

; 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.chen::ip_address" = type { i8, %union.anon }
%union.anon = type { %"class.chen::ip_version6" }
%"class.chen::ip_version6" = type { %"class.chen::ip_version", %"struct.std::array", i32 }
%"class.chen::ip_version" = type { i8 }
%"struct.std::array" = type { [16 x i8] }
%"class.chen::ip_version4" = type { %"class.chen::ip_version", 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK4chen10ip_address7maxhostEv(ptr dead_on_unwind noalias writable sret(%"class.chen::ip_address") align 4 %0, ptr noundef nonnull align 4 dereferenceable(28) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca %"class.chen::ip_version4", align 4
  %5 = alloca %"class.chen::ip_version6", align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.chen::ip_address", ptr %6, i32 0, i32 0
  %8 = load i8, ptr %7, align 4, !tbaa !9
  switch i8 %8, label %14 [
    i8 2, label %9
    i8 10, label %12
  ]

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = getelementptr inbounds %"class.chen::ip_address", ptr %6, i32 0, i32 1
  %11 = call i64 @_ZNK4chen11ip_version47maxhostEv(ptr noundef nonnull align 4 dereferenceable(8) %10)
  store i64 %11, ptr %4, align 4
  call void @_ZN4chen10ip_addressC1ERKNS_11ip_version4E(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr noundef nonnull align 4 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %15

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #3
  %13 = getelementptr inbounds %"class.chen::ip_address", ptr %6, i32 0, i32 1
  call void @_ZNK4chen11ip_version67maxhostEv(ptr dead_on_unwind writable sret(%"class.chen::ip_version6") align 4 %5, ptr noundef nonnull align 4 dereferenceable(24) %13)
  call void @_ZN4chen10ip_addressC1ERKNS_11ip_version6E(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr noundef nonnull align 4 dereferenceable(24) %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #3
  br label %15

14:                                               ; preds = %2
  call void @_ZN4chen10ip_addressC1EDn(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr null)
  br label %15

15:                                               ; preds = %14, %12, %9
  ret void
}

declare i64 @_ZNK4chen11ip_version47maxhostEv(ptr noundef nonnull align 4 dereferenceable(8)) #2

declare void @_ZNK4chen11ip_version67maxhostEv(ptr dead_on_unwind writable sret(%"class.chen::ip_version6") align 4, ptr noundef nonnull align 4 dereferenceable(24)) #2

declare void @_ZN4chen10ip_addressC1EDn(ptr, ptr)

declare void @_ZN4chen10ip_addressC1ERKNS_11ip_version4E(ptr, ptr)

declare void @_ZN4chen10ip_addressC1ERKNS_11ip_version6E(ptr, ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN4chen10ip_addressE", !11, i64 0, !7, i64 4}
!11 = !{!"_ZTSN4chen10ip_address4TypeE", !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.chen::ip_address" = type { i8, %union.anon }
%union.anon = type { %"class.chen::ip_version6" }
%"class.chen::ip_version6" = type { %"class.chen::ip_version", %"struct.std::array", i32 }
%"class.chen::ip_version" = type { i8 }
%"struct.std::array" = type { [16 x i8] }
%"class.chen::ip_version4" = type { %"class.chen::ip_version", i32 }

; 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 uwtable
define dso_local void @_ZNK4chen10ip_address7maxhostEv(ptr dead_on_unwind noalias writable sret(%"class.chen::ip_address") align 4 %0, ptr noundef nonnull align 4 dereferenceable(28) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %"class.chen::ip_version4", align 8
  %4 = alloca %"class.chen::ip_version6", align 4
  %5 = load i8, ptr %1, align 4, !tbaa !5
  switch i8 %5, label %11 [
    i8 2, label %6
    i8 10, label %9
  ]

6:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = tail call i64 @_ZNK4chen11ip_version47maxhostEv(ptr noundef nonnull align 4 dereferenceable(8) %7)
  store i64 %8, ptr %3, align 8
  call void @_ZN4chen10ip_addressC1ERKNS_11ip_version4E(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %12

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  call void @_ZNK4chen11ip_version67maxhostEv(ptr dead_on_unwind nonnull writable sret(%"class.chen::ip_version6") align 4 %4, ptr noundef nonnull align 4 dereferenceable(24) %10)
  call void @_ZN4chen10ip_addressC1ERKNS_11ip_version6E(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr noundef nonnull align 4 dereferenceable(24) %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  br label %12

11:                                               ; preds = %2
  tail call void @_ZN4chen10ip_addressC1EDn(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr null)
  br label %12

12:                                               ; preds = %11, %9, %6
  ret void
}

declare i64 @_ZNK4chen11ip_version47maxhostEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2

declare void @_ZNK4chen11ip_version67maxhostEv(ptr dead_on_unwind writable sret(%"class.chen::ip_version6") align 4, ptr noundef nonnull align 4 dereferenceable(24)) local_unnamed_addr #2

declare void @_ZN4chen10ip_addressC1EDn(ptr, ptr) local_unnamed_addr

declare void @_ZN4chen10ip_addressC1ERKNS_11ip_version4E(ptr, ptr) local_unnamed_addr

declare void @_ZN4chen10ip_addressC1ERKNS_11ip_version6E(ptr, ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTSN4chen10ip_addressE", !7, i64 0, !8, i64 4}
!7 = !{!"_ZTSN4chen10ip_address4TypeE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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