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

; 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_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]] }
%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 }

; 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 @TmpMemIo(i64 noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i64 noundef %3, i64 noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store i8 %2, ptr %8, align 1, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store i32 0, ptr %11, align 4, !tbaa !10
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = inttoptr i64 %13 to ptr
  store ptr %14, ptr %12, align 8, !tbaa !12
  %15 = load i8, ptr %8, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  switch i32 %16, label %20 [
    i32 2, label %17
    i32 4, label %18
    i32 8, label %19
  ]

17:                                               ; preds = %5
  store i32 1, ptr %11, align 4, !tbaa !10
  br label %20

18:                                               ; preds = %5
  store i32 2, ptr %11, align 4, !tbaa !10
  br label %20

19:                                               ; preds = %5
  store i32 3, ptr %11, align 4, !tbaa !10
  br label %20

20:                                               ; preds = %19, %18, %17, %5
  %21 = load i8, ptr %7, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  switch i32 %22, label %83 [
    i32 0, label %23
    i32 1, label %38
    i32 2, label %53
    i32 4, label %68
  ]

23:                                               ; preds = %20
  %24 = load ptr, ptr %12, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct.s_data_instance, ptr %24, i32 0, i32 59
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %26, i32 0, i32 3
  %28 = getelementptr inbounds %struct.EFI_PCI_IO_PROTOCOL_ACCESS, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %30 = load ptr, ptr %12, align 8, !tbaa !12
  %31 = getelementptr inbounds %struct.s_data_instance, ptr %30, i32 0, i32 59
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %11, align 4, !tbaa !10
  %34 = load i64, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %10, align 8, !tbaa !5
  %36 = inttoptr i64 %35 to ptr
  %37 = call i64 %29(ptr noundef %32, i32 noundef %33, i8 noundef zeroext 1, i64 noundef %34, i64 noundef 1, ptr noundef %36)
  br label %83

38:                                               ; preds = %20
  %39 = load ptr, ptr %12, align 8, !tbaa !12
  %40 = getelementptr inbounds %struct.s_data_instance, ptr %39, i32 0, i32 59
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %41, i32 0, i32 3
  %43 = getelementptr inbounds %struct.EFI_PCI_IO_PROTOCOL_ACCESS, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  %45 = load ptr, ptr %12, align 8, !tbaa !12
  %46 = getelementptr inbounds %struct.s_data_instance, ptr %45, i32 0, i32 59
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = load i32, ptr %11, align 4, !tbaa !10
  %49 = load i64, ptr %9, align 8, !tbaa !5
  %50 = load i64, ptr %10, align 8, !tbaa !5
  %51 = inttoptr i64 %50 to ptr
  %52 = call i64 %44(ptr noundef %47, i32 noundef %48, i8 noundef zeroext 1, i64 noundef %49, i64 noundef 1, ptr noundef %51)
  br label %83

53:                                               ; preds = %20
  %54 = load ptr, ptr %12, align 8, !tbaa !12
  %55 = getelementptr inbounds %struct.s_data_instance, ptr %54, i32 0, i32 59
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds %struct.EFI_PCI_IO_PROTOCOL_ACCESS, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  %60 = load ptr, ptr %12, align 8, !tbaa !12
  %61 = getelementptr inbounds %struct.s_data_instance, ptr %60, i32 0, i32 59
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load i32, ptr %11, align 4, !tbaa !10
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = load i64, ptr %10, align 8, !tbaa !5
  %66 = inttoptr i64 %65 to ptr
  %67 = call i64 %59(ptr noundef %62, i32 noundef %63, i8 noundef zeroext 0, i64 noundef %64, i64 noundef 1, ptr noundef %66)
  br label %83

68:                                               ; preds = %20
  %69 = load ptr, ptr %12, align 8, !tbaa !12
  %70 = getelementptr inbounds %struct.s_data_instance, ptr %69, i32 0, i32 59
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %71, i32 0, i32 2
  %73 = getelementptr inbounds %struct.EFI_PCI_IO_PROTOCOL_ACCESS, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !23
  %75 = load ptr, ptr %12, align 8, !tbaa !12
  %76 = getelementptr inbounds %struct.s_data_instance, ptr %75, i32 0, i32 59
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  %78 = load i32, ptr %11, align 4, !tbaa !10
  %79 = load i64, ptr %9, align 8, !tbaa !5
  %80 = load i64, ptr %10, align 8, !tbaa !5
  %81 = inttoptr i64 %80 to ptr
  %82 = call i64 %74(ptr noundef %77, i32 noundef %78, i8 noundef zeroext 0, i64 noundef %79, i64 noundef 1, ptr noundef %81)
  br label %83

83:                                               ; preds = %68, %53, %38, %23, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!15, !13, i64 1816}
!15 = !{!"s_data_instance", !16, i64 0, !16, i64 2, !7, i64 4, !7, i64 5, !16, i64 6, !16, i64 8, !16, i64 10, !16, i64 12, !16, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !11, i64 880, !11, i64 884, !16, i64 888, !16, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !16, i64 896, !16, i64 898, !16, i64 900, !16, i64 902, !11, i64 904, !11, i64 908, !16, i64 912, !16, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !16, i64 922, !11, i64 924, !13, i64 928, !13, i64 936, !13, i64 944, !13, i64 952, !13, i64 960, !13, i64 968, !6, i64 976, !6, i64 984, !6, i64 992, !6, i64 1000, !6, i64 1008, !7, i64 1016, !16, i64 1528, !16, i64 1530, !16, i64 1532, !16, i64 1534, !7, i64 1536, !7, i64 1537, !7, i64 1538, !7, i64 1539, !7, i64 1540, !7, i64 1541, !17, i64 1544, !6, i64 1808, !13, i64 1816, !6, i64 1824, !13, i64 1832, !13, i64 1840, !13, i64 1848, !13, i64 1856, !13, i64 1864, !13, i64 1872, !13, i64 1880, !13, i64 1888, !13, i64 1896, !13, i64 1904, !13, i64 1912}
!16 = !{!"short", !7, i64 0}
!17 = !{!"mc", !7, i64 0, !16, i64 6, !7, i64 8}
!18 = !{!19, !13, i64 32}
!19 = !{!"_EFI_PCI_IO_PROTOCOL", !13, i64 0, !13, i64 8, !20, i64 16, !20, i64 32, !20, i64 48, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !6, i64 144, !13, i64 152}
!20 = !{!"", !13, i64 0, !13, i64 8}
!21 = !{!19, !13, i64 40}
!22 = !{!19, !13, i64 16}
!23 = !{!19, !13, i64 24}


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

