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

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

; 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 ptr @RemoveEntryList(ptr noundef) #2

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

declare i64 @NetGetMaskLength(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4DelRoute(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %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
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  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
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = call i64 @NetGetMaskLength(i32 noundef %17)
  %19 = getelementptr inbounds [33 x %struct._LIST_ENTRY], ptr %16, i64 0, i64 %18
  store ptr %19, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %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 %11, align 8, !tbaa !5
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._LIST_ENTRY, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %25, ptr %12, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %63, %4
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = icmp ne ptr %27, %28
  br i1 %29, label %30, label %68

30:                                               ; preds = %26
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = ptrtoint ptr %31 to i64
  %33 = sub i64 %32, 0
  %34 = inttoptr i64 %33 to ptr
  store ptr %34, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = and i32 %37, %38
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = and i32 %40, %41
  %43 = icmp eq i32 %39, %42
  br i1 %43, label %44, label %62

44:                                               ; preds = %30
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.IP4_ROUTE_ENTRY, ptr %45, i32 0, i32 4
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = icmp eq i32 %47, %48
  br i1 %49, label %50, label %62

50:                                               ; preds = %44
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = ptrtoint ptr %53 to i64
  call void @Ip4PurgeRouteCache(ptr noundef %52, i64 noundef %54)
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = call ptr @RemoveEntryList(ptr noundef %55)
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  call void @Ip4FreeRouteEntry(ptr noundef %57)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._IP4_ROUTE_TABLE, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 8, !tbaa !17
  %61 = add i32 %60, -1
  store i32 %61, ptr %59, align 8, !tbaa !17
  store i64 0, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %69

62:                                               ; preds = %44, %30
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %64, ptr %11, align 8, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._LIST_ENTRY, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  store ptr %67, ptr %12, align 8, !tbaa !5
  br label %26, !llvm.loop !20

68:                                               ; preds = %26
  store i64 -9223372036854775794, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %69

69:                                               ; preds = %68, %50
  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
  %70 = load i64, ptr %5, align 8
  ret i64 %70
}

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, !6, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 24}
!14 = !{!"", !12, i64 0, !15, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!15 = !{!"long long", !7, i64 0}
!16 = !{!14, !10, i64 32}
!17 = !{!18, !10, i64 8}
!18 = !{!"_IP4_ROUTE_TABLE", !15, i64 0, !10, i64 8, !7, i64 16, !6, i64 544, !19, i64 552}
!19 = !{!"", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 void @Ip4FreeRouteEntry(ptr noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #1

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

declare i64 @NetGetMaskLength(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775794, 1) i64 @Ip4DelRoute(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = tail call i64 @NetGetMaskLength(i32 noundef %2) #2
  %7 = getelementptr inbounds [33 x %struct._LIST_ENTRY], ptr %5, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not24 = icmp eq ptr %8, %7
  br i1 %.not24, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %25
  %.02125 = phi ptr [ %.02026, %25 ], [ %8, %4 ]
  %.02026 = load ptr, ptr %.02125, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %.02125, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !10
  %11 = xor i32 %10, %1
  %12 = and i32 %11, %2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %25

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %.02125, i64 32
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp eq i32 %16, %3
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = ptrtoint ptr %.02125 to i64
  %20 = getelementptr inbounds i8, ptr %0, i64 552
  tail call void @Ip4PurgeRouteCache(ptr noundef nonnull %20, i64 noundef %19)
  %21 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.02125) #2
  tail call void @Ip4FreeRouteEntry(ptr noundef nonnull %.02125)
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = add i32 %23, -1
  store i32 %24, ptr %22, align 8, !tbaa !15
  br label %.loopexit

25:                                               ; preds = %.lr.ph, %14
  %.not = icmp eq ptr %.02026, %7
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !18

.loopexit:                                        ; preds = %25, %4, %18
  %.0 = phi i64 [ 0, %18 ], [ -9223372036854775794, %4 ], [ -9223372036854775794, %25 ]
  ret i64 %.0
}

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, !13, i64 24}
!11 = !{!"", !6, i64 0, !12, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!11, !13, i64 32}
!15 = !{!16, !13, i64 8}
!16 = !{!"_IP4_ROUTE_TABLE", !12, i64 0, !13, i64 8, !8, i64 16, !7, i64 544, !17, i64 552}
!17 = !{!"", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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