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

; 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.MNP_DEVICE_DATA = type { i32, ptr, ptr, %struct._EFI_VLAN_CONFIG_PROTOCOL, i64, ptr, ptr, %struct._LIST_ENTRY, i64, %struct._LIST_ENTRY, i32, ptr, %struct.NET_BUF_QUEUE, i64, ptr, i8, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr }
%struct._EFI_VLAN_CONFIG_PROTOCOL = type { ptr, ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [125 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @MnpAddFreeNbuf(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  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 8, ptr %7) #3
  br label %8

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

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %19

14:                                               ; preds = %11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp eq i32 %17, 1148218957
  br i1 %18, label %20, label %19

19:                                               ; preds = %14, %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 70, ptr noundef @.str.1)
  br label %20

20:                                               ; preds = %19, %14
  br label %21

21:                                               ; preds = %20, %8
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = call zeroext i8 @DebugAssertEnabled()
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %37

27:                                               ; preds = %24
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = icmp ugt i64 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %27
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %31, i32 0, i32 22
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = icmp ugt i32 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %30, %27
  call void @DebugAssert(ptr noundef @.str, i64 noundef 71, ptr noundef @.str.2)
  br label %36

36:                                               ; preds = %35, %30
  br label %37

37:                                               ; preds = %36, %24
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  store i64 0, ptr %5, align 8, !tbaa !9
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %90, %39
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %44, label %93

44:                                               ; preds = %40
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %45, i32 0, i32 22
  %47 = load i32, ptr %46, align 8, !tbaa !17
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %48, i32 0, i32 23
  %50 = load i32, ptr %49, align 4, !tbaa !18
  %51 = add i32 %47, %50
  %52 = call ptr @NetbufAlloc(i32 noundef %51)
  store ptr %52, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %70

55:                                               ; preds = %44
  br label %56

56:                                               ; preds = %55
  %57 = call zeroext i8 @DebugPrintEnabled()
  %58 = icmp ne i8 %57, 0
  br i1 %58, label %59, label %67

59:                                               ; preds = %56
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %60
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3)
  br label %64

64:                                               ; preds = %63, %60
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66, %56
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  store i64 -9223372036854775799, ptr %5, align 8, !tbaa !9
  br label %93

70:                                               ; preds = %44
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %71, i32 0, i32 23
  %73 = load i32, ptr %72, align 4, !tbaa !18
  %74 = icmp ugt i32 %73, 0
  br i1 %74, label %75, label %86

75:                                               ; preds = %70
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %77, i32 0, i32 23
  %79 = load i32, ptr %78, align 4, !tbaa !18
  %80 = call ptr @NetbufAllocSpace(ptr noundef %76, i32 noundef %79, i8 noundef zeroext 0)
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %82, i32 0, i32 23
  %84 = load i32, ptr %83, align 4, !tbaa !18
  %85 = call i32 @NetbufTrim(ptr noundef %81, i32 noundef %84, i8 noundef zeroext 1)
  br label %86

86:                                               ; preds = %75, %70
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %87, i32 0, i32 12
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  call void @NetbufQueAppend(ptr noundef %88, ptr noundef %89)
  br label %90

90:                                               ; preds = %86
  %91 = load i64, ptr %6, align 8, !tbaa !9
  %92 = add i64 %91, 1
  store i64 %92, ptr %6, align 8, !tbaa !9
  br label %40, !llvm.loop !19

93:                                               ; preds = %69, %40
  %94 = load i64, ptr %6, align 8, !tbaa !9
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %95, i32 0, i32 13
  %97 = load i64, ptr %96, align 8, !tbaa !21
  %98 = add i64 %97, %94
  store i64 %98, ptr %96, align 8, !tbaa !21
  %99 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, 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
  ret i64 %99
}

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

declare zeroext i8 @DebugAssertEnabled() #2

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

declare ptr @NetbufAlloc(i32 noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) #2

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) #2

declare void @NetbufQueAppend(ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !10, i64 48, !6, i64 56, !6, i64 64, !15, i64 72, !10, i64 88, !15, i64 96, !13, i64 112, !6, i64 120, !16, i64 128, !10, i64 184, !6, i64 192, !7, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !13, i64 228, !13, i64 232, !13, i64 236, !13, i64 240, !13, i64 244, !6, i64 248, !6, i64 256}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!16 = !{!"", !13, i64 0, !10, i64 8, !15, i64 16, !15, i64 32, !13, i64 48, !13, i64 52}
!17 = !{!12, !13, i64 240}
!18 = !{!12, !13, i64 244}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !10, i64 184}


