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

; 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.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: nounwind uwtable
define dso_local i32 @nio_sockaddrequal(ptr noundef %0, ptr noundef %1) #1 {
  %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
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.niosockaddr_s, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct.sockaddr_storage, ptr %11, i32 0, i32 0
  %13 = load i16, ptr %12, align 8, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.niosockaddr_s, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.sockaddr_storage, ptr %16, i32 0, i32 0
  %18 = load i16, ptr %17, align 8, !tbaa !9
  %19 = zext i16 %18 to i32
  %20 = icmp ne i32 %14, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %80

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.niosockaddr_s, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.sockaddr_storage, ptr %24, i32 0, i32 0
  %26 = load i16, ptr %25, align 8, !tbaa !9
  %27 = zext i16 %26 to i32
  switch i32 %27, label %79 [
    i32 2, label %28
    i32 10, label %55
  ]

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.niosockaddr_s, ptr %29, i32 0, i32 0
  store ptr %30, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.niosockaddr_s, ptr %31, i32 0, i32 0
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sockaddr_in, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds %struct.in_addr, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.sockaddr_in, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds %struct.in_addr, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = icmp eq i32 %36, %40
  br i1 %41, label %42, label %52

42:                                               ; preds = %28
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.sockaddr_in, ptr %43, i32 0, i32 1
  %45 = load i16, ptr %44, align 2, !tbaa !18
  %46 = zext i16 %45 to i32
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.sockaddr_in, ptr %47, i32 0, i32 1
  %49 = load i16, ptr %48, align 2, !tbaa !18
  %50 = zext i16 %49 to i32
  %51 = icmp eq i32 %46, %50
  br label %52

52:                                               ; preds = %42, %28
  %53 = phi i1 [ false, %28 ], [ %51, %42 ]
  %54 = zext i1 %53 to i32
  store i32 %54, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %80

55:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.niosockaddr_s, ptr %56, i32 0, i32 0
  store ptr %57, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.niosockaddr_s, ptr %58, i32 0, i32 0
  store ptr %59, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.sockaddr_in6, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sockaddr_in6, ptr %62, i32 0, i32 3
  %64 = call i32 @in6_equal(ptr noundef %61, ptr noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %76

66:                                               ; preds = %55
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.sockaddr_in6, ptr %67, i32 0, i32 1
  %69 = load i16, ptr %68, align 2, !tbaa !19
  %70 = zext i16 %69 to i32
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.sockaddr_in6, ptr %71, i32 0, i32 1
  %73 = load i16, ptr %72, align 2, !tbaa !19
  %74 = zext i16 %73 to i32
  %75 = icmp eq i32 %70, %74
  br label %76

76:                                               ; preds = %66, %55
  %77 = phi i1 [ false, %55 ], [ %75, %66 ]
  %78 = zext i1 %77 to i32
  store i32 %78, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %80

79:                                               ; preds = %22
  store i32 0, ptr %3, align 4
  br label %80

80:                                               ; preds = %79, %76, %52, %21
  %81 = load i32, ptr %3, align 4
  ret i32 %81
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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, !17, i64 4}
!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 = !{!15, !12, i64 2}
!19 = !{!20, !12, i64 2}
!20 = !{!"sockaddr_in6", !12, i64 0, !12, i64 2, !17, i64 4, !21, i64 8, !17, i64 24}
!21 = !{!"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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nio_sockaddrequal(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i16, ptr %0, align 8, !tbaa !5
  %4 = load i16, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i16 %3, %4
  br i1 %.not, label %5, label %22

5:                                                ; preds = %2
  switch i16 %3, label %22 [
    i16 2, label %6
    i16 10, label %12
  ]

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %1, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = icmp eq i32 %8, %10
  br i1 %11, label %.sink.split, label %22

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = tail call i32 @in6_equal(ptr noundef nonnull %13, ptr noundef nonnull %14)
  %.not16 = icmp eq i32 %15, 0
  br i1 %.not16, label %22, label %.sink.split

.sink.split:                                      ; preds = %12, %6
  %16 = getelementptr inbounds i8, ptr %0, i64 2
  %17 = load i16, ptr %16, align 2, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %1, i64 2
  %19 = load i16, ptr %18, align 2, !tbaa !16
  %20 = icmp eq i16 %17, %19
  %21 = zext i1 %20 to i32
  br label %22

22:                                               ; preds = %.sink.split, %5, %12, %6, %2
  %.0.shrunk = phi i32 [ 0, %2 ], [ 0, %6 ], [ 0, %12 ], [ 0, %5 ], [ %21, %.sink.split ]
  ret i32 %.0.shrunk
}

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

attributes #0 = { 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 = !{!13, !15, i64 4}
!13 = !{!"sockaddr_in", !8, i64 0, !8, i64 2, !14, i64 4, !9, i64 8}
!14 = !{!"in_addr", !15, i64 0}
!15 = !{!"int", !9, i64 0}
!16 = !{!8, !8, i64 0}


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