; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (Ip4StationAddressValid)

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

@gIp4AllMasks = external global [33 x i32], align 16

; 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 zeroext i8 @Ip4StationAddressValid(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  %15 = zext i1 %14 to i32
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %63

17:                                               ; preds = %2
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = call i64 @NetGetMaskLength(i32 noundef %18)
  store i64 %19, ptr %7, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 33
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %63

22:                                               ; preds = %17
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = call i64 @NetGetIpClass(i32 noundef %23)
  store i64 %24, ptr %8, align 8, !tbaa !9
  %25 = icmp sgt i64 %24, 3
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %63

27:                                               ; preds = %22
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = and i32 %29, %30
  %32 = icmp eq i32 %28, %31
  br i1 %32, label %40, label %33

33:                                               ; preds = %27
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = xor i32 %36, -1
  %38 = or i32 %35, %37
  %39 = icmp eq i32 %34, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %33, %27
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %63

41:                                               ; preds = %33
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = shl i64 %43, 3
  %45 = icmp slt i64 %42, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %41
  %47 = load i64, ptr %7, align 8, !tbaa !9
  br label %51

48:                                               ; preds = %41
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = shl i64 %49, 3
  br label %51

51:                                               ; preds = %48, %46
  %52 = phi i64 [ %47, %46 ], [ %50, %48 ]
  %53 = getelementptr inbounds [33 x i32], ptr @gIp4AllMasks, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  store i32 %54, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = xor i32 %57, -1
  %59 = or i32 %56, %58
  %60 = icmp eq i32 %55, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %51
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %63

62:                                               ; preds = %51
  store i8 1, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %62, %61, %40, %26, %21, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %64 = load i8, ptr %3, align 1
  ret i8 %64
}

declare i64 @NetGetMaskLength(i32 noundef) #2

declare i64 @NetGetIpClass(i32 noundef) #2

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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !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"

@gIp4AllMasks = external local_unnamed_addr global [33 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @Ip4StationAddressValid(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = icmp eq i32 %0, 0
  br label %24

6:                                                ; preds = %2
  %7 = tail call i64 @NetGetMaskLength(i32 noundef %1) #3
  %8 = icmp eq i64 %7, 33
  br i1 %8, label %24, label %9

9:                                                ; preds = %6
  %10 = tail call i64 @NetGetIpClass(i32 noundef %0) #3
  %11 = icmp sgt i64 %10, 3
  br i1 %11, label %24, label %12

12:                                               ; preds = %9
  %13 = and i32 %1, %0
  %14 = icmp eq i32 %13, %0
  %15 = or i32 %1, %0
  %16 = icmp eq i32 %15, -1
  %or.cond = or i1 %14, %16
  br i1 %or.cond, label %24, label %17

17:                                               ; preds = %12
  %18 = shl i64 %10, 3
  %19 = tail call i64 @llvm.smin.i64(i64 %7, i64 %18)
  %20 = getelementptr inbounds [33 x i32], ptr @gIp4AllMasks, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = or i32 %21, %0
  %23 = icmp ne i32 %22, -1
  br label %24

24:                                               ; preds = %17, %12, %9, %6, %4
  %.0.shrunk = phi i1 [ %5, %4 ], [ false, %6 ], [ false, %9 ], [ false, %12 ], [ %23, %17 ]
  %.0 = zext i1 %.0.shrunk to i8
  ret i8 %.0
}

declare i64 @NetGetMaskLength(i32 noundef) local_unnamed_addr #1

declare i64 @NetGetIpClass(i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #2

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" }
attributes #1 = { "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 speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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