; 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"

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [125 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @MnpAddFreeNbuf(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %9, label %4

4:                                                ; preds = %2
  %.not23 = icmp eq ptr %0, null
  br i1 %.not23, label %8, label %5

5:                                                ; preds = %4
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1148218957
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %2, %8, %5
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not24 = icmp eq i8 %10, 0
  br i1 %.not24, label %16, label %11

11:                                               ; preds = %9
  %.not25 = icmp eq i64 %1, 0
  br i1 %.not25, label %15, label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds i8, ptr %0, i64 240
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %.not26 = icmp eq i32 %14, 0
  br i1 %.not26, label %15, label %.lr.ph

15:                                               ; preds = %12, %11
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 71, ptr noundef nonnull @.str.2) #2
  br label %16

16:                                               ; preds = %15, %9
  %.not33 = icmp eq i64 %1, 0
  br i1 %.not33, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %16
  %17 = getelementptr inbounds i8, ptr %0, i64 240
  %18 = getelementptr inbounds i8, ptr %0, i64 244
  %19 = getelementptr inbounds i8, ptr %0, i64 128
  br label %20

20:                                               ; preds = %.lr.ph, %37
  %.01932 = phi i64 [ 0, %.lr.ph ], [ %38, %37 ]
  %21 = load i32, ptr %17, align 8, !tbaa !15
  %22 = load i32, ptr %18, align 4, !tbaa !16
  %23 = add i32 %22, %21
  %24 = tail call ptr @NetbufAlloc(i32 noundef %23) #2
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %20
  %27 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not28 = icmp eq i8 %27, 0
  br i1 %.not28, label %.loopexit, label %28

28:                                               ; preds = %26
  %29 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not29 = icmp eq i8 %29, 0
  br i1 %.not29, label %.loopexit, label %30

30:                                               ; preds = %28
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3) #2
  br label %.loopexit

31:                                               ; preds = %20
  %32 = load i32, ptr %18, align 4, !tbaa !16
  %.not27 = icmp eq i32 %32, 0
  br i1 %.not27, label %37, label %33

33:                                               ; preds = %31
  %34 = tail call ptr @NetbufAllocSpace(ptr noundef nonnull %24, i32 noundef %32, i8 noundef zeroext 0) #2
  %35 = load i32, ptr %18, align 4, !tbaa !16
  %36 = tail call i32 @NetbufTrim(ptr noundef nonnull %24, i32 noundef %35, i8 noundef zeroext 1) #2
  br label %37

37:                                               ; preds = %33, %31
  tail call void @NetbufQueAppend(ptr noundef nonnull %19, ptr noundef nonnull %24) #2
  %38 = add nuw i64 %.01932, 1
  %exitcond.not = icmp eq i64 %38, %1
  br i1 %exitcond.not, label %.loopexit, label %20, !llvm.loop !17

.loopexit:                                        ; preds = %37, %16, %26, %30, %28
  %.01931 = phi i64 [ %.01932, %28 ], [ %.01932, %30 ], [ %.01932, %26 ], [ 0, %16 ], [ %1, %37 ]
  %.0 = phi i64 [ -9223372036854775799, %28 ], [ -9223372036854775799, %30 ], [ -9223372036854775799, %26 ], [ 0, %16 ], [ 0, %37 ]
  %39 = getelementptr inbounds i8, ptr %0, i64 184
  %40 = load i64, ptr %39, align 8, !tbaa !19
  %41 = add i64 %40, %.01931
  store i64 %41, ptr %39, align 8, !tbaa !19
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare ptr @NetbufAlloc(i32 noundef) local_unnamed_addr #1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

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

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @NetbufQueAppend(ptr noundef, 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 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 48, !10, i64 56, !10, i64 64, !13, i64 72, !12, i64 88, !13, i64 96, !7, i64 112, !10, i64 120, !14, i64 128, !12, i64 184, !10, i64 192, !8, i64 200, !10, i64 208, !10, i64 216, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !10, i64 248, !10, i64 256}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!14 = !{!"", !7, i64 0, !12, i64 8, !13, i64 16, !13, i64 32, !7, i64 48, !7, i64 52}
!15 = !{!6, !7, i64 240}
!16 = !{!6, !7, i64 244}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !12, i64 184}


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