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

; 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_ENTRY = type { %struct._LIST_ENTRY, i64, i32, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

@.str = external hidden unnamed_addr constant [130 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [55 x i8], align 1

; 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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6FindRouteEntry(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %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 i64, align 8
  %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 8, ptr %10) #3
  br label %12

12:                                               ; preds = %3
  %13 = call zeroext i8 @DebugAssertEnabled()
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %22, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @DebugAssert(ptr noundef @.str, i64 noundef 134, ptr noundef @.str.2)
  br label %22

22:                                               ; preds = %21, %18, %15
  br label %23

23:                                               ; preds = %22, %12
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  store ptr null, ptr %9, align 8, !tbaa !5
  store i64 128, ptr %10, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %92, %25
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = icmp sge i64 %27, 0
  br i1 %28, label %29, label %95

29:                                               ; preds = %26
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %31, i64 0, i64 %32
  %34 = getelementptr inbounds %struct._LIST_ENTRY, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  store ptr %35, ptr %8, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %87, %29
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %39, i64 0, i64 %40
  %42 = icmp ne ptr %37, %41
  br i1 %42, label %43, label %91

43:                                               ; preds = %36
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = ptrtoint ptr %44 to i64
  %46 = sub i64 %45, 0
  %47 = inttoptr i64 %46 to ptr
  store ptr %47, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %66

50:                                               ; preds = %43
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %54, i32 0, i32 3
  %56 = load i8, ptr %55, align 4, !tbaa !13
  %57 = call zeroext i8 @NetIp6IsNetEqual(ptr noundef %51, ptr noundef %53, i8 noundef zeroext %56)
  %58 = icmp ne i8 %57, 0
  br i1 %58, label %59, label %65

59:                                               ; preds = %50
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !17
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %61, align 8, !tbaa !17
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %64, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %96

65:                                               ; preds = %50
  br label %86

66:                                               ; preds = %43
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %85

69:                                               ; preds = %66
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %71, i32 0, i32 5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %73, i32 0, i32 3
  %75 = load i8, ptr %74, align 4, !tbaa !13
  %76 = call zeroext i8 @NetIp6IsNetEqual(ptr noundef %70, ptr noundef %72, i8 noundef zeroext %75)
  %77 = icmp ne i8 %76, 0
  br i1 %77, label %78, label %84

78:                                               ; preds = %69
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.IP6_ROUTE_ENTRY, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !17
  %82 = add nsw i64 %81, 1
  store i64 %82, ptr %80, align 8, !tbaa !17
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %83, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %96

84:                                               ; preds = %69
  br label %85

85:                                               ; preds = %84, %66
  br label %86

86:                                               ; preds = %85, %65
  br label %87

87:                                               ; preds = %86
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._LIST_ENTRY, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !11
  store ptr %90, ptr %8, align 8, !tbaa !5
  br label %36, !llvm.loop !18

91:                                               ; preds = %36
  br label %92

92:                                               ; preds = %91
  %93 = load i64, ptr %10, align 8, !tbaa !9
  %94 = add nsw i64 %93, -1
  store i64 %94, ptr %10, align 8, !tbaa !9
  br label %26, !llvm.loop !20

95:                                               ; preds = %26
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %96

96:                                               ; preds = %95, %78, %59
  call void @llvm.lifetime.end.p0(i64 8, 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
  %97 = load ptr, ptr %4, align 8
  ret ptr %97
}

declare zeroext i8 @NetIp6IsNetEqual(ptr noundef, ptr noundef, i8 noundef zeroext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!14, !7, i64 28}
!14 = !{!"", !12, i64 0, !10, i64 16, !15, i64 24, !7, i64 28, !16, i64 29, !16, i64 45}
!15 = !{!"int", !7, i64 0}
!16 = !{!"", !7, i64 0}
!17 = !{!14, !10, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@.str = external hidden unnamed_addr constant [130 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [55 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip6FindRouteEntry(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %8, label %5

5:                                                ; preds = %3
  %6 = icmp ne ptr %1, null
  %7 = icmp ne ptr %2, null
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %8, label %.split.us39.thread

.split.us39.thread:                               ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 134, ptr noundef nonnull @.str.2) #2
  br label %.loopexit

8:                                                ; preds = %5, %3
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %.not29 = icmp eq ptr %1, null
  br i1 %.not29, label %.split.us39, label %.split

.split.us39:                                      ; preds = %8
  %.not30 = icmp eq ptr %2, null
  br i1 %.not30, label %.loopexit, label %.split.us39.split

.split.us39.split:                                ; preds = %.split.us39, %._crit_edge.split.us.split.us43
  %.038.us = phi i64 [ %11, %._crit_edge.split.us.split.us43 ], [ 128, %.split.us39 ]
  %10 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %9, i64 0, i64 %.038.us
  %.02435.us = load ptr, ptr %10, align 8, !tbaa !5
  %.not2836.us = icmp eq ptr %.02435.us, %10
  br i1 %.not2836.us, label %._crit_edge.split.us.split.us43, label %.lr.ph.us

._crit_edge.split.us.split.us43:                  ; preds = %16, %.split.us39.split
  %11 = add nsw i64 %.038.us, -1
  %.not50 = icmp eq i64 %.038.us, 0
  br i1 %.not50, label %.loopexit, label %.split.us39.split, !llvm.loop !10

.lr.ph.us:                                        ; preds = %.split.us39.split, %16
  %.02437.us.us40 = phi ptr [ %.024.us.us41, %16 ], [ %.02435.us, %.split.us39.split ]
  %12 = getelementptr inbounds i8, ptr %.02437.us.us40, i64 45
  %13 = getelementptr inbounds i8, ptr %.02437.us.us40, i64 28
  %14 = load i8, ptr %13, align 4, !tbaa !12
  %15 = tail call zeroext i8 @NetIp6IsNetEqual(ptr noundef nonnull %2, ptr noundef nonnull %12, i8 noundef zeroext %14) #2
  %.not31.us.us = icmp eq i8 %15, 0
  br i1 %.not31.us.us, label %16, label %.split.us

16:                                               ; preds = %.lr.ph.us
  %.024.us.us41 = load ptr, ptr %.02437.us.us40, align 8, !tbaa !5
  %.not28.us.us42 = icmp eq ptr %.024.us.us41, %10
  br i1 %.not28.us.us42, label %._crit_edge.split.us.split.us43, label %.lr.ph.us, !llvm.loop !17

.split:                                           ; preds = %8, %._crit_edge.split
  %.038 = phi i64 [ %30, %._crit_edge.split ], [ 128, %8 ]
  %17 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %9, i64 0, i64 %.038
  %.02435 = load ptr, ptr %17, align 8, !tbaa !5
  %.not2836 = icmp eq ptr %.02435, %17
  br i1 %.not2836, label %._crit_edge.split, label %.lr.ph

.lr.ph:                                           ; preds = %.split, %29
  %.02437 = phi ptr [ %.024, %29 ], [ %.02435, %.split ]
  %18 = getelementptr inbounds i8, ptr %.02437, i64 29
  %19 = getelementptr inbounds i8, ptr %.02437, i64 28
  %20 = load i8, ptr %19, align 4, !tbaa !12
  %21 = tail call zeroext i8 @NetIp6IsNetEqual(ptr noundef nonnull %1, ptr noundef nonnull %18, i8 noundef zeroext %20) #2
  %.not32 = icmp eq i8 %21, 0
  br i1 %.not32, label %29, label %22

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i8, ptr %.02437, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !18
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %23, align 8, !tbaa !18
  br label %.loopexit

.split.us:                                        ; preds = %.lr.ph.us
  %26 = getelementptr inbounds i8, ptr %.02437.us.us40, i64 16
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %26, align 8, !tbaa !18
  br label %.loopexit

29:                                               ; preds = %.lr.ph
  %.024 = load ptr, ptr %.02437, align 8, !tbaa !5
  %.not28 = icmp eq ptr %.024, %17
  br i1 %.not28, label %._crit_edge.split, label %.lr.ph, !llvm.loop !17

._crit_edge.split:                                ; preds = %29, %.split
  %30 = add nsw i64 %.038, -1
  %.not49 = icmp eq i64 %.038, 0
  br i1 %.not49, label %.loopexit, label %.split, !llvm.loop !10

.loopexit:                                        ; preds = %._crit_edge.split, %._crit_edge.split.us.split.us43, %.split.us39, %.split.us39.thread, %.split.us, %22
  %.025 = phi ptr [ %.02437, %22 ], [ %.02437.us.us40, %.split.us ], [ null, %.split.us39.thread ], [ null, %.split.us39 ], [ null, %._crit_edge.split.us.split.us43 ], [ null, %._crit_edge.split ]
  ret ptr %.025
}

declare zeroext i8 @NetIp6IsNetEqual(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

attributes #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 = { 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, !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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !8, i64 28}
!13 = !{!"", !6, i64 0, !14, i64 16, !15, i64 24, !8, i64 28, !16, i64 29, !16, i64 45}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!"", !8, i64 0}
!17 = distinct !{!17, !11}
!18 = !{!13, !14, i64 16}


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