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

; 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.s_pxe_cdb = type { i16, i16, i16, i16, i64, i64, i16, i16, i16, i16 }
%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 global ptr, align 8
@UNDI32DeviceList = external global [16 x ptr], align 16

; 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 @UNDI_APIEntry_new(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 1, ptr %5, align 4
  br label %43

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

27:                                               ; preds = %9
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.s_pxe_cdb, ptr %28, i32 0, i32 7
  store i16 -32768, ptr %29, align 1, !tbaa !18
  %30 = load ptr, ptr %3, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.s_pxe_cdb, ptr %30, i32 0, i32 6
  store i16 1, ptr %31, align 1, !tbaa !19
  store i32 1, ptr %5, align 4
  br label %43

32:                                               ; preds = %9
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.s_pxe_cdb, ptr %33, i32 0, i32 8
  %35 = load i16, ptr %34, align 1, !tbaa !11
  %36 = zext i16 %35 to i64
  %37 = getelementptr inbounds [16 x ptr], ptr @UNDI32DeviceList, i64 0, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.UNDI32_DEV, ptr %38, i32 0, i32 5
  store ptr %39, ptr %4, align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.s_data_instance, ptr %40, i32 0, i32 55
  store i8 49, ptr %41, align 4, !tbaa !20
  %42 = load i64, ptr %2, align 8, !tbaa !5
  call void @UNDI_APIEntry_Common(i64 noundef %42)
  store i32 0, ptr %5, align 4
  br label %43

43:                                               ; preds = %32, %27, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  %44 = load i32, ptr %5, align 4
  switch i32 %44, label %46 [
    i32 0, label %45
    i32 1, label %45
  ]

45:                                               ; preds = %43, %43
  ret void

46:                                               ; preds = %43
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local void @UNDI_APIEntry_Common(i64 noundef) #1

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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 28}
!12 = !{!"s_pxe_cdb", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 26, !13, i64 28, !13, i64 30}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !7, i64 7}
!15 = !{!"s_pxe_sw_undi", !16, 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, !16, i64 12, !6, i64 16, !7, i64 24, !7, i64 27, !7, i64 28}
!16 = !{!"int", !7, i64 0}
!17 = !{!15, !7, i64 10}
!18 = !{!12, !13, i64 26}
!19 = !{!12, !13, i64 24}
!20 = !{!21, !7, i64 1540}
!21 = !{!"s_data_instance", !13, i64 0, !13, i64 2, !7, i64 4, !7, i64 5, !13, i64 6, !13, i64 8, !13, i64 10, !13, i64 12, !13, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !16, i64 880, !16, i64 884, !13, i64 888, !13, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !13, i64 896, !13, i64 898, !13, i64 900, !13, i64 902, !16, i64 904, !16, i64 908, !13, i64 912, !13, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !13, i64 922, !16, i64 924, !10, i64 928, !10, i64 936, !10, i64 944, !10, i64 952, !10, i64 960, !10, i64 968, !6, i64 976, !6, i64 984, !6, i64 992, !6, i64 1000, !6, i64 1008, !7, i64 1016, !13, i64 1528, !13, i64 1530, !13, i64 1532, !13, i64 1534, !7, i64 1536, !7, i64 1537, !7, i64 1538, !7, i64 1539, !7, i64 1540, !7, i64 1541, !22, i64 1544, !6, i64 1808, !10, i64 1816, !6, i64 1824, !10, i64 1832, !10, i64 1840, !10, i64 1848, !10, i64 1856, !10, i64 1864, !10, i64 1872, !10, i64 1880, !10, i64 1888, !10, i64 1896, !10, i64 1904, !10, i64 1912}
!22 = !{!"mc", !7, i64 0, !13, i64 6, !7, i64 8}


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

@pxe_31 = external local_unnamed_addr global ptr, align 8
@UNDI32DeviceList = external local_unnamed_addr global [16 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local void @UNDI_APIEntry_new(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i64 %0, 0
  br i1 %2, label %25, label %3

3:                                                ; preds = %1
  %4 = inttoptr i64 %0 to ptr
  %5 = getelementptr inbounds i8, ptr %4, i64 28
  %6 = load i16, ptr %5, align 1, !tbaa !5
  %7 = zext i16 %6 to i32
  %8 = load ptr, ptr @pxe_31, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %8, i64 7
  %10 = load i8, ptr %9, align 1, !tbaa !13
  %11 = zext i8 %10 to i32
  %12 = getelementptr inbounds i8, ptr %8, i64 10
  %13 = load i8, ptr %12, align 1, !tbaa !16
  %14 = zext i8 %13 to i32
  %15 = shl nuw nsw i32 %14, 8
  %16 = or disjoint i32 %15, %11
  %.not = icmp ugt i32 %16, %7
  br i1 %.not, label %20, label %17

17:                                               ; preds = %3
  %18 = getelementptr inbounds i8, ptr %4, i64 26
  store i16 -32768, ptr %18, align 1, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %4, i64 24
  store i16 1, ptr %19, align 1, !tbaa !18
  br label %25

20:                                               ; preds = %3
  %21 = zext i16 %6 to i64
  %22 = getelementptr inbounds [16 x ptr], ptr @UNDI32DeviceList, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %23, i64 1612
  store i8 49, ptr %24, align 4, !tbaa !19
  tail call void @UNDI_APIEntry_Common(i64 noundef %0)
  br label %25

25:                                               ; preds = %1, %20, %17
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @UNDI_APIEntry_Common(i64 noundef) local_unnamed_addr #0

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

!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 28}
!6 = !{!"s_pxe_cdb", !7, i64 0, !7, i64 2, !7, i64 4, !7, i64 6, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 26, !7, i64 28, !7, i64 30}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !8, i64 7}
!14 = !{!"s_pxe_sw_undi", !15, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !15, i64 12, !10, i64 16, !8, i64 24, !8, i64 27, !8, i64 28}
!15 = !{!"int", !8, i64 0}
!16 = !{!14, !8, i64 10}
!17 = !{!6, !7, i64 26}
!18 = !{!6, !7, i64 24}
!19 = !{!20, !8, i64 1540}
!20 = !{!"s_data_instance", !7, i64 0, !7, i64 2, !8, i64 4, !8, i64 5, !7, i64 6, !7, i64 8, !7, i64 10, !7, i64 12, !7, i64 14, !8, i64 16, !8, i64 48, !8, i64 80, !8, i64 112, !8, i64 368, !15, i64 880, !15, i64 884, !7, i64 888, !7, i64 890, !8, i64 892, !8, i64 893, !8, i64 894, !8, i64 895, !7, i64 896, !7, i64 898, !7, i64 900, !7, i64 902, !15, i64 904, !15, i64 908, !7, i64 912, !7, i64 914, !8, i64 916, !8, i64 920, !8, i64 921, !7, i64 922, !15, i64 924, !12, i64 928, !12, i64 936, !12, i64 944, !12, i64 952, !12, i64 960, !12, i64 968, !10, i64 976, !10, i64 984, !10, i64 992, !10, i64 1000, !10, i64 1008, !8, i64 1016, !7, i64 1528, !7, i64 1530, !7, i64 1532, !7, i64 1534, !8, i64 1536, !8, i64 1537, !8, i64 1538, !8, i64 1539, !8, i64 1540, !8, i64 1541, !21, i64 1544, !10, i64 1808, !12, i64 1816, !10, i64 1824, !12, i64 1832, !12, i64 1840, !12, i64 1848, !12, i64 1856, !12, i64 1864, !12, i64 1872, !12, i64 1880, !12, i64 1888, !12, i64 1896, !12, i64 1904, !12, i64 1912}
!21 = !{!"mc", !8, i64 0, !7, i64 6, !8, i64 8}


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