; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (BlockArrayCheck)

; 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.IFR_BLOCK_DATA = type { %struct._LIST_ENTRY, i16, i16, i16, i8, i8, %struct._LIST_ENTRY, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [21 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

declare zeroext i8 @DebugAssertEnabled() #1

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

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) #1

declare i64 @StrLen(ptr noundef) #1

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

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @InternalGetString(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @BlockArrayCheck(ptr noundef %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3, ptr noundef %4) #2 {
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i16 %1, ptr %8, align 2, !tbaa !9
  store i16 %2, ptr %9, align 2, !tbaa !9
  store i8 %3, ptr %10, align 1, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  store i8 1, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %95

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct._LIST_ENTRY, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  store ptr %23, ptr %12, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %90, %19
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %26, i32 0, i32 0
  %28 = icmp ne ptr %25, %27
  br i1 %28, label %29, label %94

29:                                               ; preds = %24
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = sub i64 %31, 0
  %33 = inttoptr i64 %32 to ptr
  store ptr %33, ptr %13, align 8, !tbaa !5
  %34 = load i8, ptr %10, align 1, !tbaa !11
  %35 = icmp ne i8 %34, 0
  br i1 %35, label %36, label %63

36:                                               ; preds = %29
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load i16, ptr %8, align 2, !tbaa !9
  %39 = call ptr @InternalGetString(ptr noundef %37, i16 noundef zeroext %38)
  store ptr %39, ptr %14, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %36
  %41 = call zeroext i8 @DebugAssertEnabled()
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %48

43:                                               ; preds = %40
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1008, ptr noundef @.str.22)
  br label %47

47:                                               ; preds = %46, %43
  br label %48

48:                                               ; preds = %47, %40
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %51, i32 0, i32 7
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = call i64 @StrLen(ptr noundef %55)
  %57 = call i64 @StrnCmp(ptr noundef %53, ptr noundef %54, i64 noundef %56)
  %58 = icmp eq i64 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %50
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  call void @FreePool(ptr noundef %60)
  store i8 1, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %95

61:                                               ; preds = %50
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  call void @FreePool(ptr noundef %62)
  br label %89

63:                                               ; preds = %29
  %64 = load i16, ptr %8, align 2, !tbaa !9
  %65 = zext i16 %64 to i32
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %66, i32 0, i32 1
  %68 = load i16, ptr %67, align 8, !tbaa !16
  %69 = zext i16 %68 to i32
  %70 = icmp sge i32 %65, %69
  br i1 %70, label %71, label %88

71:                                               ; preds = %63
  %72 = load i16, ptr %8, align 2, !tbaa !9
  %73 = zext i16 %72 to i32
  %74 = load i16, ptr %9, align 2, !tbaa !9
  %75 = zext i16 %74 to i32
  %76 = add nsw i32 %73, %75
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %77, i32 0, i32 1
  %79 = load i16, ptr %78, align 8, !tbaa !16
  %80 = zext i16 %79 to i32
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %81, i32 0, i32 2
  %83 = load i16, ptr %82, align 2, !tbaa !17
  %84 = zext i16 %83 to i32
  %85 = add nsw i32 %80, %84
  %86 = icmp sle i32 %76, %85
  br i1 %86, label %87, label %88

87:                                               ; preds = %71
  store i8 1, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %95

88:                                               ; preds = %71, %63
  br label %89

89:                                               ; preds = %88, %61
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._LIST_ENTRY, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !18
  store ptr %93, ptr %12, align 8, !tbaa !5
  br label %24, !llvm.loop !19

94:                                               ; preds = %24
  store i8 0, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %95

95:                                               ; preds = %94, %87, %59, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %96 = load i8, ptr %6, align 1
  ret i8 %96
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !14, i64 0, !10, i64 16, !10, i64 18, !10, i64 20, !7, i64 22, !7, i64 23, !14, i64 24, !6, i64 40}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!13, !6, i64 40}
!16 = !{!13, !10, i64 16}
!17 = !{!13, !10, i64 18}
!18 = !{!14, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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 [155 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i64 @StrLen(ptr noundef) local_unnamed_addr #0

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @InternalGetString(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @BlockArrayCheck(ptr noundef readonly %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = icmp eq ptr %0, null
  br i1 %6, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %5
  %.02229 = load ptr, ptr %0, align 8, !tbaa !5
  %.not30 = icmp eq ptr %.02229, %0
  br i1 %.not30, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %.not26 = icmp eq i8 %3, 0
  %7 = zext i16 %1 to i32
  %8 = zext i16 %2 to i32
  %9 = add nuw nsw i32 %8, %7
  br i1 %.not26, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %18
  %.02231.us = phi ptr [ %.022.us, %18 ], [ %.02229, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.02231.us, i64 16
  %11 = load i16, ptr %10, align 8, !tbaa !10
  %.not27.us = icmp ugt i16 %11, %1
  br i1 %.not27.us, label %18, label %12

12:                                               ; preds = %.lr.ph.split.us
  %13 = zext i16 %11 to i32
  %14 = getelementptr inbounds i8, ptr %.02231.us, i64 18
  %15 = load i16, ptr %14, align 2, !tbaa !13
  %16 = zext i16 %15 to i32
  %17 = add nuw nsw i32 %16, %13
  %.not28.us = icmp ugt i32 %9, %17
  br i1 %.not28.us, label %18, label %.loopexit

18:                                               ; preds = %12, %.lr.ph.split.us
  %.022.us = load ptr, ptr %.02231.us, align 8, !tbaa !5
  %.not.us = icmp eq ptr %.022.us, %0
  br i1 %.not.us, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !14

.lr.ph.split:                                     ; preds = %.lr.ph, %30
  %.02231 = phi ptr [ %.022, %30 ], [ %.02229, %.lr.ph ]
  %19 = tail call ptr @InternalGetString(ptr noundef %4, i16 noundef zeroext %1)
  %20 = tail call zeroext i8 @DebugAssertEnabled() #2
  %21 = icmp eq i8 %20, 0
  %22 = icmp ne ptr %19, null
  %or.cond = select i1 %21, i1 true, i1 %22
  br i1 %or.cond, label %24, label %23

23:                                               ; preds = %.lr.ph.split
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1008, ptr noundef nonnull @.str.22) #2
  br label %24

24:                                               ; preds = %23, %.lr.ph.split
  %25 = getelementptr inbounds i8, ptr %.02231, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = tail call i64 @StrLen(ptr noundef %19) #2
  %28 = tail call i64 @StrnCmp(ptr noundef %26, ptr noundef %19, i64 noundef %27) #2
  %29 = icmp eq i64 %28, 0
  tail call void @FreePool(ptr noundef %19) #2
  br i1 %29, label %.loopexit, label %30

30:                                               ; preds = %24
  %.022 = load ptr, ptr %.02231, align 8, !tbaa !5
  %.not = icmp eq ptr %.022, %0
  br i1 %.not, label %.loopexit, label %.lr.ph.split, !llvm.loop !14

.loopexit:                                        ; preds = %30, %24, %12, %18, %.preheader, %5
  %.0 = phi i8 [ 1, %5 ], [ 0, %.preheader ], [ 1, %12 ], [ 0, %18 ], [ 0, %30 ], [ 1, %24 ]
  ret i8 %.0
}

attributes #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 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, !7, i64 0}
!6 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 16}
!11 = !{!"", !6, i64 0, !12, i64 16, !12, i64 18, !12, i64 20, !8, i64 22, !8, i64 23, !6, i64 24, !7, i64 40}
!12 = !{!"short", !8, i64 0}
!13 = !{!11, !12, i64 18}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!11, !7, i64 40}


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