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

; 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_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%struct.IP4_CLIP_INFO = type { i64, i64, i64, i64, i64, i32, i64 }

@.str = external hidden unnamed_addr constant [150 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 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
define dso_local void @Ip4TrimPacket(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.NET_BUF, ptr %9, i32 0, i32 6
  %11 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  store ptr %11, ptr %7, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %3
  %13 = call zeroext i8 @DebugAssertEnabled()
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %29

15:                                               ; preds = %12
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %19, i32 0, i32 4
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %22 = add nsw i64 %18, %21
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %23, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = icmp eq i64 %22, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %15
  call void @DebugAssert(ptr noundef @.str, i64 noundef 161, ptr noundef @.str.1)
  br label %28

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

29:                                               ; preds = %28, %12
  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 %49

35:                                               ; preds = %32
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %36, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %41, label %47

41:                                               ; preds = %35
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %43, i32 0, i32 3
  %45 = load i64, ptr %44, align 8, !tbaa !15
  %46 = icmp slt i64 %42, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %41, %35
  call void @DebugAssert(ptr noundef @.str, i64 noundef 162, ptr noundef @.str.2)
  br label %48

48:                                               ; preds = %47, %41
  br label %49

49:                                               ; preds = %48, %32
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %52, i32 0, i32 2
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = icmp slt i64 %54, %55
  br i1 %56, label %57, label %75

57:                                               ; preds = %51
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %59, i32 0, i32 2
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = sub nsw i64 %58, %61
  store i64 %62, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = trunc i64 %64 to i32
  %66 = call i32 @NetbufTrim(ptr noundef %63, i32 noundef %65, i8 noundef zeroext 1)
  %67 = load i64, ptr %5, align 8, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %68, i32 0, i32 2
  store i64 %67, ptr %69, align 8, !tbaa !11
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %71, i32 0, i32 4
  %73 = load i64, ptr %72, align 8, !tbaa !14
  %74 = sub nsw i64 %73, %70
  store i64 %74, ptr %72, align 8, !tbaa !14
  br label %75

75:                                               ; preds = %57, %51
  %76 = load i64, ptr %6, align 8, !tbaa !9
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %77, i32 0, i32 3
  %79 = load i64, ptr %78, align 8, !tbaa !15
  %80 = icmp slt i64 %76, %79
  br i1 %80, label %81, label %99

81:                                               ; preds = %75
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %83, i32 0, i32 3
  %85 = load i64, ptr %84, align 8, !tbaa !15
  %86 = sub nsw i64 %82, %85
  store i64 %86, ptr %8, align 8, !tbaa !9
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i64, ptr %8, align 8, !tbaa !9
  %89 = trunc i64 %88 to i32
  %90 = call i32 @NetbufTrim(ptr noundef %87, i32 noundef %89, i8 noundef zeroext 0)
  %91 = load i64, ptr %6, align 8, !tbaa !9
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %92, i32 0, i32 3
  store i64 %91, ptr %93, align 8, !tbaa !15
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %95, i32 0, i32 4
  %97 = load i64, ptr %96, align 8, !tbaa !14
  %98 = sub nsw i64 %97, %94
  store i64 %98, ptr %96, align 8, !tbaa !14
  br label %99

99:                                               ; preds = %81, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare zeroext i8 @DebugAssertEnabled() #2

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

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

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 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !10, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 32}
!15 = !{!12, !10, i64 24}


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

; Function Attrs: nounwind uwtable
define dso_local void @Ip4TrimPacket(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %15, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = add nsw i64 %9, %7
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = icmp eq i64 %10, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %3, %14, %5
  %16 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not30 = icmp eq i8 %16, 0
  br i1 %.not30, label %26, label %17

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 72
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = icmp slt i64 %19, %2
  br i1 %20, label %21, label %25

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 80
  %23 = load i64, ptr %22, align 8, !tbaa !12
  %24 = icmp sgt i64 %23, %1
  br i1 %24, label %26, label %25

25:                                               ; preds = %21, %17
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 162, ptr noundef nonnull @.str.2) #2
  br label %26

26:                                               ; preds = %21, %25, %15
  %27 = getelementptr inbounds i8, ptr %0, i64 72
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = icmp slt i64 %28, %1
  br i1 %29, label %30, label %37

30:                                               ; preds = %26
  %31 = sub nsw i64 %1, %28
  %32 = trunc i64 %31 to i32
  %33 = tail call i32 @NetbufTrim(ptr noundef nonnull %0, i32 noundef %32, i8 noundef zeroext 1) #2
  store i64 %1, ptr %27, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 88
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = sub nsw i64 %35, %31
  store i64 %36, ptr %34, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %30, %26
  %38 = getelementptr inbounds i8, ptr %0, i64 80
  %39 = load i64, ptr %38, align 8, !tbaa !12
  %40 = icmp sgt i64 %39, %2
  br i1 %40, label %41, label %48

41:                                               ; preds = %37
  %42 = sub nsw i64 %2, %39
  %43 = trunc i64 %42 to i32
  %44 = tail call i32 @NetbufTrim(ptr noundef nonnull %0, i32 noundef %43, i8 noundef zeroext 0) #2
  store i64 %2, ptr %38, align 8, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %0, i64 88
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = sub nsw i64 %46, %42
  store i64 %47, ptr %45, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %41, %37
  ret void
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) 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 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 48}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 32}
!12 = !{!6, !7, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass