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

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

@.str = external hidden unnamed_addr constant [130 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 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

; Function Attrs: nounwind uwtable
declare dso_local void @Ip6FreeRouteEntry(ptr noundef) #1

declare zeroext i8 @DebugAssertEnabled() #2

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

declare void @FreePool(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @Ip6FreeRouteCacheEntry(ptr noundef) #1

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

9:                                                ; preds = %1
  %10 = call zeroext i8 @DebugAssertEnabled()
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %19

12:                                               ; preds = %9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @DebugAssert(ptr noundef @.str, i64 noundef 379, ptr noundef @.str.6)
  br label %18

18:                                               ; preds = %17, %12
  br label %19

19:                                               ; preds = %18, %9
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = add nsw i64 %24, -1
  store i64 %25, ptr %23, align 8, !tbaa !9
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 1, ptr %8, align 4
  br label %112

28:                                               ; preds = %21
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %29

29:                                               ; preds = %65, %28
  %30 = load i32, ptr %7, align 4, !tbaa !14
  %31 = icmp ult i32 %30, 129
  br i1 %31, label %32, label %68

32:                                               ; preds = %29
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %7, align 4, !tbaa !14
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %34, i64 0, i64 %36
  %38 = getelementptr inbounds %struct._LIST_ENTRY, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  store ptr %39, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._LIST_ENTRY, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  store ptr %42, ptr %4, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %59, %32
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %7, align 4, !tbaa !14
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %46, i64 0, i64 %48
  %50 = icmp ne ptr %44, %49
  br i1 %50, label %51, label %64

51:                                               ; preds = %43
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = ptrtoint ptr %52 to i64
  %54 = sub i64 %53, 0
  %55 = inttoptr i64 %54 to ptr
  store ptr %55, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call ptr @RemoveEntryList(ptr noundef %56)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Ip6FreeRouteEntry(ptr noundef %58)
  br label %59

59:                                               ; preds = %51
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %60, ptr %3, align 8, !tbaa !5
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._LIST_ENTRY, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  store ptr %63, ptr %4, align 8, !tbaa !5
  br label %43, !llvm.loop !17

64:                                               ; preds = %43
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %7, align 4, !tbaa !14
  %67 = add i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !14
  br label %29, !llvm.loop !19

68:                                               ; preds = %29
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %69

69:                                               ; preds = %107, %68
  %70 = load i32, ptr %7, align 4, !tbaa !14
  %71 = icmp ult i32 %70, 31
  br i1 %71, label %72, label %110

72:                                               ; preds = %69
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %73, i32 0, i32 3
  %75 = getelementptr inbounds %struct.IP6_ROUTE_CACHE, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %7, align 4, !tbaa !14
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %75, i64 0, i64 %77
  %79 = getelementptr inbounds %struct._LIST_ENTRY, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  store ptr %80, ptr %3, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._LIST_ENTRY, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !15
  store ptr %83, ptr %4, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %101, %72
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._IP6_ROUTE_TABLE, ptr %86, i32 0, i32 3
  %88 = getelementptr inbounds %struct.IP6_ROUTE_CACHE, ptr %87, i32 0, i32 0
  %89 = load i32, ptr %7, align 4, !tbaa !14
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %88, i64 0, i64 %90
  %92 = icmp ne ptr %85, %91
  br i1 %92, label %93, label %106

93:                                               ; preds = %84
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = ptrtoint ptr %94 to i64
  %96 = sub i64 %95, 0
  %97 = inttoptr i64 %96 to ptr
  store ptr %97, ptr %6, align 8, !tbaa !5
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = call ptr @RemoveEntryList(ptr noundef %98)
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  call void @Ip6FreeRouteCacheEntry(ptr noundef %100)
  br label %101

101:                                              ; preds = %93
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %102, ptr %3, align 8, !tbaa !5
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._LIST_ENTRY, ptr %103, i32 0, i32 0
  %105 = load ptr, ptr %104, align 8, !tbaa !15
  store ptr %105, ptr %4, align 8, !tbaa !5
  br label %84, !llvm.loop !20

106:                                              ; preds = %84
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %7, align 4, !tbaa !14
  %109 = add i32 %108, 1
  store i32 %109, ptr %7, align 4, !tbaa !14
  br label %69, !llvm.loop !21

110:                                              ; preds = %69
  %111 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %111)
  store i32 0, ptr %8, align 4
  br label %112

112:                                              ; preds = %110, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %113 = load i32, ptr %8, align 4
  switch i32 %113, label %115 [
    i32 0, label %114
    i32 1, label %114
  ]

114:                                              ; preds = %112, %112
  ret void

115:                                              ; preds = %112
  unreachable
}

declare ptr @RemoveEntryList(ptr noundef) #2

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 = { "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, !11, i64 0}
!10 = !{!"_IP6_ROUTE_TABLE", !11, i64 0, !12, i64 8, !7, i64 16, !13, i64 2080}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 496}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}


; 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.6 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @Ip6FreeRouteEntry(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Ip6FreeRouteCacheEntry(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Ip6CleanRouteTable(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %thread-pre-split, label %3

3:                                                ; preds = %1
  %4 = load i64, ptr %0, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 379, ptr noundef nonnull @.str.6) #2
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %1, %6
  %.pr = load i64, ptr %0, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %thread-pre-split, %3
  %8 = phi i64 [ %.pr, %thread-pre-split ], [ %4, %3 ]
  %9 = add nsw i64 %8, -1
  store i64 %9, ptr %0, align 8, !tbaa !5
  %10 = icmp sgt i64 %8, 1
  br i1 %10, label %22, label %.preheader34

.preheader34:                                     ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %13

.preheader:                                       ; preds = %._crit_edge
  %12 = getelementptr inbounds i8, ptr %0, i64 2080
  br label %17

13:                                               ; preds = %.preheader34, %._crit_edge
  %indvars.iv = phi i64 [ 0, %.preheader34 ], [ %indvars.iv.next, %._crit_edge ]
  %14 = getelementptr inbounds [129 x %struct._LIST_ENTRY], ptr %11, i64 0, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %.not3335 = icmp eq ptr %15, %14
  br i1 %.not3335, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.02836 = phi ptr [ %.030, %.lr.ph ], [ %15, %13 ]
  %.030 = load ptr, ptr %.02836, align 8, !tbaa !12
  %16 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.02836) #2
  tail call void @Ip6FreeRouteEntry(ptr noundef nonnull %.02836)
  %.not33 = icmp eq ptr %.030, %14
  br i1 %.not33, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 129
  br i1 %exitcond.not, label %.preheader, label %13, !llvm.loop !17

17:                                               ; preds = %.preheader, %._crit_edge42
  %indvars.iv45 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next46, %._crit_edge42 ]
  %18 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %12, i64 0, i64 %indvars.iv45
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %.not3238 = icmp eq ptr %19, %18
  br i1 %.not3238, label %._crit_edge42, label %.lr.ph41

.lr.ph41:                                         ; preds = %17, %.lr.ph41
  %.12939 = phi ptr [ %.131, %.lr.ph41 ], [ %19, %17 ]
  %.131 = load ptr, ptr %.12939, align 8, !tbaa !12
  %20 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.12939) #2
  tail call void @Ip6FreeRouteCacheEntry(ptr noundef nonnull %.12939)
  %.not32 = icmp eq ptr %.131, %18
  br i1 %.not32, label %._crit_edge42, label %.lr.ph41, !llvm.loop !18

._crit_edge42:                                    ; preds = %.lr.ph41, %17
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next46, 31
  br i1 %exitcond48.not, label %21, label %17, !llvm.loop !19

21:                                               ; preds = %._crit_edge42
  tail call void @FreePool(ptr noundef nonnull %0) #2
  br label %22

22:                                               ; preds = %7, %21
  ret void
}

declare ptr @RemoveEntryList(ptr 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 = !{!"_IP6_ROUTE_TABLE", !7, i64 0, !10, i64 8, !8, i64 16, !11, i64 2080}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !8, i64 0, !8, i64 496}
!12 = !{!13, !14, i64 0}
!13 = !{!"_LIST_ENTRY", !14, i64 0, !14, i64 8}
!14 = !{!"any pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


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