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

; 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"

; 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 i64 @UfsExecUicCommands(ptr noundef, i8 noundef zeroext, i32 noundef, i32 noundef, i32 noundef) #1

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

7:                                                ; preds = %21, %1
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 3
  br i1 %9, label %10, label %24

10:                                               ; preds = %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i64 @UfsExecUicCommands(ptr noundef %11, i8 noundef zeroext 22, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  store i64 %12, ptr %5, align 8, !tbaa !9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  br label %24

16:                                               ; preds = %10
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = icmp eq i64 %17, -9223372036854775794
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  br label %21

20:                                               ; preds = %16
  store i64 -9223372036854775801, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %29

21:                                               ; preds = %19
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = add i64 %22, 1
  store i64 %23, ptr %4, align 8, !tbaa !9
  br label %7, !llvm.loop !11

24:                                               ; preds = %15, %7
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 3
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i64 -9223372036854775794, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %29

28:                                               ; preds = %24
  store i64 0, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %29

29:                                               ; preds = %28, %27, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %30 = load i64, ptr %2, align 8
  ret i64 %30
}

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 = distinct !{!11, !12}
!12 = !{!"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: nounwind uwtable
declare dso_local i64 @UfsExecUicCommands(ptr noundef, i8 noundef zeroext, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775801, 1) i64 @UfsDeviceDetection(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @UfsExecUicCommands(ptr noundef %0, i8 noundef zeroext 22, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %3 = icmp slt i64 %2, 0
  br i1 %3, label %4, label %.loopexit

4:                                                ; preds = %1
  %5 = icmp eq i64 %2, -9223372036854775794
  br i1 %5, label %6, label %.loopexit.loopexit

6:                                                ; preds = %4
  %7 = tail call i64 @UfsExecUicCommands(ptr noundef %0, i8 noundef zeroext 22, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %8 = icmp slt i64 %7, 0
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %6
  %10 = icmp eq i64 %7, -9223372036854775794
  br i1 %10, label %11, label %.loopexit.loopexit

11:                                               ; preds = %9
  %12 = tail call i64 @UfsExecUicCommands(ptr noundef %0, i8 noundef zeroext 22, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %.loopexit

14:                                               ; preds = %11
  %15 = icmp eq i64 %12, -9223372036854775794
  br i1 %15, label %.loopexit, label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %14, %9, %4
  br label %.loopexit

.loopexit:                                        ; preds = %1, %6, %11, %14, %.loopexit.loopexit
  %.0 = phi i64 [ -9223372036854775801, %.loopexit.loopexit ], [ 0, %1 ], [ 0, %6 ], [ 0, %11 ], [ -9223372036854775794, %14 ]
  ret i64 %.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" }

!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)"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass