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

; 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.NET_VECTOR = type { i32, i64, ptr, ptr, i32, i32, i32, [1 x %struct.NET_BLOCK] }
%struct.NET_BLOCK = type { i32, ptr }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [111 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1
@gBS = external global ptr, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare zeroext i8 @DebugAssertEnabled() #1

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

declare void @FreePool(ptr noundef) #1

; 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
define dso_local void @NetbufFreeVector(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  br label %5

5:                                                ; preds = %1
  %6 = call zeroext i8 @DebugAssertEnabled()
  %7 = icmp ne i8 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @DebugAssert(ptr noundef @.str, i64 noundef 156, ptr noundef @.str.3)
  br label %12

12:                                               ; preds = %11, %8
  br label %13

13:                                               ; preds = %12, %5
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = call zeroext i8 @DebugAssertEnabled()
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %29

19:                                               ; preds = %16
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.NET_VECTOR, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = icmp eq i32 %25, 1667593838
  br i1 %26, label %28, label %27

27:                                               ; preds = %22, %19
  call void @DebugAssert(ptr noundef @.str, i64 noundef 157, ptr noundef @.str.4)
  br label %28

28:                                               ; preds = %27, %22
  br label %29

29:                                               ; preds = %28, %16
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = call zeroext i8 @DebugAssertEnabled()
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NET_VECTOR, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !13
  %39 = icmp sgt i64 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  call void @DebugAssert(ptr noundef @.str, i64 noundef 158, ptr noundef @.str.5)
  br label %41

41:                                               ; preds = %40, %35
  br label %42

42:                                               ; preds = %41, %32
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NET_VECTOR, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !13
  %48 = add nsw i64 %47, -1
  store i64 %48, ptr %46, align 8, !tbaa !13
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.NET_VECTOR, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !13
  %52 = icmp sgt i64 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %44
  store i32 1, ptr %4, align 4
  br label %107

54:                                               ; preds = %44
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.NET_VECTOR, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %82

59:                                               ; preds = %54
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.NET_VECTOR, ptr %60, i32 0, i32 4
  %62 = load i32, ptr %61, align 8, !tbaa !15
  %63 = and i32 %62, 1
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %75

65:                                               ; preds = %59
  %66 = load ptr, ptr @gBS, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %66, i32 0, i32 7
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.NET_VECTOR, ptr %69, i32 0, i32 7
  %71 = getelementptr inbounds [1 x %struct.NET_BLOCK], ptr %70, i64 0, i64 0
  %72 = getelementptr inbounds %struct.NET_BLOCK, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  %74 = call i64 %68(ptr noundef %73)
  br label %75

75:                                               ; preds = %65, %59
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.NET_VECTOR, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.NET_VECTOR, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !21
  call void %78(ptr noundef %81)
  br label %105

82:                                               ; preds = %54
  store i32 0, ptr %3, align 4, !tbaa !22
  br label %83

83:                                               ; preds = %101, %82
  %84 = load i32, ptr %3, align 4, !tbaa !22
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.NET_VECTOR, ptr %85, i32 0, i32 6
  %87 = load i32, ptr %86, align 8, !tbaa !23
  %88 = icmp ult i32 %84, %87
  br i1 %88, label %89, label %104

89:                                               ; preds = %83
  %90 = load ptr, ptr @gBS, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %90, i32 0, i32 7
  %92 = load ptr, ptr %91, align 8, !tbaa !16
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.NET_VECTOR, ptr %93, i32 0, i32 7
  %95 = load i32, ptr %3, align 4, !tbaa !22
  %96 = zext i32 %95 to i64
  %97 = getelementptr inbounds [1 x %struct.NET_BLOCK], ptr %94, i64 0, i64 %96
  %98 = getelementptr inbounds %struct.NET_BLOCK, ptr %97, i32 0, i32 1
  %99 = load ptr, ptr %98, align 8, !tbaa !19
  %100 = call i64 %92(ptr noundef %99)
  br label %101

101:                                              ; preds = %89
  %102 = load i32, ptr %3, align 4, !tbaa !22
  %103 = add i32 %102, 1
  store i32 %103, ptr %3, align 4, !tbaa !22
  br label %83, !llvm.loop !24

104:                                              ; preds = %83
  br label %105

105:                                              ; preds = %104, %75
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %106)
  store i32 0, ptr %4, align 4
  br label %107

107:                                              ; preds = %105, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %108 = load i32, ptr %4, align 4
  switch i32 %108, label %110 [
    i32 0, label %109
    i32 1, label %109
  ]

109:                                              ; preds = %107, %107
  ret void

110:                                              ; preds = %107
  unreachable
}

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, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !7, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !11, i64 32}
!16 = !{!17, !6, i64 72}
!17 = !{!"", !18, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!18 = !{!"", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!19 = !{!20, !6, i64 8}
!20 = !{!"", !11, i64 0, !6, i64 8}
!21 = !{!10, !6, i64 24}
!22 = !{!11, !11, i64 0}
!23 = !{!10, !11, i64 40}
!24 = distinct !{!24, !25}
!25 = !{!"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.NET_BLOCK = type { i32, ptr }

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [111 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

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

5:                                                ; preds = %1
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 156, ptr noundef nonnull @.str.3) #2
  br label %6

6:                                                ; preds = %1, %5
  %7 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %13, label %8

8:                                                ; preds = %6
  br i1 %4, label %9, label %12

9:                                                ; preds = %8
  %10 = load i32, ptr %0, align 8, !tbaa !5
  %11 = icmp eq i32 %10, 1667593838
  br i1 %11, label %13, label %12

12:                                               ; preds = %9, %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 157, ptr noundef nonnull @.str.4) #2
  br label %13

13:                                               ; preds = %6, %12, %9
  %14 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not18 = icmp eq i8 %14, 0
  br i1 %.not18, label %20, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = icmp sgt i64 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 158, ptr noundef nonnull @.str.5) #2
  br label %20

20:                                               ; preds = %15, %19, %13
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !12
  %23 = add nsw i64 %22, -1
  store i64 %23, ptr %21, align 8, !tbaa !12
  %24 = icmp sgt i64 %22, 1
  br i1 %24, label %56, label %25

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %.not19 = icmp eq ptr %27, null
  br i1 %.not19, label %.preheader, label %31

.preheader:                                       ; preds = %25
  %28 = getelementptr inbounds i8, ptr %0, i64 40
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %.not22 = icmp eq i32 %29, 0
  br i1 %.not22, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %30 = getelementptr inbounds i8, ptr %0, i64 48
  br label %46

31:                                               ; preds = %25
  %32 = getelementptr inbounds i8, ptr %0, i64 32
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = and i32 %33, 1
  %.not20 = icmp eq i32 %34, 0
  br i1 %.not20, label %42, label %35

35:                                               ; preds = %31
  %36 = load ptr, ptr @gBS, align 8, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %36, i64 72
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = getelementptr inbounds i8, ptr %0, i64 56
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = tail call i64 %38(ptr noundef %40) #2
  %.pre = load ptr, ptr %26, align 8, !tbaa !13
  br label %42

42:                                               ; preds = %35, %31
  %43 = phi ptr [ %.pre, %35 ], [ %27, %31 ]
  %44 = getelementptr inbounds i8, ptr %0, i64 24
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  tail call void %43(ptr noundef %45) #2
  br label %.loopexit

46:                                               ; preds = %.lr.ph, %46
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %46 ]
  %47 = load ptr, ptr @gBS, align 8, !tbaa !16
  %48 = getelementptr inbounds i8, ptr %47, i64 72
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = getelementptr inbounds [1 x %struct.NET_BLOCK], ptr %30, i64 0, i64 %indvars.iv, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = tail call i64 %49(ptr noundef %51) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %53 = load i32, ptr %28, align 8, !tbaa !14
  %54 = zext i32 %53 to i64
  %55 = icmp ult i64 %indvars.iv.next, %54
  br i1 %55, label %46, label %.loopexit, !llvm.loop !23

.loopexit:                                        ; preds = %46, %.preheader, %42
  tail call void @FreePool(ptr noundef nonnull %0) #2
  br label %56

56:                                               ; preds = %20, %.loopexit
  ret void
}

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 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !8, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !11, i64 16}
!14 = !{!6, !7, i64 40}
!15 = !{!6, !7, i64 32}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !11, i64 72}
!18 = !{!"", !19, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !11, i64 336, !11, i64 344, !11, i64 352, !11, i64 360, !11, i64 368}
!19 = !{!"", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!20 = !{!21, !11, i64 8}
!21 = !{!"", !7, i64 0, !11, i64 8}
!22 = !{!6, !11, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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