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

; 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._IP6_ROUTE_TABLE = type { i64, i32, [129 x %struct._LIST_ENTRY], %struct.IP6_ROUTE_CACHE }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.IP6_ROUTE_CACHE = type { [31 x %struct._LIST_ENTRY], [31 x i8] }
%struct.IP6_ROUTE_CACHE_ENTRY = type { %struct._LIST_ENTRY, i64, i64, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local i32 @Ip6RouteCacheHash(ptr noundef, ptr noundef) #0

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

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

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

32:                                               ; preds = %23
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = sub i64 %34, 0
  %36 = inttoptr i64 %35 to ptr
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.IP6_ROUTE_CACHE_ENTRY, ptr %38, i32 0, i32 3
  %40 = call i64 @CompareMem(ptr noundef %37, ptr noundef %39, i64 noundef 16)
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %42, label %54

42:                                               ; preds = %32
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IP6_ROUTE_CACHE_ENTRY, ptr %44, i32 0, i32 4
  %46 = call i64 @CompareMem(ptr noundef %43, ptr noundef %45, i64 noundef 16)
  %47 = icmp eq i64 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %42
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.IP6_ROUTE_CACHE_ENTRY, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !13
  %52 = add nsw i64 %51, 1
  store i64 %52, ptr %50, align 8, !tbaa !13
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %53, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %60

54:                                               ; preds = %42, %32
  br label %55

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

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

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #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 = { 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 = !{!"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, !15, i64 16}
!14 = !{!"", !12, i64 0, !15, i64 16, !15, i64 24, !16, i64 32, !16, i64 48, !16, i64 64}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
declare dso_local i32 @Ip6RouteCacheHash(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6FindRouteCache(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @Ip6RouteCacheHash(ptr noundef %1, ptr noundef %2)
  %5 = getelementptr inbounds i8, ptr %0, i64 2080
  %6 = zext i32 %4 to i64
  %7 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %5, i64 0, i64 %6
  %.01517 = load ptr, ptr %7, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.01517, %7
  br i1 %.not18, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %19
  %.01519 = phi ptr [ %.015, %19 ], [ %.01517, %3 ]
  %8 = getelementptr inbounds i8, ptr %.01519, i64 32
  %9 = tail call i64 @CompareMem(ptr noundef %1, ptr noundef nonnull %8, i64 noundef 16) #2
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %19

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %.01519, i64 48
  %13 = tail call i64 @CompareMem(ptr noundef %2, ptr noundef nonnull %12, i64 noundef 16) #2
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %19

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

19:                                               ; preds = %.lr.ph, %11
  %.015 = load ptr, ptr %.01519, align 8, !tbaa !5
  %.not = icmp eq ptr %.015, %7
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

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

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

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 = { 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, !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, !12, i64 16}
!11 = !{!"", !6, i64 0, !12, i64 16, !12, i64 24, !13, i64 32, !13, i64 48, !13, i64 64}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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