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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @Ip4CreateRouteCacheEntry(i32 noundef, i32 noundef, i32 noundef, i64 noundef) #1

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

declare ptr @RemoveEntryList(ptr noundef) #2

declare ptr @InsertHeadList(ptr noundef, ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip4Route(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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = 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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  br label %17

17:                                               ; preds = %3
  %18 = call zeroext i8 @DebugAssertEnabled()
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @DebugAssert(ptr noundef @.str, i64 noundef 518, ptr noundef @.str.4)
  br label %24

24:                                               ; preds = %23, %20
  br label %25

25:                                               ; preds = %24, %17
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %28, i32 0, i32 4
  %30 = getelementptr inbounds %struct.IP4_ROUTE_CACHE, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = xor i32 %31, %32
  %34 = urem i32 %33, 31
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %30, i64 0, i64 %35
  store ptr %36, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = call ptr @Ip4FindRouteCache(ptr noundef %37, i32 noundef %38, i32 noundef %39)
  store ptr %40, ptr %11, align 8, !tbaa !5
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %52

43:                                               ; preds = %27
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %44, i32 0, i32 0
  %46 = call ptr @RemoveEntryList(ptr noundef %45)
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %48, i32 0, i32 0
  %50 = call ptr @InsertHeadList(ptr noundef %47, ptr noundef %49)
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %51, ptr %4, align 8
  store i32 1, ptr %16, align 4
  br label %121

52:                                               ; preds = %27
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = call ptr @Ip4FindRouteEntry(ptr noundef %53, i32 noundef %54)
  store ptr %55, ptr %13, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = icmp eq ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %52
  store ptr null, ptr %4, align 8
  store i32 1, ptr %16, align 4
  br label %121

59:                                               ; preds = %52
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %60, i32 0, i32 5
  %62 = load i32, ptr %61, align 4, !tbaa !11
  %63 = and i32 %62, 1
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %59
  %66 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %66, ptr %14, align 4, !tbaa !9
  br label %71

67:                                               ; preds = %59
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %68, i32 0, i32 4
  %70 = load i32, ptr %69, align 8, !tbaa !15
  store i32 %70, ptr %14, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %67, %65
  %72 = load ptr, ptr %13, align 8, !tbaa !5
  call void @Ip4FreeRouteEntry(ptr noundef %72)
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = ptrtoint ptr %76 to i64
  %78 = call ptr @Ip4CreateRouteCacheEntry(i32 noundef %73, i32 noundef %74, i32 noundef %75, i64 noundef %77)
  store ptr %78, ptr %11, align 8, !tbaa !5
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = icmp eq ptr %79, null
  br i1 %80, label %81, label %82

81:                                               ; preds = %71
  store ptr null, ptr %4, align 8
  store i32 1, ptr %16, align 4
  br label %121

82:                                               ; preds = %71
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %84, i32 0, i32 0
  %86 = call ptr @InsertHeadList(ptr noundef %83, ptr noundef %85)
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.IP4_ROUTE_CACHE_ENTRY, ptr %87, i32 0, i32 1
  %89 = load i64, ptr %88, align 8, !tbaa !16
  %90 = add nsw i64 %89, 1
  store i64 %90, ptr %88, align 8, !tbaa !16
  store i32 0, ptr %15, align 4, !tbaa !9
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._LIST_ENTRY, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !18
  store ptr %93, ptr %9, align 8, !tbaa !5
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct._LIST_ENTRY, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !18
  store ptr %96, ptr %10, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %114, %82
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = icmp ne ptr %98, %99
  br i1 %100, label %101, label %119

101:                                              ; preds = %97
  %102 = load i32, ptr %15, align 4, !tbaa !9
  %103 = add i32 %102, 1
  store i32 %103, ptr %15, align 4, !tbaa !9
  %104 = icmp ult i32 %103, 64
  br i1 %104, label %105, label %106

105:                                              ; preds = %101
  br label %114

106:                                              ; preds = %101
  %107 = load ptr, ptr %9, align 8, !tbaa !5
  %108 = ptrtoint ptr %107 to i64
  %109 = sub i64 %108, 0
  %110 = inttoptr i64 %109 to ptr
  store ptr %110, ptr %12, align 8, !tbaa !5
  %111 = load ptr, ptr %9, align 8, !tbaa !5
  %112 = call ptr @RemoveEntryList(ptr noundef %111)
  %113 = load ptr, ptr %12, align 8, !tbaa !5
  call void @Ip4FreeRouteCacheEntry(ptr noundef %113)
  br label %114

114:                                              ; preds = %106, %105
  %115 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %115, ptr %9, align 8, !tbaa !5
  %116 = load ptr, ptr %9, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct._LIST_ENTRY, ptr %116, i32 0, i32 0
  %118 = load ptr, ptr %117, align 8, !tbaa !18
  store ptr %118, ptr %10, align 8, !tbaa !5
  br label %97, !llvm.loop !19

119:                                              ; preds = %97
  %120 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %120, ptr %4, align 8
  store i32 1, ptr %16, align 4
  br label %121

121:                                              ; preds = %119, %81, %58, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  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
  %122 = load ptr, ptr %4, align 8
  ret ptr %122
}

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

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

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

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

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #1

declare ptr @InsertHeadList(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip4Route(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %5 = icmp eq i8 %4, 0
  %6 = icmp ne ptr %0, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %8, label %7

7:                                                ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 518, ptr noundef nonnull @.str.4) #2
  br label %8

8:                                                ; preds = %7, %3
  %9 = getelementptr inbounds i8, ptr %0, i64 552
  %10 = xor i32 %2, %1
  %11 = urem i32 %10, 31
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds [31 x %struct._LIST_ENTRY], ptr %9, i64 0, i64 %12
  %14 = tail call ptr @Ip4FindRouteCache(ptr noundef %0, i32 noundef %1, i32 noundef %2)
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %18, label %15

15:                                               ; preds = %8
  %16 = tail call ptr @RemoveEntryList(ptr noundef nonnull %14) #2
  %17 = tail call ptr @InsertHeadList(ptr noundef nonnull %13, ptr noundef nonnull %14) #2
  br label %.loopexit

18:                                               ; preds = %8
  %19 = tail call ptr @Ip4FindRouteEntry(ptr noundef %0, i32 noundef %1)
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %19, i64 36
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = and i32 %23, 1
  %.not46 = icmp eq i32 %24, 0
  br i1 %.not46, label %25, label %28

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %19, i64 32
  %27 = load i32, ptr %26, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %21, %25
  %.039 = phi i32 [ %27, %25 ], [ %1, %21 ]
  tail call void @Ip4FreeRouteEntry(ptr noundef nonnull %19)
  %29 = ptrtoint ptr %19 to i64
  %30 = tail call ptr @Ip4CreateRouteCacheEntry(i32 noundef %1, i32 noundef %2, i32 noundef %.039, i64 noundef %29)
  %31 = icmp eq ptr %30, null
  br i1 %31, label %.loopexit, label %32

32:                                               ; preds = %28
  %33 = tail call ptr @InsertHeadList(ptr noundef nonnull %13, ptr noundef nonnull %30) #2
  %34 = getelementptr inbounds i8, ptr %30, i64 16
  %35 = load i64, ptr %34, align 8, !tbaa !14
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %34, align 8, !tbaa !14
  %37 = load ptr, ptr %13, align 8, !tbaa !16
  %.not4749 = icmp eq ptr %37, %13
  br i1 %.not4749, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %32, %42
  %.051 = phi i32 [ %38, %42 ], [ 0, %32 ]
  %.04150 = phi ptr [ %.04252, %42 ], [ %37, %32 ]
  %.04252 = load ptr, ptr %.04150, align 8, !tbaa !16
  %38 = add i32 %.051, 1
  %39 = icmp ult i32 %38, 64
  br i1 %39, label %42, label %40

40:                                               ; preds = %.lr.ph
  %41 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.04150) #2
  tail call void @Ip4FreeRouteCacheEntry(ptr noundef nonnull %.04150)
  br label %42

42:                                               ; preds = %.lr.ph, %40
  %.not47 = icmp eq ptr %.04252, %13
  br i1 %.not47, label %.loopexit, label %.lr.ph, !llvm.loop !17

.loopexit:                                        ; preds = %42, %32, %28, %18, %15
  %.040 = phi ptr [ %14, %15 ], [ null, %18 ], [ null, %28 ], [ %30, %32 ], [ %30, %42 ]
  ret ptr %.040
}

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


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