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

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

; Function Attrs: nounwind uwtable
define dso_local void @UNDI_Interrupt(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  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 1, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.s_pxe_cdb, ptr %7, i32 0, i32 1
  %9 = load i16, ptr %8, align 1, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = and i32 %10, 15
  %12 = sext i32 %11 to i64
  %13 = trunc i64 %12 to i8
  store i8 %13, ptr %5, align 1, !tbaa !13
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s_pxe_cdb, ptr %14, i32 0, i32 1
  %16 = load i16, ptr %15, align 1, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = and i32 %17, 49152
  switch i32 %18, label %54 [
    i32 0, label %59
    i32 32768, label %19
    i32 16384, label %35
  ]

19:                                               ; preds = %2
  %20 = load i8, ptr %5, align 1, !tbaa !13
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.s_pxe_cdb, ptr %24, i32 0, i32 7
  store i16 -32768, ptr %25, align 1, !tbaa !14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.s_pxe_cdb, ptr %26, i32 0, i32 6
  store i16 1, ptr %27, align 1, !tbaa !15
  store i32 1, ptr %6, align 4
  br label %102

28:                                               ; preds = %19
  %29 = load i8, ptr %5, align 1, !tbaa !13
  %30 = zext i8 %29 to i16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s_data_instance, ptr %31, i32 0, i32 28
  store i16 %30, ptr %32, align 8, !tbaa !16
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call zeroext i8 @E100bSetInterruptState(ptr noundef %33)
  br label %59

35:                                               ; preds = %2
  %36 = load i8, ptr %5, align 1, !tbaa !13
  %37 = zext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %53

39:                                               ; preds = %35
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_data_instance, ptr %40, i32 0, i32 28
  %42 = load i16, ptr %41, align 8, !tbaa !16
  %43 = zext i16 %42 to i32
  %44 = load i8, ptr %5, align 1, !tbaa !13
  %45 = zext i8 %44 to i32
  %46 = xor i32 %45, -1
  %47 = and i32 %43, %46
  %48 = trunc i32 %47 to i16
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.s_data_instance, ptr %49, i32 0, i32 28
  store i16 %48, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call zeroext i8 @E100bSetInterruptState(ptr noundef %51)
  br label %59

53:                                               ; preds = %35
  br label %54

54:                                               ; preds = %53, %2
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.s_pxe_cdb, ptr %55, i32 0, i32 7
  store i16 -32768, ptr %56, align 1, !tbaa !14
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s_pxe_cdb, ptr %57, i32 0, i32 6
  store i16 1, ptr %58, align 1, !tbaa !15
  store i32 1, ptr %6, align 4
  br label %102

59:                                               ; preds = %39, %28, %2
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s_data_instance, ptr %60, i32 0, i32 28
  %62 = load i16, ptr %61, align 8, !tbaa !16
  %63 = zext i16 %62 to i32
  %64 = and i32 %63, 1
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %73

66:                                               ; preds = %59
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.s_pxe_cdb, ptr %67, i32 0, i32 7
  %69 = load i16, ptr %68, align 1, !tbaa !14
  %70 = zext i16 %69 to i32
  %71 = or i32 %70, 1
  %72 = trunc i32 %71 to i16
  store i16 %72, ptr %68, align 1, !tbaa !14
  br label %73

73:                                               ; preds = %66, %59
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.s_data_instance, ptr %74, i32 0, i32 28
  %76 = load i16, ptr %75, align 8, !tbaa !16
  %77 = zext i16 %76 to i32
  %78 = and i32 %77, 2
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %87

80:                                               ; preds = %73
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.s_pxe_cdb, ptr %81, i32 0, i32 7
  %83 = load i16, ptr %82, align 1, !tbaa !14
  %84 = zext i16 %83 to i32
  %85 = or i32 %84, 2
  %86 = trunc i32 %85 to i16
  store i16 %86, ptr %82, align 1, !tbaa !14
  br label %87

87:                                               ; preds = %80, %73
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.s_data_instance, ptr %88, i32 0, i32 28
  %90 = load i16, ptr %89, align 8, !tbaa !16
  %91 = zext i16 %90 to i32
  %92 = and i32 %91, 4
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %101

94:                                               ; preds = %87
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.s_pxe_cdb, ptr %95, i32 0, i32 7
  %97 = load i16, ptr %96, align 1, !tbaa !14
  %98 = zext i16 %97 to i32
  %99 = or i32 %98, 4
  %100 = trunc i32 %99 to i16
  store i16 %100, ptr %96, align 1, !tbaa !14
  br label %101

101:                                              ; preds = %94, %87
  store i32 1, ptr %6, align 4
  br label %102

102:                                              ; preds = %101, %54, %23
  call void @llvm.lifetime.end.p0(i64 1, 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

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

declare zeroext i8 @E100bSetInterruptState(ptr noundef) #2

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, !11, i64 2}
!10 = !{!"s_pxe_cdb", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !12, i64 8, !12, i64 16, !11, i64 24, !11, i64 26, !11, i64 28, !11, i64 30}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !11, i64 26}
!15 = !{!10, !11, i64 24}
!16 = !{!17, !11, i64 912}
!17 = !{!"s_data_instance", !11, i64 0, !11, i64 2, !7, i64 4, !7, i64 5, !11, i64 6, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !18, i64 880, !18, i64 884, !11, i64 888, !11, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !11, i64 896, !11, i64 898, !11, i64 900, !11, i64 902, !18, i64 904, !18, i64 908, !11, i64 912, !11, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !11, i64 922, !18, 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, !11, i64 1528, !11, i64 1530, !11, i64 1532, !11, 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}
!18 = !{!"int", !7, i64 0}
!19 = !{!"mc", !7, i64 0, !11, 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"

; Function Attrs: nounwind uwtable
define dso_local void @UNDI_Interrupt(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 2
  %4 = load i16, ptr %3, align 1, !tbaa !5
  %5 = trunc i16 %4 to i8
  %6 = and i8 %5, 15
  %7 = lshr i16 %4, 14
  switch i16 %7, label %default.unreachable [
    i16 0, label %27
    i16 2, label %8
    i16 1, label %16
    i16 3, label %23
  ]

8:                                                ; preds = %2
  %9 = icmp eq i8 %6, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 -32768, ptr %11, align 1, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  store i16 1, ptr %12, align 1, !tbaa !12
  br label %47

13:                                               ; preds = %8
  %14 = and i16 %4, 15
  %15 = getelementptr inbounds i8, ptr %1, i64 912
  store i16 %14, ptr %15, align 8, !tbaa !13
  br label %.sink.split

16:                                               ; preds = %2
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %23, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %1, i64 912
  %19 = load i16, ptr %18, align 8, !tbaa !13
  %20 = xor i8 %6, -1
  %21 = sext i8 %20 to i16
  %22 = and i16 %19, %21
  store i16 %22, ptr %18, align 8, !tbaa !13
  br label %.sink.split

default.unreachable:                              ; preds = %2
  unreachable

23:                                               ; preds = %16, %2
  %24 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 -32768, ptr %24, align 1, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i16 1, ptr %25, align 1, !tbaa !12
  br label %47

.sink.split:                                      ; preds = %13, %17
  %26 = tail call zeroext i8 @E100bSetInterruptState(ptr noundef %1) #2
  br label %27

27:                                               ; preds = %.sink.split, %2
  %28 = getelementptr inbounds i8, ptr %1, i64 912
  %29 = load i16, ptr %28, align 8, !tbaa !13
  %30 = and i16 %29, 1
  %.not20 = icmp eq i16 %30, 0
  br i1 %.not20, label %35, label %31

31:                                               ; preds = %27
  %32 = getelementptr inbounds i8, ptr %0, i64 26
  %33 = load i16, ptr %32, align 1, !tbaa !11
  %34 = or i16 %33, 1
  store i16 %34, ptr %32, align 1, !tbaa !11
  br label %35

35:                                               ; preds = %31, %27
  %36 = and i16 %29, 2
  %.not21 = icmp eq i16 %36, 0
  br i1 %.not21, label %41, label %37

37:                                               ; preds = %35
  %38 = getelementptr inbounds i8, ptr %0, i64 26
  %39 = load i16, ptr %38, align 1, !tbaa !11
  %40 = or i16 %39, 2
  store i16 %40, ptr %38, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %37, %35
  %42 = and i16 %29, 4
  %.not22 = icmp eq i16 %42, 0
  br i1 %.not22, label %47, label %43

43:                                               ; preds = %41
  %44 = getelementptr inbounds i8, ptr %0, i64 26
  %45 = load i16, ptr %44, align 1, !tbaa !11
  %46 = or i16 %45, 4
  store i16 %46, ptr %44, align 1, !tbaa !11
  br label %47

47:                                               ; preds = %41, %43, %23, %10
  ret void
}

declare zeroext i8 @E100bSetInterruptState(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 2}
!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 = !{!6, !7, i64 26}
!12 = !{!6, !7, i64 24}
!13 = !{!14, !7, i64 912}
!14 = !{!"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, !16, i64 928, !16, i64 936, !16, i64 944, !16, i64 952, !16, i64 960, !16, 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, !17, i64 1544, !10, i64 1808, !16, i64 1816, !10, i64 1824, !16, i64 1832, !16, i64 1840, !16, i64 1848, !16, i64 1856, !16, i64 1864, !16, i64 1872, !16, i64 1880, !16, i64 1888, !16, i64 1896, !16, i64 1904, !16, i64 1912}
!15 = !{!"int", !8, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"mc", !8, i64 0, !7, i64 6, !8, i64 8}


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