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

; 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._TRANSFER_RING = type <{ i64, i32, i64, i64, i32 }>
%struct._TRB_TEMPLATE = type { i32, i32, i32, i32 }

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

; 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 zeroext i8 @IsTrbInTrsRing(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._TRANSFER_RING, ptr %9, i32 0, i32 0
  %11 = load i64, ptr %10, align 1, !tbaa !9
  %12 = inttoptr i64 %11 to ptr
  store ptr %12, ptr %6, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %2
  %14 = call zeroext i8 @DebugAssertEnabled()
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %23

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._TRANSFER_RING, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 1, !tbaa !13
  %20 = icmp eq i32 %19, 256
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @DebugAssert(ptr noundef @.str, i64 noundef 193, ptr noundef @.str.7)
  br label %22

22:                                               ; preds = %21, %16
  br label %23

23:                                               ; preds = %22, %13
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %26

26:                                               ; preds = %41, %25
  %27 = load i64, ptr %7, align 8, !tbaa !14
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._TRANSFER_RING, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 1, !tbaa !13
  %31 = zext i32 %30 to i64
  %32 = icmp ult i64 %27, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %26
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = icmp eq ptr %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  store i8 1, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %45

38:                                               ; preds = %33
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._TRB_TEMPLATE, ptr %39, i32 1
  store ptr %40, ptr %6, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %38
  %42 = load i64, ptr %7, align 8, !tbaa !14
  %43 = add i64 %42, 1
  store i64 %43, ptr %7, align 8, !tbaa !14
  br label %26, !llvm.loop !15

44:                                               ; preds = %26
  store i8 0, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %45

45:                                               ; preds = %44, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %46 = load i8, ptr %3, align 1
  ret i8 %46
}

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, !11, i64 0}
!10 = !{!"_TRANSFER_RING", !11, i64 0, !12, i64 8, !11, i64 12, !11, i64 20, !12, i64 28}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 [191 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @IsTrbInTrsRing(ptr nocapture noundef readonly %0, ptr noundef readnone %1) local_unnamed_addr #1 {
  %3 = load i64, ptr %0, align 1, !tbaa !5
  %4 = inttoptr i64 %3 to ptr
  %5 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %11, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 1, !tbaa !11
  %9 = icmp eq i32 %8, 256
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 193, ptr noundef nonnull @.str.7) #2
  br label %11

11:                                               ; preds = %6, %10, %2
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 1, !tbaa !11
  %14 = zext i32 %13 to i64
  %.not14 = icmp eq i32 %13, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %16
  %.011 = phi i64 [ %18, %16 ], [ 0, %11 ]
  %.0810 = phi ptr [ %17, %16 ], [ %4, %11 ]
  %15 = icmp eq ptr %.0810, %1
  br i1 %15, label %._crit_edge, label %16

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.0810, i64 16
  %18 = add nuw nsw i64 %.011, 1
  %exitcond.not = icmp eq i64 %18, %14
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %16, %11
  %.09 = phi i8 [ 0, %11 ], [ 0, %16 ], [ 1, %.lr.ph ]
  ret i8 %.09
}

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 = !{!"_TRANSFER_RING", !7, i64 0, !10, i64 8, !7, i64 12, !7, i64 20, !10, i64 28}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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