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

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

@.str = external hidden unnamed_addr constant [150 x i8], align 1
@.str.3 = 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 @Ip4FreeRouteEntry(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 @Ip4CleanRouteCache(ptr noundef) #1

declare ptr @RemoveEntryList(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @Ip4FreeRouteTable(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 i32, align 4
  %7 = 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 4, ptr %6) #3
  br label %8

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

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

16:                                               ; preds = %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 235, ptr noundef @.str.3)
  br label %17

17:                                               ; preds = %16, %11
  br label %18

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

19:                                               ; preds = %18
  br label %20

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

26:                                               ; preds = %20
  store i32 1, ptr %7, align 4
  br label %71

27:                                               ; preds = %20
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %28

28:                                               ; preds = %64, %27
  %29 = load i32, ptr %6, align 4, !tbaa !14
  %30 = icmp ult i32 %29, 33
  br i1 %30, label %31, label %67

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

42:                                               ; preds = %58, %31
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %6, align 4, !tbaa !14
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds [33 x %struct._LIST_ENTRY], ptr %45, i64 0, i64 %47
  %49 = icmp ne ptr %43, %48
  br i1 %49, label %50, label %63

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

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

63:                                               ; preds = %42
  br label %64

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

67:                                               ; preds = %28
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %68, i32 0, i32 4
  call void @Ip4CleanRouteCache(ptr noundef %69)
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %70)
  store i32 0, ptr %7, align 4
  br label %71

71:                                               ; preds = %67, %26
  call void @llvm.lifetime.end.p0(i64 4, 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
  %72 = load i32, ptr %7, align 4
  switch i32 %72, label %74 [
    i32 0, label %73
    i32 1, label %73
  ]

73:                                               ; preds = %71, %71
  ret void

74:                                               ; preds = %71
  unreachable
}

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 = !{!"_IP4_ROUTE_TABLE", !11, i64 0, !12, i64 8, !7, i64 16, !6, i64 544, !13, i64 552}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !7, i64 0}
!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}


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

; Function Attrs: nounwind uwtable
declare dso_local void @Ip4FreeRouteEntry(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 @Ip4CleanRouteCache(ptr noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @Ip4FreeRouteTable(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 235, ptr noundef nonnull @.str.3) #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 %18, label %.preheader

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

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

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

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

16:                                               ; preds = %._crit_edge
  %17 = getelementptr inbounds i8, ptr %0, i64 552
  tail call void @Ip4CleanRouteCache(ptr noundef nonnull %17)
  tail call void @FreePool(ptr noundef nonnull %0) #2
  br label %18

18:                                               ; preds = %7, %16
  ret void
}

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 = !{!"_IP4_ROUTE_TABLE", !7, i64 0, !10, i64 8, !8, i64 16, !11, i64 544, !12, i64 552}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"", !8, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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