@switch.table.TmpMemIo = private unnamed_addr constant [7 x i32] [i32 1, i32 0, i32 2, i32 0, i32 0, i32 0, i32 3], align 4
@switch.table.TmpMemIo.1 = private unnamed_addr constant [5 x i64] [i64 32, i64 40, i64 16, i64 32, i64 24], align 8

; Function Attrs: nounwind uwtable
define dso_local void @TmpMemIo(i64 noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = inttoptr i64 %0 to ptr
  %switch.tableidx = add i8 %2, -2
  %7 = icmp ult i8 %switch.tableidx, 7
  br i1 %7, label %switch.lookup, label %9

switch.lookup:                                    ; preds = %5
  %8 = zext nneg i8 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [7 x i32], ptr @switch.table.TmpMemIo, i64 0, i64 %8
  %switch.load = load i32, ptr %switch.gep, align 4
  br label %9

9:                                                ; preds = %switch.lookup, %5
  %.0 = phi i32 [ 0, %5 ], [ %switch.load, %switch.lookup ]
  %10 = icmp ult i8 %1, 5
  br i1 %10, label %switch.hole_check, label %19

switch.hole_check:                                ; preds = %9
  %switch.shifted = lshr i8 23, %1
  %switch.lobit = trunc i8 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup30, label %19

switch.lookup30:                                  ; preds = %switch.hole_check
  %11 = zext nneg i8 %1 to i64
  %switch.gep31 = getelementptr inbounds [5 x i64], ptr @switch.table.TmpMemIo.1, i64 0, i64 %11
  %switch.load32 = load i64, ptr %switch.gep31, align 8
  %12 = shl nuw nsw i8 %1, 3
  %switch.shiftamt = zext nneg i8 %12 to i40
  %switch.downshift = lshr i40 16777473, %switch.shiftamt
  %switch.masked = trunc i40 %switch.downshift to i8
  %13 = getelementptr inbounds i8, ptr %6, i64 1816
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 %switch.load32
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = inttoptr i64 %4 to ptr
  %18 = tail call i64 %16(ptr noundef %14, i32 noundef %.0, i8 noundef zeroext %switch.masked, i64 noundef %3, i64 noundef 1, ptr noundef %17) #1
  br label %19

19:                                               ; preds = %switch.hole_check, %9, %switch.lookup30
  ret void
}

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 = { 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, !11, i64 1816}
!6 = !{!"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, !10, i64 880, !10, 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, !10, i64 904, !10, i64 908, !7, i64 912, !7, i64 914, !8, i64 916, !8, i64 920, !8, i64 921, !7, i64 922, !10, i64 924, !11, i64 928, !11, i64 936, !11, i64 944, !11, i64 952, !11, i64 960, !11, i64 968, !12, i64 976, !12, i64 984, !12, i64 992, !12, i64 1000, !12, 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, !13, i64 1544, !12, i64 1808, !11, i64 1816, !12, i64 1824, !11, i64 1832, !11, i64 1840, !11, i64 1848, !11, i64 1856, !11, i64 1864, !11, i64 1872, !11, i64 1880, !11, i64 1888, !11, i64 1896, !11, i64 1904, !11, i64 1912}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"mc", !8, i64 0, !7, i64 6, !8, i64 8}
!14 = !{!11, !11, i64 0}


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