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

; 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 }
%struct.MNP_SERVICE_DATA = type { i32, %struct._LIST_ENTRY, ptr, ptr, %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr, %struct._LIST_ENTRY, i64, i32, i16, i8 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [21 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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, 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 ptr @MnpFindServiceData(ptr noundef %0, i16 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %9, i32 0, i32 7
  %11 = getelementptr inbounds %struct._LIST_ENTRY, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %6, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %49, %2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %15, i32 0, i32 7
  %17 = icmp ne ptr %14, %16
  br i1 %17, label %18, label %53

18:                                               ; preds = %13
  %19 = call zeroext i8 @DebugAssertEnabled()
  %20 = zext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %32

22:                                               ; preds = %18
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = ptrtoint ptr %23 to i64
  %25 = sub i64 %24, ptrtoint (ptr getelementptr inbounds (%struct.MNP_SERVICE_DATA, ptr null, i32 0, i32 1) to i64)
  %26 = inttoptr i64 %25 to ptr
  %27 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !18
  %29 = icmp ne i32 %28, 1399877197
  br i1 %29, label %30, label %32

30:                                               ; preds = %22
  call void @DebugAssert(ptr noundef @.str, i64 noundef 768, ptr noundef @.str.16)
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  br label %37

32:                                               ; preds = %22, %18
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = sub i64 %34, ptrtoint (ptr getelementptr inbounds (%struct.MNP_SERVICE_DATA, ptr null, i32 0, i32 1) to i64)
  %36 = inttoptr i64 %35 to ptr
  br label %37

37:                                               ; preds = %32, %30
  %38 = phi ptr [ %31, %30 ], [ %36, %32 ]
  store ptr %38, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %39, i32 0, i32 9
  %41 = load i16, ptr %40, align 4, !tbaa !21
  %42 = zext i16 %41 to i32
  %43 = load i16, ptr %5, align 2, !tbaa !9
  %44 = zext i16 %43 to i32
  %45 = icmp eq i32 %42, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %37
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %47, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %54

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._LIST_ENTRY, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !22
  store ptr %52, ptr %6, align 8, !tbaa !5
  br label %13, !llvm.loop !23

53:                                               ; preds = %13
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %54

54:                                               ; preds = %53, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %55 = load ptr, ptr %3, align 8
  ret ptr %55
}

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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 72}
!12 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !15, i64 48, !6, i64 56, !6, i64 64, !16, i64 72, !15, i64 88, !16, i64 96, !13, i64 112, !6, i64 120, !17, i64 128, !15, 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 = !{!"long long", !7, i64 0}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"", !13, i64 0, !15, i64 8, !16, i64 16, !16, i64 32, !13, i64 48, !13, i64 52}
!18 = !{!19, !13, i64 0}
!19 = !{!"", !13, i64 0, !16, i64 8, !6, i64 24, !6, i64 32, !20, i64 40, !6, i64 56, !16, i64 64, !15, i64 80, !13, i64 88, !10, i64 92, !7, i64 94}
!20 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!21 = !{!19, !10, i64 92}
!22 = !{!16, !6, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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"

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [21 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 @MnpFindServiceData(ptr noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  br label %4

4:                                                ; preds = %._crit_edge, %2
  %.010.in = phi ptr [ %3, %2 ], [ %.010, %._crit_edge ]
  %.010 = load ptr, ptr %.010.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.010, %3
  br i1 %.not, label %14, label %5

5:                                                ; preds = %4
  %6 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not11 = icmp eq i8 %6, 0
  %.pre = ptrtoint ptr %.010 to i64
  %.pre13 = add i64 %.pre, -8
  %.pre15 = inttoptr i64 %.pre13 to ptr
  br i1 %.not11, label %._crit_edge, label %7

7:                                                ; preds = %5
  %8 = load i32, ptr %.pre15, align 8, !tbaa !10
  %.not12 = icmp eq i32 %8, 1399877197
  br i1 %.not12, label %._crit_edge, label %9

9:                                                ; preds = %7
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 768, ptr noundef nonnull @.str.16) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %7, %9
  %10 = phi ptr [ %.010, %9 ], [ %.pre15, %7 ], [ %.pre15, %5 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 92
  %12 = load i16, ptr %11, align 4, !tbaa !16
  %13 = icmp eq i16 %12, %1
  br i1 %13, label %14, label %4, !llvm.loop !17

14:                                               ; preds = %4, %._crit_edge
  %.0 = phi ptr [ %10, %._crit_edge ], [ null, %4 ]
  ret ptr %.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 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !6, i64 8, !7, i64 24, !7, i64 32, !13, i64 40, !7, i64 56, !6, i64 64, !14, i64 80, !12, i64 88, !15, i64 92, !8, i64 94}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !7, i64 0, !7, i64 8}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = !{!11, !15, i64 92}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass