; LLVM IR from shixiongfei/nio4c :: nio4c_socket (nio_ipstr)

; 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.niosockaddr_s = type { %struct.sockaddr_storage }
%struct.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.nioipstr_s = type { [46 x i8], i16 }
%struct.sockaddr_in6 = type { i16, i16, i32, %struct.in6_addr, i32 }
%struct.in6_addr = type { %union.anon.2 }
%union.anon.2 = type { [4 x 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: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @nio_ipstr(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.niosockaddr_s, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds %struct.sockaddr_storage, ptr %9, i32 0, i32 0
  %11 = load i16, ptr %10, align 8, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = icmp eq i32 2, %12
  br i1 %13, label %14, label %29

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.niosockaddr_s, ptr %15, i32 0, i32 0
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sockaddr_in, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.nioipstr_s, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds [46 x i8], ptr %20, i64 0, i64 0
  %22 = call ptr @nio_inetntop(i32 noundef 2, ptr noundef %18, ptr noundef %21, i32 noundef 46)
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.sockaddr_in, ptr %23, i32 0, i32 1
  %25 = load i16, ptr %24, align 2, !tbaa !14
  %26 = call zeroext i16 @__bswap_16(i16 noundef zeroext %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.nioipstr_s, ptr %27, i32 0, i32 1
  store i16 %26, ptr %28, align 2, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %53

29:                                               ; preds = %2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.niosockaddr_s, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.sockaddr_storage, ptr %31, i32 0, i32 0
  %33 = load i16, ptr %32, align 8, !tbaa !9
  %34 = zext i16 %33 to i32
  %35 = icmp eq i32 10, %34
  br i1 %35, label %36, label %51

36:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.niosockaddr_s, ptr %37, i32 0, i32 0
  store ptr %38, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.sockaddr_in6, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.nioipstr_s, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [46 x i8], ptr %42, i64 0, i64 0
  %44 = call ptr @nio_inetntop(i32 noundef 10, ptr noundef %40, ptr noundef %43, i32 noundef 46)
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.sockaddr_in6, ptr %45, i32 0, i32 1
  %47 = load i16, ptr %46, align 2, !tbaa !20
  %48 = call zeroext i16 @__bswap_16(i16 noundef zeroext %47)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.nioipstr_s, ptr %49, i32 0, i32 1
  store i16 %48, ptr %50, align 2, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %52

51:                                               ; preds = %29
  store i32 -1, ptr %3, align 4
  br label %54

52:                                               ; preds = %36
  br label %53

53:                                               ; preds = %52, %14
  store i32 0, ptr %3, align 4
  br label %54

54:                                               ; preds = %53, %51
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

; Function Attrs: nounwind uwtable
declare hidden ptr @nio_inetntop(i32 noundef, ptr noundef, ptr noundef, i32 noundef) #2

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 }

!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, !12, i64 0}
!10 = !{!"niosockaddr_s", !11, i64 0}
!11 = !{!"sockaddr_storage", !12, i64 0, !7, i64 2, !13, i64 120}
!12 = !{!"short", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !12, i64 2}
!15 = !{!"sockaddr_in", !12, i64 0, !12, i64 2, !16, i64 4, !7, i64 8}
!16 = !{!"in_addr", !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!19, !12, i64 46}
!19 = !{!"nioipstr_s", !7, i64 0, !12, i64 46}
!20 = !{!21, !12, i64 2}
!21 = !{!"sockaddr_in6", !12, i64 0, !12, i64 2, !17, i64 4, !22, i64 8, !17, i64 24}
!22 = !{!"in6_addr", !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"

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @nio_ipstr(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load i16, ptr %1, align 8, !tbaa !5
  switch i16 %3, label %11 [
    i16 2, label %.sink.split
    i16 10, label %4
  ]

4:                                                ; preds = %2
  br label %.sink.split

.sink.split:                                      ; preds = %2, %4
  %.sink16 = phi i64 [ 8, %4 ], [ 4, %2 ]
  %.sink = phi i32 [ 10, %4 ], [ 2, %2 ]
  %5 = getelementptr inbounds i8, ptr %1, i64 %.sink16
  %6 = tail call ptr @nio_inetntop(i32 noundef %.sink, ptr noundef nonnull %5, ptr noundef %0, i32 noundef 46)
  %7 = getelementptr inbounds i8, ptr %1, i64 2
  %8 = load i16, ptr %7, align 2, !tbaa !12
  %9 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 46
  store i16 %9, ptr %10, align 2, !tbaa !13
  br label %11

11:                                               ; preds = %.sink.split, %2
  %.0 = phi i32 [ -1, %2 ], [ 0, %.sink.split ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @nio_inetntop(i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { 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" }

!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, !8, i64 0}
!6 = !{!"niosockaddr_s", !7, i64 0}
!7 = !{!"sockaddr_storage", !8, i64 0, !9, i64 2, !11, i64 120}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !8, i64 46}
!14 = !{!"nioipstr_s", !9, i64 0, !8, i64 46}


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