; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/IpSecDxe (IpSecMatchIpAddress)

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

%union.EFI_IP_ADDRESS = type { [4 x i32] }
%struct._EFI_IP_ADDRESS_INFO = type { %union.EFI_IP_ADDRESS, i8 }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IpSecValidAddressRange(i8 noundef zeroext, ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @ZeroMem(ptr noundef, i64 noundef) #2

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @IpSecExtractAddressRange(ptr noundef, i8 noundef zeroext, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @IpSecMatchIpAddress(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %union.EFI_IP_ADDRESS, align 4
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  store i8 %0, ptr %5, align 1, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !8
  store ptr %2, ptr %7, align 8, !tbaa !8
  store i32 %3, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  store i8 0, ptr %11, align 1, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !10
  br label %12

12:                                               ; preds = %60, %4
  %13 = load i32, ptr %10, align 4, !tbaa !10
  %14 = load i32, ptr %8, align 4, !tbaa !10
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %16, label %63

16:                                               ; preds = %12
  %17 = load i8, ptr %5, align 1, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !8
  %19 = load i32, ptr %10, align 4, !tbaa !10
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %18, i64 %20
  %22 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %7, align 8, !tbaa !8
  %24 = load i32, ptr %10, align 4, !tbaa !10
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 4, !tbaa !12
  %29 = call zeroext i8 @IpSecValidAddressRange(i8 noundef zeroext %17, ptr noundef %22, i8 noundef zeroext %28)
  %30 = icmp ne i8 %29, 0
  br i1 %30, label %31, label %49

31:                                               ; preds = %16
  %32 = call ptr @ZeroMem(ptr noundef %9, i64 noundef 16)
  %33 = load ptr, ptr %6, align 8, !tbaa !8
  %34 = load ptr, ptr %7, align 8, !tbaa !8
  %35 = load i32, ptr %10, align 4, !tbaa !10
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %37, i32 0, i32 1
  %39 = load i8, ptr %38, align 4, !tbaa !12
  call void @IpSecExtractAddressRange(ptr noundef %33, i8 noundef zeroext %39, ptr noundef %9)
  %40 = load ptr, ptr %7, align 8, !tbaa !8
  %41 = load i32, ptr %10, align 4, !tbaa !10
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %43, i32 0, i32 0
  %45 = call i64 @CompareMem(ptr noundef %9, ptr noundef %44, i64 noundef 16)
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %31
  store i8 1, ptr %11, align 1, !tbaa !5
  br label %63

48:                                               ; preds = %31
  br label %49

49:                                               ; preds = %48, %16
  %50 = load ptr, ptr %6, align 8, !tbaa !8
  %51 = load ptr, ptr %7, align 8, !tbaa !8
  %52 = load i32, ptr %10, align 4, !tbaa !10
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %54, i32 0, i32 0
  %56 = call i64 @CompareMem(ptr noundef %50, ptr noundef %55, i64 noundef 16)
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %49
  store i8 1, ptr %11, align 1, !tbaa !5
  br label %63

59:                                               ; preds = %49
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %10, align 4, !tbaa !10
  %62 = add i32 %61, 1
  store i32 %62, ptr %10, align 4, !tbaa !10
  br label %12, !llvm.loop !14

63:                                               ; preds = %58, %47, %12
  %64 = load i8, ptr %11, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  ret i8 %64
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"_EFI_IP_ADDRESS_INFO", !6, i64 0, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

%union.EFI_IP_ADDRESS = type { [4 x i32] }
%struct._EFI_IP_ADDRESS_INFO = type { %union.EFI_IP_ADDRESS, i8 }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IpSecValidAddressRange(i8 noundef zeroext, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @IpSecExtractAddressRange(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @IpSecMatchIpAddress(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %union.EFI_IP_ADDRESS, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  %.not22 = icmp eq i32 %3, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext i32 %3 to i64
  br label %.lr.ph

6:                                                ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph.preheader, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %2, i64 %indvars.iv
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load i8, ptr %8, align 4, !tbaa !7
  %10 = call zeroext i8 @IpSecValidAddressRange(i8 noundef zeroext %0, ptr noundef %7, i8 noundef zeroext %9)
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %16, label %11

11:                                               ; preds = %.lr.ph
  %12 = call ptr @ZeroMem(ptr noundef nonnull %5, i64 noundef 16) #3
  %13 = load i8, ptr %8, align 4, !tbaa !7
  call void @IpSecExtractAddressRange(ptr noundef %1, i8 noundef zeroext %13, ptr noundef nonnull %5)
  %14 = call i64 @CompareMem(ptr noundef nonnull %5, ptr noundef nonnull %7, i64 noundef 16) #3
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %._crit_edge, label %16

16:                                               ; preds = %11, %.lr.ph
  %17 = call i64 @CompareMem(ptr noundef %1, ptr noundef nonnull %7, i64 noundef 16) #3
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %._crit_edge, label %6

._crit_edge:                                      ; preds = %6, %11, %16, %4
  %.0 = phi i8 [ 0, %4 ], [ 1, %16 ], [ 1, %11 ], [ 0, %6 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 16}
!8 = !{!"_EFI_IP_ADDRESS_INFO", !9, i64 0, !9, i64 16}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass