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

; 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.s_TxCB = type { %struct.CB_Header, i32, i16, i8, i8, [64 x i8], [16 x %struct.TBD], i32, i32, ptr, ptr, i64 }
%struct.CB_Header = type { i16, i16, i32 }
%struct.TBD = type { i32, i32 }

@.str = external hidden unnamed_addr constant [137 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; 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
declare dso_local void @UnMapIt(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i64 noundef) #1

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @SetFreeCB(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @CheckCBList(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  store i16 0, ptr %4, align 2, !tbaa !9
  br label %5

5:                                                ; preds = %80, %1
  br label %6

6:                                                ; preds = %5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.s_data_instance, ptr %7, i32 0, i32 39
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.s_TxCB, ptr %9, i32 0, i32 9
  %11 = load ptr, ptr %10, align 1, !tbaa !16
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.s_TxCB, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds %struct.CB_Header, ptr %13, i32 0, i32 0
  %15 = load i16, ptr %14, align 1, !tbaa !19
  %16 = zext i16 %15 to i32
  %17 = and i32 %16, 61440
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %79

19:                                               ; preds = %6
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.s_data_instance, ptr %20, i32 0, i32 48
  %22 = load i16, ptr %21, align 2, !tbaa !20
  %23 = call zeroext i16 @next(i16 noundef zeroext %22)
  %24 = zext i16 %23 to i32
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s_data_instance, ptr %25, i32 0, i32 47
  %27 = load i16, ptr %26, align 8, !tbaa !21
  %28 = zext i16 %27 to i32
  %29 = icmp ne i32 %24, %28
  br i1 %29, label %30, label %76

30:                                               ; preds = %19
  br label %31

31:                                               ; preds = %30
  %32 = call zeroext i8 @DebugAssertEnabled()
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %34, label %42

34:                                               ; preds = %31
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s_data_instance, ptr %35, i32 0, i32 48
  %37 = load i16, ptr %36, align 2, !tbaa !20
  %38 = zext i16 %37 to i32
  %39 = icmp slt i32 %38, 64
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1610, ptr noundef @.str.2)
  br label %41

41:                                               ; preds = %40, %34
  br label %42

42:                                               ; preds = %41, %31
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s_TxCB, ptr %45, i32 0, i32 11
  %47 = load i64, ptr %46, align 1, !tbaa !22
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s_data_instance, ptr %48, i32 0, i32 46
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_data_instance, ptr %50, i32 0, i32 48
  %52 = load i16, ptr %51, align 2, !tbaa !20
  %53 = zext i16 %52 to i64
  %54 = getelementptr inbounds [64 x i64], ptr %49, i64 0, i64 %53
  store i64 %47, ptr %54, align 8, !tbaa !23
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.s_TxCB, ptr %56, i32 0, i32 11
  %58 = load i64, ptr %57, align 1, !tbaa !22
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.s_TxCB, ptr %59, i32 0, i32 6
  %61 = getelementptr inbounds [16 x %struct.TBD], ptr %60, i64 0, i64 0
  %62 = getelementptr inbounds %struct.TBD, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 1, !tbaa !24
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.s_TxCB, ptr %64, i32 0, i32 6
  %66 = getelementptr inbounds [16 x %struct.TBD], ptr %65, i64 0, i64 0
  %67 = getelementptr inbounds %struct.TBD, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 1, !tbaa !26
  %69 = zext i32 %68 to i64
  call void @UnMapIt(ptr noundef %55, i64 noundef %58, i32 noundef %63, i32 noundef 2, i64 noundef %69)
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.s_data_instance, ptr %70, i32 0, i32 48
  %72 = load i16, ptr %71, align 2, !tbaa !20
  %73 = call zeroext i16 @next(i16 noundef zeroext %72)
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.s_data_instance, ptr %74, i32 0, i32 48
  store i16 %73, ptr %75, align 2, !tbaa !20
  br label %76

76:                                               ; preds = %44, %19
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SetFreeCB(ptr noundef %77, ptr noundef %78)
  br label %80

79:                                               ; preds = %6
  br label %81

80:                                               ; preds = %76
  br label %5

81:                                               ; preds = %79
  %82 = load i16, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i16 %82
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @next(i16 noundef zeroext) #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 = { "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, !6, i64 960}
!12 = !{!"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, !15, 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}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"mc", !7, i64 0, !10, i64 6, !7, i64 8}
!16 = !{!17, !6, i64 216}
!17 = !{!"s_TxCB", !18, i64 0, !13, i64 8, !10, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 80, !13, i64 208, !13, i64 212, !6, i64 216, !6, i64 224, !14, i64 232}
!18 = !{!"CB_Header", !10, i64 0, !10, i64 2, !13, i64 4}
!19 = !{!17, !10, i64 0}
!20 = !{!12, !10, i64 1530}
!21 = !{!12, !10, i64 1528}
!22 = !{!17, !14, i64 232}
!23 = !{!14, !14, i64 0}
!24 = !{!25, !13, i64 4}
!25 = !{!"TBD", !13, i64 0, !13, i64 4}
!26 = !{!25, !13, 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 [137 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @UnMapIt(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @SetFreeCB(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i16 @CheckCBList(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 960
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 216
  %5 = load ptr, ptr %4, align 1, !tbaa !14
  %6 = load i16, ptr %5, align 1, !tbaa !17
  %.not18 = icmp ult i16 %6, 4096
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 1530
  %8 = getelementptr inbounds i8, ptr %0, i64 1528
  %9 = getelementptr inbounds i8, ptr %0, i64 1016
  br label %10

10:                                               ; preds = %.lr.ph, %33
  %11 = phi ptr [ %5, %.lr.ph ], [ %36, %33 ]
  %12 = load i16, ptr %7, align 2, !tbaa !18
  %13 = tail call zeroext i16 @next(i16 noundef zeroext %12)
  %14 = load i16, ptr %8, align 8, !tbaa !19
  %.not16 = icmp eq i16 %13, %14
  br i1 %.not16, label %33, label %15

15:                                               ; preds = %10
  %16 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not17 = icmp eq i8 %16, 0
  %.pre19 = load i16, ptr %7, align 2, !tbaa !18
  %17 = icmp ult i16 %.pre19, 64
  %or.cond = select i1 %.not17, i1 true, i1 %17
  br i1 %or.cond, label %19, label %18

18:                                               ; preds = %15
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1610, ptr noundef nonnull @.str.2) #2
  %.pre = load i16, ptr %7, align 2, !tbaa !18
  br label %19

19:                                               ; preds = %18, %15
  %20 = phi i16 [ %.pre, %18 ], [ %.pre19, %15 ]
  %21 = getelementptr inbounds i8, ptr %11, i64 232
  %22 = load i64, ptr %21, align 1, !tbaa !20
  %23 = zext i16 %20 to i64
  %24 = getelementptr inbounds [64 x i64], ptr %9, i64 0, i64 %23
  store i64 %22, ptr %24, align 8, !tbaa !21
  %25 = load i64, ptr %21, align 1, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %11, i64 80
  %27 = getelementptr inbounds i8, ptr %11, i64 84
  %28 = load i32, ptr %27, align 1, !tbaa !22
  %29 = load i32, ptr %26, align 1, !tbaa !24
  %30 = zext i32 %29 to i64
  tail call void @UnMapIt(ptr noundef nonnull %0, i64 noundef %25, i32 noundef %28, i32 noundef 2, i64 noundef %30)
  %31 = load i16, ptr %7, align 2, !tbaa !18
  %32 = tail call zeroext i16 @next(i16 noundef zeroext %31)
  store i16 %32, ptr %7, align 2, !tbaa !18
  br label %33

33:                                               ; preds = %19, %10
  tail call void @SetFreeCB(ptr noundef nonnull %0, ptr noundef nonnull %11)
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 216
  %36 = load ptr, ptr %35, align 1, !tbaa !14
  %37 = load i16, ptr %36, align 1, !tbaa !17
  %.not = icmp ult i16 %37, 4096
  br i1 %.not, label %._crit_edge, label %10

._crit_edge:                                      ; preds = %33, %1
  ret i16 0
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @next(i16 noundef zeroext) 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" }
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, !11, i64 960}
!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 = !{!15, !11, i64 216}
!15 = !{!"s_TxCB", !16, i64 0, !10, i64 8, !7, i64 12, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 80, !10, i64 208, !10, i64 212, !11, i64 216, !11, i64 224, !12, i64 232}
!16 = !{!"CB_Header", !7, i64 0, !7, i64 2, !10, i64 4}
!17 = !{!15, !7, i64 0}
!18 = !{!6, !7, i64 1530}
!19 = !{!6, !7, i64 1528}
!20 = !{!15, !12, i64 232}
!21 = !{!12, !12, i64 0}
!22 = !{!23, !10, i64 4}
!23 = !{!"TBD", !10, i64 0, !10, i64 4}
!24 = !{!23, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass