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

; 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 dso_local 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
declare dso_local i64 @NetGetIpClass(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @NetIp4IsUnicast(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = 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 8, ptr %6) #2
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = call i64 @NetGetIpClass(i32 noundef %8)
  store i64 %9, ptr %6, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp sge i64 %13, 4
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %2
  store i8 0, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %40

16:                                               ; preds = %12
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = shl i64 %20, 3
  %22 = getelementptr inbounds [33 x i32], ptr @gIp4AllMasks, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %19, %16
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = xor i32 %26, -1
  %28 = and i32 %25, %27
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = xor i32 %29, -1
  %31 = icmp eq i32 %28, %30
  br i1 %31, label %38, label %32

32:                                               ; preds = %24
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = xor i32 %34, -1
  %36 = and i32 %33, %35
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %32, %24
  store i8 0, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %40

39:                                               ; preds = %32
  store i8 1, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %40

40:                                               ; preds = %39, %38, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %41 = load i8, ptr %3, align 1
  ret i8 %41
}

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 = !{!"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 dso_local local_unnamed_addr global [33 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i64 @NetGetIpClass(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @NetIp4IsUnicast(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @NetGetIpClass(i32 noundef %0)
  %4 = icmp eq i32 %0, 0
  %5 = icmp sgt i64 %3, 3
  %or.cond = select i1 %4, i1 true, i1 %5
  br i1 %or.cond, label %17, label %6

6:                                                ; preds = %2
  %7 = icmp eq i32 %1, 0
  br i1 %7, label %8, label %12

8:                                                ; preds = %6
  %9 = shl i64 %3, 3
  %10 = getelementptr inbounds [33 x i32], ptr @gIp4AllMasks, i64 0, i64 %9
  %11 = load i32, ptr %10, align 16, !tbaa !5
  br label %12

12:                                               ; preds = %8, %6
  %.012 = phi i32 [ %11, %8 ], [ %1, %6 ]
  %13 = xor i32 %.012, -1
  %14 = and i32 %13, %0
  %15 = icmp ne i32 %14, %13
  %16 = icmp ne i32 %14, 0
  %or.cond17.not = and i1 %15, %16
  %spec.select = zext i1 %or.cond17.not to i8
  br label %17

17:                                               ; preds = %12, %2
  %.0 = phi i8 [ 0, %2 ], [ %spec.select, %12 ]
  ret i8 %.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, !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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass