; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg (UndiNotifyVirtual)

; 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.UNDI_CALL_TABLE = type { i16, i16, i16, i16, ptr }
%struct.s_pxe_sw_undi = type { i32, i8, i8, i8, i8, i8, i8, i8, i8, i32, i64, [3 x i8], i8, [1 x i32] }
%struct.UNDI32_DEV = type { i64, %struct._EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL, ptr, ptr, ptr, %struct.s_data_instance }
%struct._EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL = type { i64, i64, i64, i32, [4 x i8], i8, i8, i8, i8, i16 }
%struct.s_data_instance = type { i16, i16, i8, i8, i16, i16, i16, i16, i16, [32 x i8], [32 x i8], [32 x i8], [64 x i32], [128 x i32], i32, i32, i16, i16, i8, i8, i8, i8, i16, i16, i16, i16, i32, i32, i16, i16, [2 x i16], i8, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, [64 x i64], i16, i16, i16, i16, i8, i8, i8, i8, i8, [3 x i8], %struct.mc, i64, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.mc = type { [3 x i16], i16, [8 x [32 x i8]] }

@pxe_31 = external dso_local global ptr, align 8
@UNDI32DeviceList = external dso_local global [16 x ptr], align 16
@api_table = external global [0 x %struct.UNDI_CALL_TABLE], align 8

; Function Attrs: nounwind uwtable
define dso_local void @UndiNotifyVirtual(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %47

9:                                                ; preds = %2
  %10 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef %6)
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %12

12:                                               ; preds = %39, %9
  %13 = load i16, ptr %5, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.s_pxe_sw_undi, ptr %15, i32 0, i32 4
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_pxe_sw_undi, ptr %19, i32 0, i32 7
  %21 = load i8, ptr %20, align 1, !tbaa !15
  %22 = zext i8 %21 to i32
  %23 = shl i32 %22, 8
  %24 = or i32 %18, %23
  %25 = icmp slt i32 %14, %24
  br i1 %25, label %26, label %42

26:                                               ; preds = %12
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = ptrtoint ptr %27 to i64
  %29 = load i16, ptr %5, align 2, !tbaa !9
  %30 = zext i16 %29 to i64
  %31 = getelementptr inbounds [16 x ptr], ptr @UNDI32DeviceList, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.UNDI32_DEV, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %struct._EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL, ptr %33, i32 0, i32 1
  store i64 %28, ptr %34, align 8, !tbaa !16
  %35 = load i16, ptr %5, align 2, !tbaa !9
  %36 = zext i16 %35 to i64
  %37 = getelementptr inbounds [16 x ptr], ptr @UNDI32DeviceList, i64 0, i64 %36
  %38 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef %37)
  br label %39

39:                                               ; preds = %26
  %40 = load i16, ptr %5, align 2, !tbaa !9
  %41 = add i16 %40, 1
  store i16 %41, ptr %5, align 2, !tbaa !9
  br label %12, !llvm.loop !21

42:                                               ; preds = %12
  %43 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_pxe_sw_undi, ptr %43, i32 0, i32 10
  %45 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef %44)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %46, ptr @pxe_31, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %42, %2
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %48

48:                                               ; preds = %58, %47
  %49 = load i16, ptr %5, align 2, !tbaa !9
  %50 = zext i16 %49 to i32
  %51 = icmp sle i32 %50, 17
  br i1 %51, label %52, label %61

52:                                               ; preds = %48
  %53 = load i16, ptr %5, align 2, !tbaa !9
  %54 = zext i16 %53 to i64
  %55 = getelementptr inbounds [0 x %struct.UNDI_CALL_TABLE], ptr @api_table, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.UNDI_CALL_TABLE, ptr %55, i32 0, i32 4
  %57 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef %56)
  br label %58

58:                                               ; preds = %52
  %59 = load i16, ptr %5, align 2, !tbaa !9
  %60 = add i16 %59, 1
  store i16 %60, ptr %5, align 2, !tbaa !9
  br label %48, !llvm.loop !23

61:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  ret void
}

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

declare i64 @EfiConvertPointer(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 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 7}
!12 = !{!"s_pxe_sw_undi", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !13, i64 12, !14, i64 16, !7, i64 24, !7, i64 27, !7, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!12, !7, i64 10}
!16 = !{!17, !14, i64 16}
!17 = !{!"", !14, i64 0, !18, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !19, i64 72}
!18 = !{!"_EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL", !14, i64 0, !14, i64 8, !14, i64 16, !13, i64 24, !7, i64 28, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !10, i64 36}
!19 = !{!"s_data_instance", !10, i64 0, !10, i64 2, !7, i64 4, !7, i64 5, !10, i64 6, !10, i64 8, !10, i64 10, !10, i64 12, !10, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !13, i64 880, !13, i64 884, !10, i64 888, !10, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !10, i64 896, !10, i64 898, !10, i64 900, !10, i64 902, !13, i64 904, !13, i64 908, !10, i64 912, !10, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !10, i64 922, !13, i64 924, !6, i64 928, !6, i64 936, !6, i64 944, !6, i64 952, !6, i64 960, !6, i64 968, !14, i64 976, !14, i64 984, !14, i64 992, !14, i64 1000, !14, i64 1008, !7, i64 1016, !10, i64 1528, !10, i64 1530, !10, i64 1532, !10, i64 1534, !7, i64 1536, !7, i64 1537, !7, i64 1538, !7, i64 1539, !7, i64 1540, !7, i64 1541, !20, i64 1544, !14, i64 1808, !6, i64 1816, !14, i64 1824, !6, i64 1832, !6, i64 1840, !6, i64 1848, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888, !6, i64 1896, !6, i64 1904, !6, i64 1912}
!20 = !{!"mc", !7, i64 0, !10, i64 6, !7, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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.UNDI_CALL_TABLE = type { i16, i16, i16, i16, ptr }

@pxe_31 = external dso_local local_unnamed_addr global ptr, align 8
@UNDI32DeviceList = external dso_local global [16 x ptr], align 16
@api_table = external global [0 x %struct.UNDI_CALL_TABLE], align 8

; Function Attrs: nounwind uwtable
define dso_local void @UndiNotifyVirtual(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %38, label %5

5:                                                ; preds = %2
  store ptr %4, ptr %3, align 8, !tbaa !5
  %6 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull %3) #3
  %7 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 7
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = getelementptr inbounds i8, ptr %7, i64 10
  %12 = load i8, ptr %11, align 1, !tbaa !13
  %13 = zext i8 %12 to i32
  %14 = shl nuw nsw i32 %13, 8
  %15 = or disjoint i32 %14, %10
  %.not10 = icmp eq i32 %15, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.08 = phi i16 [ %23, %.lr.ph ], [ 0, %5 ]
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = zext i16 %.08 to i64
  %19 = getelementptr inbounds [16 x ptr], ptr @UNDI32DeviceList, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store i64 %17, ptr %21, align 8, !tbaa !14
  %22 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull %19) #3
  %23 = add nuw i16 %.08, 1
  %24 = zext i16 %23 to i32
  %25 = load ptr, ptr @pxe_31, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 7
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = getelementptr inbounds i8, ptr %25, i64 10
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = shl nuw nsw i32 %31, 8
  %33 = or disjoint i32 %32, %28
  %34 = icmp ugt i32 %33, %24
  br i1 %34, label %.lr.ph, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.lcssa = phi ptr [ %7, %5 ], [ %25, %.lr.ph ]
  %35 = getelementptr inbounds i8, ptr %.lcssa, i64 16
  %36 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull %35) #3
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %37, ptr @pxe_31, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %._crit_edge, %2
  %39 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 8)) #3
  %40 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 24)) #3
  %41 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 40)) #3
  %42 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 56)) #3
  %43 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 72)) #3
  %44 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 88)) #3
  %45 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 104)) #3
  %46 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 120)) #3
  %47 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 136)) #3
  %48 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 152)) #3
  %49 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 168)) #3
  %50 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 184)) #3
  %51 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 200)) #3
  %52 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 216)) #3
  %53 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 232)) #3
  %54 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 248)) #3
  %55 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 264)) #3
  %56 = call i64 @EfiConvertPointer(i64 noundef 1, ptr noundef nonnull getelementptr inbounds (i8, ptr @api_table, i64 280)) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret void
}

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

declare i64 @EfiConvertPointer(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress 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, !7, i64 7}
!10 = !{!"s_pxe_sw_undi", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !11, i64 12, !12, i64 16, !7, i64 24, !7, i64 27, !7, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !7, i64 10}
!14 = !{!15, !12, i64 16}
!15 = !{!"", !12, i64 0, !16, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !18, i64 72}
!16 = !{!"_EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL", !12, i64 0, !12, i64 8, !12, i64 16, !11, i64 24, !7, i64 28, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !17, i64 36}
!17 = !{!"short", !7, i64 0}
!18 = !{!"s_data_instance", !17, i64 0, !17, i64 2, !7, i64 4, !7, i64 5, !17, i64 6, !17, i64 8, !17, i64 10, !17, i64 12, !17, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !11, i64 880, !11, i64 884, !17, i64 888, !17, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !17, i64 896, !17, i64 898, !17, i64 900, !17, i64 902, !11, i64 904, !11, i64 908, !17, i64 912, !17, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !17, i64 922, !11, i64 924, !6, i64 928, !6, i64 936, !6, i64 944, !6, i64 952, !6, i64 960, !6, i64 968, !12, i64 976, !12, i64 984, !12, i64 992, !12, i64 1000, !12, i64 1008, !7, i64 1016, !17, i64 1528, !17, i64 1530, !17, i64 1532, !17, i64 1534, !7, i64 1536, !7, i64 1537, !7, i64 1538, !7, i64 1539, !7, i64 1540, !7, i64 1541, !19, i64 1544, !12, i64 1808, !6, i64 1816, !12, i64 1824, !6, i64 1832, !6, i64 1840, !6, i64 1848, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888, !6, i64 1896, !6, i64 1904, !6, i64 1912}
!19 = !{!"mc", !7, i64 0, !17, i64 6, !7, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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