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

; 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._IP4_ROUTE_TABLE = type { i64, i32, [33 x %struct._LIST_ENTRY], ptr, %struct.IP4_ROUTE_CACHE }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.IP4_ROUTE_CACHE = type { [31 x %struct._LIST_ENTRY] }
%struct.IP4_ROUTE_ENTRY = type { %struct._LIST_ENTRY, i64, i32, i32, i32, 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 ptr @Ip4FindRouteEntry(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  store i64 32, ptr %9, align 8, !tbaa !11
  br label %11

11:                                               ; preds = %68, %2
  %12 = load i64, ptr %9, align 8, !tbaa !11
  %13 = icmp sge i64 %12, 0
  br i1 %13, label %14, label %71

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %8, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %63, %14
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %67

19:                                               ; preds = %16
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %20, i32 0, i32 2
  %22 = load i64, ptr %9, align 8, !tbaa !11
  %23 = getelementptr inbounds [33 x %struct._LIST_ENTRY], ptr %21, i64 0, i64 %22
  %24 = getelementptr inbounds %struct._LIST_ENTRY, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  store ptr %25, ptr %6, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %58, %19
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %9, align 8, !tbaa !11
  %31 = getelementptr inbounds [33 x %struct._LIST_ENTRY], ptr %29, i64 0, i64 %30
  %32 = icmp ne ptr %27, %31
  br i1 %32, label %33, label %62

33:                                               ; preds = %26
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = sub i64 %35, 0
  %37 = inttoptr i64 %36 to ptr
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 4, !tbaa !17
  %44 = and i32 %40, %43
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 4, !tbaa !17
  %49 = and i32 %45, %48
  %50 = icmp eq i32 %44, %49
  br i1 %50, label %51, label %57

51:                                               ; preds = %33
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !18
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr %53, align 8, !tbaa !18
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %72

57:                                               ; preds = %33
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._LIST_ENTRY, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  store ptr %61, ptr %6, align 8, !tbaa !5
  br label %26, !llvm.loop !19

62:                                               ; preds = %26
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %64, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !21
  store ptr %66, ptr %8, align 8, !tbaa !5
  br label %16, !llvm.loop !24

67:                                               ; preds = %16
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %9, align 8, !tbaa !11
  %70 = add nsw i64 %69, -1
  store i64 %70, ptr %9, align 8, !tbaa !11
  br label %11, !llvm.loop !25

71:                                               ; preds = %11
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %72

72:                                               ; preds = %71, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %73 = load ptr, ptr %3, align 8
  ret ptr %73
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!16, !10, i64 24}
!16 = !{!"", !14, i64 0, !12, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!17 = !{!16, !10, i64 28}
!18 = !{!16, !12, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !6, i64 544}
!22 = !{!"_IP4_ROUTE_TABLE", !12, i64 0, !10, i64 8, !7, i64 16, !6, i64 544, !23, i64 552}
!23 = !{!"", !7, i64 0}
!24 = distinct !{!24, !20}
!25 = distinct !{!25, !20}


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

%struct._LIST_ENTRY = type { ptr, ptr }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @Ip4FindRouteEntry(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not23 = icmp eq ptr %0, null
  br i1 %.not23, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2, %._crit_edge
  %.025 = phi i64 [ %22, %._crit_edge ], [ 32, %2 ]
  br label %3

3:                                                ; preds = %.preheader, %19
  %.01824 = phi ptr [ %0, %.preheader ], [ %21, %19 ]
  %4 = getelementptr inbounds i8, ptr %.01824, i64 16
  %5 = getelementptr inbounds [33 x %struct._LIST_ENTRY], ptr %4, i64 0, i64 %.025
  br label %6

6:                                                ; preds = %7, %3
  %.019.in = phi ptr [ %5, %3 ], [ %.019, %7 ]
  %.019 = load ptr, ptr %.019.in, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.019, %5
  br i1 %.not21, label %19, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %.019, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %.019, i64 28
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %12 = xor i32 %9, %1
  %13 = and i32 %12, %11
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %6, !llvm.loop !15

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %.019, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !17
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr %16, align 8, !tbaa !17
  br label %.loopexit

19:                                               ; preds = %6
  %20 = getelementptr inbounds i8, ptr %.01824, i64 544
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %._crit_edge, label %3, !llvm.loop !21

._crit_edge:                                      ; preds = %19
  %22 = add nsw i64 %.025, -1
  %.not28 = icmp eq i64 %.025, 0
  br i1 %.not28, label %.loopexit, label %.preheader, !llvm.loop !22

.loopexit:                                        ; preds = %._crit_edge, %2, %15
  %.020 = phi ptr [ %.019, %15 ], [ null, %2 ], [ null, %._crit_edge ]
  ret ptr %.020
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !13, i64 24}
!11 = !{!"", !6, i64 0, !12, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!11, !13, i64 28}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!11, !12, i64 16}
!18 = !{!19, !7, i64 544}
!19 = !{!"_IP4_ROUTE_TABLE", !12, i64 0, !13, i64 8, !8, i64 16, !7, i64 544, !20, i64 552}
!20 = !{!"", !8, i64 0}
!21 = distinct !{!21, !16}
!22 = distinct !{!22, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass