; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Pci (UfsHcMap)

; 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._UFS_HOST_CONTROLLER_PRIVATE_DATA = type { i32, ptr, %struct._EDKII_UFS_HOST_CONTROLLER_PROTOCOL, ptr, i64 }
%struct._EDKII_UFS_HOST_CONTROLLER_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_PCI_IO_PROTOCOL = type { ptr, ptr, %struct.EFI_PCI_IO_PROTOCOL_ACCESS, %struct.EFI_PCI_IO_PROTOCOL_ACCESS, %struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.EFI_PCI_IO_PROTOCOL_ACCESS = type { ptr, ptr }
%struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [148 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @UfsHcMap(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %32, label %20

20:                                               ; preds = %6
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %32, label %23

23:                                               ; preds = %20
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %32, label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %32, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %29, %26, %23, %20, %6
  store i64 -9223372036854775806, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %68

33:                                               ; preds = %29
  %34 = call zeroext i8 @DebugAssertEnabled()
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %47

37:                                               ; preds = %33
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = ptrtoint ptr %38 to i64
  %40 = sub i64 %39, ptrtoint (ptr getelementptr inbounds (%struct._UFS_HOST_CONTROLLER_PRIVATE_DATA, ptr null, i32 0, i32 2) to i64)
  %41 = inttoptr i64 %40 to ptr
  %42 = getelementptr inbounds %struct._UFS_HOST_CONTROLLER_PRIVATE_DATA, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = icmp ne i32 %43, 1213417045
  br i1 %44, label %45, label %47

45:                                               ; preds = %37
  call void @DebugAssert(ptr noundef @.str, i64 noundef 127, ptr noundef @.str.1)
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  br label %52

47:                                               ; preds = %37, %33
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = ptrtoint ptr %48 to i64
  %50 = sub i64 %49, ptrtoint (ptr getelementptr inbounds (%struct._UFS_HOST_CONTROLLER_PRIVATE_DATA, ptr null, i32 0, i32 2) to i64)
  %51 = inttoptr i64 %50 to ptr
  br label %52

52:                                               ; preds = %47, %45
  %53 = phi ptr [ %46, %45 ], [ %51, %47 ]
  store ptr %53, ptr %14, align 8, !tbaa !5
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._UFS_HOST_CONTROLLER_PRIVATE_DATA, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  store ptr %56, ptr %15, align 8, !tbaa !5
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %57, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = load ptr, ptr %15, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = call i64 %59(ptr noundef %60, i32 noundef %61, ptr noundef %62, ptr noundef %63, ptr noundef %64, ptr noundef %65)
  store i64 %66, ptr %16, align 8, !tbaa !19
  %67 = load i64, ptr %16, align 8, !tbaa !19
  store i64 %67, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %68

68:                                               ; preds = %52, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %69 = load i64, ptr %7, align 8
  ret i64 %69
}

; 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

; 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_UFS_HOST_CONTROLLER_PRIVATE_DATA", !10, i64 0, !6, i64 8, !13, i64 16, !6, i64 64, !14, i64 72}
!13 = !{!"_EDKII_UFS_HOST_CONTROLLER_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!14 = !{!"long long", !7, i64 0}
!15 = !{!12, !6, i64 64}
!16 = !{!17, !6, i64 72}
!17 = !{!"_EFI_PCI_IO_PROTOCOL", !6, i64 0, !6, i64 8, !18, i64 16, !18, i64 32, !18, i64 48, !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, !14, i64 144, !6, i64 152}
!18 = !{!"", !6, i64 0, !6, i64 8}
!19 = !{!14, !14, i64 0}


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

; Function Attrs: nounwind uwtable
define dso_local i64 @UfsHcMap(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %8 = insertelement <4 x ptr> %7, ptr %2, i64 1
  %9 = insertelement <4 x ptr> %8, ptr %3, i64 2
  %10 = insertelement <4 x ptr> %9, ptr %4, i64 3
  %11 = icmp eq <4 x ptr> %10, zeroinitializer
  %12 = icmp eq ptr %5, null
  %13 = bitcast <4 x i1> %11 to i4
  %14 = icmp ne i4 %13, 0
  %op.rdx = or i1 %14, %12
  br i1 %op.rdx, label %26, label %15

15:                                               ; preds = %6
  %16 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %16, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre29 = add i64 %.pre, -16
  %.pre31 = inttoptr i64 %.pre29 to ptr
  br i1 %.not, label %._crit_edge, label %17

17:                                               ; preds = %15
  %18 = load i32, ptr %.pre31, align 8, !tbaa !5
  %.not28 = icmp eq i32 %18, 1213417045
  br i1 %.not28, label %._crit_edge, label %19

19:                                               ; preds = %17
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 127, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %15, %17, %19
  %20 = phi ptr [ %0, %19 ], [ %.pre31, %17 ], [ %.pre31, %15 ]
  %21 = getelementptr inbounds i8, ptr %20, i64 64
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %22, i64 72
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = tail call i64 %24(ptr noundef %22, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5) #2
  br label %26

26:                                               ; preds = %6, %._crit_edge
  %.0 = phi i64 [ %25, %._crit_edge ], [ -9223372036854775806, %6 ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 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 = !{!"_UFS_HOST_CONTROLLER_PRIVATE_DATA", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 64, !12, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EDKII_UFS_HOST_CONTROLLER_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!"long long", !8, i64 0}
!13 = !{!6, !10, i64 64}
!14 = !{!15, !10, i64 72}
!15 = !{!"_EFI_PCI_IO_PROTOCOL", !10, i64 0, !10, i64 8, !16, i64 16, !16, i64 32, !16, i64 48, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !12, i64 144, !10, i64 152}
!16 = !{!"", !10, i64 0, !10, i64 8}


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