; LLVM IR from RemHero/ReUp-DateBase-Raft :: layer3/ossSocket.ll (ZN10_ossSocket10setAddressEPKcj)

; 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._ossSocket = type { i32, i32, i32, %struct.sockaddr_in, %struct.sockaddr_in, i8, i32 }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.hostent = type { ptr, ptr, i32, i32, ptr }

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext) #1

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

declare ptr @gethostbyname(ptr noundef) #3

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10_ossSocket10setAddressEPKcj(ptr noundef nonnull align 4 dereferenceable(52) %0, ptr noundef %1, i32 noundef %2) #5 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %9 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 3
  call void @llvm.memset.p0.i64(ptr align 4 %9, i8 0, i64 16, i1 false)
  %10 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 4
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 16, i1 false)
  %11 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 2
  store i32 16, ptr %11, align 4, !tbaa !11
  %12 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 3
  %13 = getelementptr inbounds %struct.sockaddr_in, ptr %12, i32 0, i32 0
  store i16 2, ptr %13, align 4, !tbaa !17
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call ptr @gethostbyname(ptr noundef %14)
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %27

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.hostent, ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %21 = getelementptr inbounds ptr, ptr %20, i64 0
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 3
  %25 = getelementptr inbounds %struct.sockaddr_in, ptr %24, i32 0, i32 2
  %26 = getelementptr inbounds %struct.in_addr, ptr %25, i32 0, i32 0
  store i32 %23, ptr %26, align 4, !tbaa !20
  br label %33

27:                                               ; preds = %3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @inet_addr(ptr noundef %28) #6
  %30 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 3
  %31 = getelementptr inbounds %struct.sockaddr_in, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.in_addr, ptr %31, i32 0, i32 0
  store i32 %29, ptr %32, align 4, !tbaa !20
  br label %33

33:                                               ; preds = %27, %17
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = trunc i32 %34 to i16
  %36 = call noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext %35)
  %37 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 3
  %38 = getelementptr inbounds %struct.sockaddr_in, ptr %37, i32 0, i32 1
  store i16 %36, ptr %38, align 2, !tbaa !21
  %39 = getelementptr inbounds %class._ossSocket, ptr %8, i32 0, i32 1
  store i32 16, ptr %39, align 4, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { 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 #6 = { 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, !10, i64 8}
!12 = !{!"_ZTS10_ossSocket", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 12, !13, i64 28, !16, i64 44, !10, i64 48}
!13 = !{!"_ZTS11sockaddr_in", !14, i64 0, !14, i64 2, !15, i64 4, !7, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ZTS7in_addr", !10, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!12, !14, i64 12}
!18 = !{!19, !6, i64 24}
!19 = !{!"_ZTS7hostent", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!20 = !{!12, !10, i64 16}
!21 = !{!12, !14, i64 14}
!22 = !{!12, !10, i64 4}


; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext) local_unnamed_addr #1

declare ptr @gethostbyname(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10_ossSocket10setAddressEPKcj(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(52) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #4 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %4, i8 0, i64 32, i1 false)
  store i32 16, ptr %5, align 4, !tbaa !5
  store i16 2, ptr %4, align 4, !tbaa !14
  %6 = tail call ptr @gethostbyname(ptr noundef %1)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %12, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %6, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = load ptr, ptr %9, align 8, !tbaa !18
  %11 = load i32, ptr %10, align 4, !tbaa !19
  br label %14

12:                                               ; preds = %3
  %13 = tail call i32 @inet_addr(ptr noundef %1) #5
  br label %14

14:                                               ; preds = %12, %7
  %.sink = phi i32 [ %13, %12 ], [ %11, %7 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %.sink, ptr %15, align 4
  %16 = trunc i32 %2 to i16
  %17 = tail call noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext %16)
  %18 = getelementptr inbounds i8, ptr %0, i64 14
  store i16 %17, ptr %18, align 2, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 16, ptr %19, align 4, !tbaa !21
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { inlinehint 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 = { "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 = { 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 #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 8}
!6 = !{!"_ZTS10_ossSocket", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !10, i64 28, !13, i64 44, !7, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS11sockaddr_in", !11, i64 0, !11, i64 2, !12, i64 4, !8, i64 8}
!11 = !{!"short", !8, i64 0}
!12 = !{!"_ZTS7in_addr", !7, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !11, i64 12}
!15 = !{!16, !17, i64 24}
!16 = !{!"_ZTS7hostent", !17, i64 0, !17, i64 8, !7, i64 16, !7, i64 20, !17, i64 24}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!17, !17, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!6, !11, i64 14}
!21 = !{!6, !7, i64 4}


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