; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Scsi (ScsiDiskIsMediaChange)

; 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.EFI_SCSI_SENSE_DATA = type { i8, i8, i8, [4 x i8], i8, [4 x i8], i8, i8, i8, [3 x i8] }

; 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
define dso_local zeroext i8 @ScsiDiskIsMediaChange(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %30, %2
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = icmp ult i64 %10, %11
  br i1 %12, label %13, label %33

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_SCSI_SENSE_DATA, ptr %14, i32 0, i32 2
  %16 = load i8, ptr %15, align 1
  %17 = and i8 %16, 15
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 6
  br i1 %19, label %20, label %27

20:                                               ; preds = %13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EFI_SCSI_SENSE_DATA, ptr %21, i32 0, i32 6
  %23 = load i8, ptr %22, align 1, !tbaa !12
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 40
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i8 1, ptr %7, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %26, %20, %13
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_SCSI_SENSE_DATA, ptr %28, i32 1
  store ptr %29, ptr %5, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %27
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = add i64 %31, 1
  store i64 %32, ptr %6, align 8, !tbaa !9
  br label %9, !llvm.loop !14

33:                                               ; preds = %9
  %34 = load i8, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i8 %34
}

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 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 12}
!13 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 3, !7, i64 7, !7, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @ScsiDiskIsMediaChange(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %1, 1
  %3 = icmp eq i64 %1, 1
  br i1 %3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %1, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %20, %.lr.ph.preheader.new
  %.011 = phi i8 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %20 ]
  %.089 = phi ptr [ %0, %.lr.ph.preheader.new ], [ %21, %20 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %20 ]
  %4 = getelementptr inbounds i8, ptr %.089, i64 2
  %5 = load i8, ptr %4, align 1
  %6 = and i8 %5, 15
  %7 = icmp eq i8 %6, 6
  br i1 %7, label %8, label %.lr.ph.1

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.089, i64 12
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp eq i8 %10, 40
  %spec.select = select i1 %11, i8 1, i8 %.011
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %8, %.lr.ph
  %.1 = phi i8 [ %.011, %.lr.ph ], [ %spec.select, %8 ]
  %12 = getelementptr inbounds i8, ptr %.089, i64 20
  %13 = load i8, ptr %12, align 1
  %14 = and i8 %13, 15
  %15 = icmp eq i8 %14, 6
  br i1 %15, label %16, label %20

16:                                               ; preds = %.lr.ph.1
  %17 = getelementptr inbounds i8, ptr %.089, i64 30
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %18, 40
  %spec.select.1 = select i1 %19, i8 1, i8 %.1
  br label %20

20:                                               ; preds = %16, %.lr.ph.1
  %.1.1 = phi i8 [ %.1, %.lr.ph.1 ], [ %spec.select.1, %16 ]
  %21 = getelementptr inbounds i8, ptr %.089, i64 36
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %20, %.lr.ph.preheader
  %.1.lcssa.ph = phi i8 [ poison, %.lr.ph.preheader ], [ %.1.1, %20 ]
  %.011.unr = phi i8 [ 0, %.lr.ph.preheader ], [ %.1.1, %20 ]
  %.089.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %21, %20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %22 = getelementptr inbounds i8, ptr %.089.unr, i64 2
  %23 = load i8, ptr %22, align 1
  %24 = and i8 %23, 15
  %25 = icmp eq i8 %24, 6
  br i1 %25, label %26, label %._crit_edge

26:                                               ; preds = %.lr.ph.epil
  %27 = getelementptr inbounds i8, ptr %.089.unr, i64 12
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = icmp eq i8 %28, 40
  %spec.select.epil = select i1 %29, i8 1, i8 %.011.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %26, %.lr.ph.epil, %2
  %.0.lcssa = phi i8 [ 0, %2 ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.011.unr, %.lr.ph.epil ], [ %spec.select.epil, %26 ]
  ret i8 %.0.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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" }

!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 12}
!6 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 3, !7, i64 7, !7, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass