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

; 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._LIST_ENTRY = type { ptr, ptr }
%struct._IP_IO = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, %union.IP_IO_IP_PROTOCOL, i8, i8, %union.IP_IO_IP_COMPLETION_TOKEN, %struct._LIST_ENTRY, ptr, ptr, ptr, ptr, i8 }
%union.IP_IO_IP_PROTOCOL = type { ptr }
%union.IP_IO_IP_COMPLETION_TOKEN = type { %struct.EFI_IP4_COMPLETION_TOKEN }
%struct.EFI_IP4_COMPLETION_TOKEN = type { ptr, i64, %union.anon }
%union.anon = type { ptr }
%struct._IP_IO_IP_INFO = type { %union.EFI_IP_ADDRESS, %union.IP_IO_IP_MASK, %struct._LIST_ENTRY, ptr, %union.IP_IO_IP_PROTOCOL, %union.IP_IO_IP_COMPLETION_TOKEN, i64, i8 }
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%union.IP_IO_IP_MASK = type { i32 }

@mActiveIpIoList = external dso_local global %struct._LIST_ENTRY, align 8
@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 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

declare zeroext i8 @DebugAssertEnabled() #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @IpIoFindSender(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  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
  br label %13

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

16:                                               ; preds = %13
  %17 = load i8, ptr %6, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 4
  br i1 %19, label %25, label %20

20:                                               ; preds = %16
  %21 = load i8, ptr %6, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = icmp eq i32 %22, 6
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %24, %20, %16
  br label %26

26:                                               ; preds = %25, %13
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr @mActiveIpIoList, align 8, !tbaa !10
  store ptr %29, ptr %8, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %103, %28
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = icmp ne ptr %31, @mActiveIpIoList
  br i1 %32, label %33, label %107

33:                                               ; preds = %30
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = sub i64 %35, 0
  %37 = inttoptr i64 %36 to ptr
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %46

41:                                               ; preds = %33
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = icmp ne ptr %43, %44
  br i1 %45, label %54, label %46

46:                                               ; preds = %41, %33
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._IP_IO, ptr %47, i32 0, i32 14
  %49 = load i8, ptr %48, align 8, !tbaa !12
  %50 = zext i8 %49 to i32
  %51 = load i8, ptr %6, align 1, !tbaa !9
  %52 = zext i8 %51 to i32
  %53 = icmp ne i32 %50, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %46, %41
  br label %103

55:                                               ; preds = %46
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._IP_IO, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct._LIST_ENTRY, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  store ptr %59, ptr %10, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %98, %55
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._IP_IO, ptr %62, i32 0, i32 1
  %64 = icmp ne ptr %61, %63
  br i1 %64, label %65, label %102

65:                                               ; preds = %60
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = ptrtoint ptr %66 to i64
  %68 = sub i64 %67, ptrtoint (ptr getelementptr inbounds (%struct._IP_IO_IP_INFO, ptr null, i32 0, i32 2) to i64)
  %69 = inttoptr i64 %68 to ptr
  store ptr %69, ptr %11, align 8, !tbaa !5
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._IP_IO_IP_INFO, ptr %70, i32 0, i32 7
  %72 = load i8, ptr %71, align 8, !tbaa !15
  %73 = zext i8 %72 to i32
  %74 = icmp eq i32 %73, 4
  br i1 %74, label %75, label %86

75:                                               ; preds = %65
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._IP_IO_IP_INFO, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = call i64 @CompareMem(ptr noundef %77, ptr noundef %78, i64 noundef 4)
  %80 = icmp eq i64 %79, 0
  br i1 %80, label %81, label %85

81:                                               ; preds = %75
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %82, ptr %83, align 8, !tbaa !5
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %84, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %108

85:                                               ; preds = %75
  br label %97

86:                                               ; preds = %65
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._IP_IO_IP_INFO, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = call i64 @CompareMem(ptr noundef %88, ptr noundef %89, i64 noundef 16)
  %91 = icmp eq i64 %90, 0
  br i1 %91, label %92, label %96

92:                                               ; preds = %86
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %93, ptr %94, align 8, !tbaa !5
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %95, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %108

96:                                               ; preds = %86
  br label %97

97:                                               ; preds = %96, %85
  br label %98

98:                                               ; preds = %97
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._LIST_ENTRY, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !10
  store ptr %101, ptr %10, align 8, !tbaa !5
  br label %60, !llvm.loop !18

102:                                              ; preds = %60
  br label %103

103:                                              ; preds = %102, %54
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct._LIST_ENTRY, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !10
  store ptr %106, ptr %8, align 8, !tbaa !5
  br label %30, !llvm.loop !20

107:                                              ; preds = %30
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %108

108:                                              ; preds = %107, %92, %81
  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
  %109 = load ptr, ptr %4, align 8
  ret ptr %109
}

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #1

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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!13, !7, i64 144}
!13 = !{!"_IP_IO", !11, i64 0, !11, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !7, i64 64, !7, i64 65, !7, i64 72, !11, i64 96, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !7, i64 144}
!14 = !{!13, !6, i64 16}
!15 = !{!16, !7, i64 88}
!16 = !{!"_IP_IO_IP_INFO", !7, i64 0, !7, i64 16, !11, i64 24, !6, i64 40, !7, i64 48, !7, i64 56, !17, i64 80, !7, i64 88}
!17 = !{!"long long", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@mActiveIpIoList = external dso_local global %struct._LIST_ENTRY, align 8
@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @IpIoFindSender(ptr nocapture noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  %5 = and i8 %1, -3
  %or.cond = icmp eq i8 %5, 4
  %or.cond36 = or i1 %or.cond, %.not
  br i1 %or.cond36, label %7, label %6

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

7:                                                ; preds = %6, %3
  %.02945 = load ptr, ptr @mActiveIpIoList, align 8, !tbaa !5
  %.not3146 = icmp eq ptr %.02945, @mActiveIpIoList
  br i1 %.not3146, label %.loopexit38, label %.lr.ph48

.lr.ph48:                                         ; preds = %7, %.loopexit
  %.02947 = phi ptr [ %.029, %.loopexit ], [ %.02945, %7 ]
  %8 = load ptr, ptr %0, align 8, !tbaa !10
  %.not32 = icmp eq ptr %8, null
  %.not33 = icmp eq ptr %8, %.02947
  %or.cond37 = or i1 %.not32, %.not33
  br i1 %or.cond37, label %9, label %.loopexit

9:                                                ; preds = %.lr.ph48
  %10 = getelementptr inbounds i8, ptr %.02947, i64 144
  %11 = load i8, ptr %10, align 8, !tbaa !11
  %.not34 = icmp eq i8 %11, %1
  br i1 %.not34, label %12, label %.loopexit

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %.02947, i64 16
  %.02842 = load ptr, ptr %13, align 8, !tbaa !5
  %.not3543 = icmp eq ptr %.02842, %13
  br i1 %.not3543, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %26
  %.02844 = phi ptr [ %.028, %26 ], [ %.02842, %12 ]
  %14 = ptrtoint ptr %.02844 to i64
  %15 = add i64 %14, -24
  %16 = inttoptr i64 %15 to ptr
  %17 = getelementptr inbounds i8, ptr %16, i64 88
  %18 = load i8, ptr %17, align 8, !tbaa !13
  %19 = icmp eq i8 %18, 4
  br i1 %19, label %20, label %23

20:                                               ; preds = %.lr.ph
  %21 = tail call i64 @CompareMem(ptr noundef nonnull %16, ptr noundef %2, i64 noundef 4) #2
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %.loopexit38.sink.split, label %26

23:                                               ; preds = %.lr.ph
  %24 = tail call i64 @CompareMem(ptr noundef nonnull %16, ptr noundef %2, i64 noundef 16) #2
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %.loopexit38.sink.split, label %26

26:                                               ; preds = %20, %23
  %.028 = load ptr, ptr %.02844, align 8, !tbaa !5
  %.not35 = icmp eq ptr %.028, %13
  br i1 %.not35, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %26, %12, %.lr.ph48, %9
  %.029 = load ptr, ptr %.02947, align 8, !tbaa !5
  %.not31 = icmp eq ptr %.029, @mActiveIpIoList
  br i1 %.not31, label %.loopexit38, label %.lr.ph48, !llvm.loop !18

.loopexit38.sink.split:                           ; preds = %23, %20
  store ptr %.02947, ptr %0, align 8, !tbaa !10
  br label %.loopexit38

.loopexit38:                                      ; preds = %.loopexit, %.loopexit38.sink.split, %7
  %.0 = phi ptr [ null, %7 ], [ %16, %.loopexit38.sink.split ], [ null, %.loopexit ]
  ret ptr %.0
}

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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 = !{!"_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 = !{!7, !7, i64 0}
!11 = !{!12, !8, i64 144}
!12 = !{!"_IP_IO", !6, i64 0, !6, i64 16, !7, i64 32, !7, i64 40, !7, i64 48, !8, i64 56, !8, i64 64, !8, i64 65, !8, i64 72, !6, i64 96, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !8, i64 144}
!13 = !{!14, !8, i64 88}
!14 = !{!"_IP_IO_IP_INFO", !8, i64 0, !8, i64 16, !6, i64 24, !7, i64 40, !8, i64 48, !8, i64 56, !15, i64 80, !8, i64 88}
!15 = !{!"long long", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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