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

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

; 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 i32 @__bswap_32(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @nio_isnat(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.niosockaddr_s, ptr %6, i32 0, i32 0
  store ptr %7, ptr %4, align 8, !tbaa !5
  %8 = call i32 @__bswap_32(i32 noundef 167772160)
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.sockaddr_in, ptr %9, i32 0, i32 2
  %11 = getelementptr inbounds %struct.in_addr, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = call i32 @ipv4_submask(i32 noundef 8)
  %14 = and i32 %12, %13
  %15 = icmp eq i32 %8, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

17:                                               ; preds = %1
  %18 = call i32 @__bswap_32(i32 noundef -1408237568)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sockaddr_in, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.in_addr, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = call i32 @ipv4_submask(i32 noundef 12)
  %24 = and i32 %22, %23
  %25 = icmp eq i32 %18, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %17
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

27:                                               ; preds = %17
  %28 = call i32 @__bswap_32(i32 noundef -1062731776)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.sockaddr_in, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds %struct.in_addr, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = call i32 @ipv4_submask(i32 noundef 16)
  %34 = and i32 %32, %33
  %35 = icmp eq i32 %28, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %27
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

37:                                               ; preds = %27
  %38 = call i32 @__bswap_32(i32 noundef -1442971648)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.sockaddr_in, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.in_addr, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = call i32 @ipv4_submask(i32 noundef 16)
  %44 = and i32 %42, %43
  %45 = icmp eq i32 %38, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %37
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

47:                                               ; preds = %37
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

48:                                               ; preds = %47, %46, %36, %26, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %49 = load i32, ptr %2, align 4
  ret i32 %49
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ipv4_submask(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, !13, i64 4}
!10 = !{!"sockaddr_in", !11, i64 0, !11, i64 2, !12, i64 4, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!"in_addr", !13, i64 0}
!13 = !{!"int", !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 i32 @__bswap_32(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nio_isnat(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call i32 @__bswap_32(i32 noundef 167772160)
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = tail call i32 @ipv4_submask(i32 noundef 8)
  %6 = and i32 %5, %4
  %7 = icmp eq i32 %2, %6
  br i1 %7, label %26, label %8

8:                                                ; preds = %1
  %9 = tail call i32 @__bswap_32(i32 noundef -1408237568)
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = tail call i32 @ipv4_submask(i32 noundef 12)
  %12 = and i32 %11, %10
  %13 = icmp eq i32 %9, %12
  br i1 %13, label %26, label %14

14:                                               ; preds = %8
  %15 = tail call i32 @__bswap_32(i32 noundef -1062731776)
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = tail call i32 @ipv4_submask(i32 noundef 16)
  %18 = and i32 %17, %16
  %19 = icmp eq i32 %15, %18
  br i1 %19, label %26, label %20

20:                                               ; preds = %14
  %21 = tail call i32 @__bswap_32(i32 noundef -1442971648)
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = tail call i32 @ipv4_submask(i32 noundef 16)
  %24 = and i32 %23, %22
  %25 = icmp eq i32 %21, %24
  %. = zext i1 %25 to i32
  br label %26

26:                                               ; preds = %20, %14, %8, %1
  %.0 = phi i32 [ 1, %1 ], [ 1, %8 ], [ 1, %14 ], [ %., %20 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ipv4_submask(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, !11, i64 4}
!6 = !{!"sockaddr_in", !7, i64 0, !7, i64 2, !10, i64 4, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"in_addr", !11, i64 0}
!11 = !{!"int", !8, i64 0}


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