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

; 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_CACHE_ENTRY = type { %struct._LIST_ENTRY, i64, i32, i32, i32, i64 }

; 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 @Ip4FindRouteCache(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = xor i32 %12, %13
  %15 = urem i32 %14, 31
  store i32 %15, ptr %10, align 4, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %16, i32 0, i32 4
  %18 = getelementptr inbounds %struct.IP4_ROUTE_CACHE, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %18, i64 0, i64 %20
  %22 = getelementptr inbounds %struct._LIST_ENTRY, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %56, %3
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %26, i32 0, i32 4
  %28 = getelementptr inbounds %struct.IP4_ROUTE_CACHE, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %28, i64 0, i64 %30
  %32 = icmp ne ptr %25, %31
  br i1 %32, label %33, label %60

33:                                               ; preds = %24
  %34 = load ptr, ptr %8, 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 %9, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !13
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %55

43:                                               ; preds = %33
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !16
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp eq i32 %46, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %43
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !17
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %51, align 8, !tbaa !17
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %54, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %61

55:                                               ; preds = %43, %33
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._LIST_ENTRY, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  store ptr %59, ptr %8, align 8, !tbaa !5
  br label %24, !llvm.loop !18

60:                                               ; preds = %24
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %61

61:                                               ; preds = %60, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %62 = load ptr, ptr %4, align 8
  ret ptr %62
}

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, !6, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 24}
!14 = !{!"", !12, i64 0, !15, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !15, i64 40}
!15 = !{!"long long", !7, i64 0}
!16 = !{!14, !10, i64 28}
!17 = !{!14, !15, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct._LIST_ENTRY = type { ptr, ptr }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @Ip4FindRouteCache(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = xor i32 %2, %1
  %5 = urem i32 %4, 31
  %6 = getelementptr inbounds i8, ptr %0, i64 552
  %7 = zext nneg i32 %5 to i64
  %8 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %6, i64 0, i64 %7
  %.01517 = load ptr, ptr %8, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.01517, %8
  br i1 %.not18, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %20
  %.01519 = phi ptr [ %.015, %20 ], [ %.01517, %3 ]
  %9 = getelementptr inbounds i8, ptr %.01519, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !10
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %12, label %20

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %.01519, i64 28
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = icmp eq i32 %14, %2
  br i1 %15, label %16, label %20

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

20:                                               ; preds = %.lr.ph, %12
  %.015 = load ptr, ptr %.01519, align 8, !tbaa !5
  %.not = icmp eq ptr %.015, %8
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %20, %3, %16
  %.0 = phi ptr [ %.01519, %16 ], [ null, %3 ], [ null, %20 ]
  ret ptr %.0
}

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, !12, i64 40}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!11, !13, i64 28}
!15 = !{!11, !12, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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