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

; 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._EVENT_RING = type <{ i64, i64, i32, i64, i64, i32 }>

@.str = external hidden unnamed_addr constant [191 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 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 i64 @XhcCheckNewEvent(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  br label %11

11:                                               ; preds = %3
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %19

14:                                               ; preds = %11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  call void @DebugAssert(ptr noundef @.str, i64 noundef 150, ptr noundef @.str.5)
  br label %18

18:                                               ; preds = %17, %14
  br label %19

19:                                               ; preds = %18, %11
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._EVENT_RING, ptr %22, i32 0, i32 4
  %24 = load i64, ptr %23, align 1, !tbaa !9
  %25 = inttoptr i64 %24 to ptr
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._EVENT_RING, ptr %26, i32 0, i32 4
  %28 = load i64, ptr %27, align 1, !tbaa !9
  %29 = inttoptr i64 %28 to ptr
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %29, ptr %30, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._EVENT_RING, ptr %31, i32 0, i32 4
  %33 = load i64, ptr %32, align 1, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._EVENT_RING, ptr %34, i32 0, i32 3
  %36 = load i64, ptr %35, align 1, !tbaa !13
  %37 = icmp eq i64 %33, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %21
  store i64 -9223372036854775802, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %65

39:                                               ; preds = %21
  store i64 0, ptr %8, align 8, !tbaa !14
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._EVENT_RING, ptr %40, i32 0, i32 4
  %42 = load i64, ptr %41, align 1, !tbaa !9
  %43 = add i64 %42, 16
  store i64 %43, ptr %41, align 1, !tbaa !9
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._EVENT_RING, ptr %44, i32 0, i32 4
  %46 = load i64, ptr %45, align 1, !tbaa !9
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._EVENT_RING, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 1, !tbaa !15
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._EVENT_RING, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 1, !tbaa !16
  %53 = zext i32 %52 to i64
  %54 = mul i64 16, %53
  %55 = add i64 %49, %54
  %56 = icmp uge i64 %46, %55
  br i1 %56, label %57, label %63

57:                                               ; preds = %39
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._EVENT_RING, ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 1, !tbaa !15
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._EVENT_RING, ptr %61, i32 0, i32 4
  store i64 %60, ptr %62, align 1, !tbaa !9
  br label %63

63:                                               ; preds = %57, %39
  %64 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %64, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %65

65:                                               ; preds = %63, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %66 = load i64, ptr %4, align 8
  ret i64 %66
}

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 28}
!10 = !{!"_EVENT_RING", !11, i64 0, !11, i64 8, !12, i64 16, !11, i64 20, !11, i64 28, !12, i64 36}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 20}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !12, i64 16}


; 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.5 = external hidden unnamed_addr constant [24 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 range(i64 -9223372036854775802, 1) i64 @XhcCheckNewEvent(ptr nocapture noundef readnone %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %5 = icmp eq i8 %4, 0
  %6 = icmp ne ptr %1, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %8, label %7

7:                                                ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 150, ptr noundef nonnull @.str.5) #2
  br label %8

8:                                                ; preds = %7, %3
  %9 = getelementptr inbounds i8, ptr %1, i64 28
  %10 = load i64, ptr %9, align 1, !tbaa !5
  %11 = inttoptr i64 %10 to ptr
  store ptr %11, ptr %2, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %1, i64 20
  %13 = load i64, ptr %12, align 1, !tbaa !13
  %14 = icmp eq i64 %10, %13
  br i1 %14, label %25, label %15

15:                                               ; preds = %8
  %16 = add i64 %10, 16
  store i64 %16, ptr %9, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load i64, ptr %17, align 1, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %1, i64 16
  %20 = load i32, ptr %19, align 1, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 4
  %23 = add i64 %22, %18
  %.not = icmp ult i64 %16, %23
  br i1 %.not, label %25, label %24

24:                                               ; preds = %15
  store i64 %18, ptr %9, align 1, !tbaa !5
  br label %25

25:                                               ; preds = %15, %24, %8
  %.0 = phi i64 [ -9223372036854775802, %8 ], [ 0, %24 ], [ 0, %15 ]
  ret i64 %.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 28}
!6 = !{!"_EVENT_RING", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 20, !7, i64 28, !10, i64 36}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 20}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !10, i64 16}


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