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

; 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._UFS_PASS_THRU_PRIVATE_DATA = type { i32, ptr, %struct.EFI_EXT_SCSI_PASS_THRU_MODE, %struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL, ptr, i64, i32, i8, ptr, i8, ptr, ptr, i8, ptr, %struct.UFS_EXPOSED_LUNS }
%struct.EFI_EXT_SCSI_PASS_THRU_MODE = type { i32, i32, i32 }
%struct._EFI_EXT_SCSI_PASS_THRU_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.UFS_EXPOSED_LUNS = type { [12 x i8], i16 }

; Function Attrs: nounwind uwtable
declare dso_local i64 @UfsWaitMemSet(i64 noundef, i32 noundef, i32 noundef, i64 noundef) #0

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

declare i32 @MmioRead32(i64 noundef) #2

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

declare i32 @MmioWrite32(i64 noundef, i32 noundef) #2

declare i64 @MultU64x32(i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UfsEnableHostController(ptr noundef %0) #0 {
  %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
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._UFS_PASS_THRU_PRIVATE_DATA, ptr %8, i32 0, i32 5
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = add i64 %10, 52
  store i64 %11, ptr %5, align 8, !tbaa !17
  %12 = load i64, ptr %5, align 8, !tbaa !17
  %13 = call i32 @MmioRead32(i64 noundef %12)
  store i32 %13, ptr %6, align 4, !tbaa !18
  %14 = load i32, ptr %6, align 4, !tbaa !18
  %15 = and i32 %14, 1
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %27

17:                                               ; preds = %1
  %18 = load i64, ptr %5, align 8, !tbaa !17
  %19 = call i32 @MmioWrite32(i64 noundef %18, i32 noundef 0)
  %20 = load i64, ptr %5, align 8, !tbaa !17
  %21 = call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000)
  %22 = call i64 @UfsWaitMemSet(i64 noundef %20, i32 noundef 1, i32 noundef 0, i64 noundef %21)
  store i64 %22, ptr %4, align 8, !tbaa !17
  %23 = load i64, ptr %4, align 8, !tbaa !17
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %17
  store i64 -9223372036854775801, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %37

26:                                               ; preds = %17
  br label %27

27:                                               ; preds = %26, %1
  %28 = load i64, ptr %5, align 8, !tbaa !17
  %29 = call i32 @MmioWrite32(i64 noundef %28, i32 noundef 1)
  %30 = load i64, ptr %5, align 8, !tbaa !17
  %31 = call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000)
  %32 = call i64 @UfsWaitMemSet(i64 noundef %30, i32 noundef 1, i32 noundef 1, i64 noundef %31)
  store i64 %32, ptr %4, align 8, !tbaa !17
  %33 = load i64, ptr %4, align 8, !tbaa !17
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  store i64 -9223372036854775801, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %37

36:                                               ; preds = %27
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %36, %35, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %38 = load i64, ptr %2, align 8
  ret i64 %38
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !14, i64 104}
!10 = !{!"_UFS_PASS_THRU_PRIVATE_DATA", !11, i64 0, !6, i64 8, !12, i64 16, !13, i64 32, !6, i64 96, !14, i64 104, !11, i64 112, !7, i64 116, !6, i64 120, !7, i64 128, !6, i64 136, !6, i64 144, !7, i64 152, !6, i64 160, !15, i64 168}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!13 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"", !7, i64 0, !16, i64 12, !16, i64 13}
!16 = !{!"short", !7, i64 0}
!17 = !{!14, !14, i64 0}
!18 = !{!11, !11, i64 0}


; 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 @UfsWaitMemSet(i64 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

declare i32 @MmioRead32(i64 noundef) local_unnamed_addr #1

declare i32 @MmioWrite32(i64 noundef, i32 noundef) local_unnamed_addr #1

declare i64 @MultU64x32(i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775801, 1) i64 @UfsEnableHostController(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 104
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = add i64 %3, 52
  %5 = tail call i32 @MmioRead32(i64 noundef %4) #2
  %6 = and i32 %5, 1
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %12, label %7

7:                                                ; preds = %1
  %8 = tail call i32 @MmioWrite32(i64 noundef %4, i32 noundef 0) #2
  %9 = tail call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000) #2
  %10 = tail call i64 @UfsWaitMemSet(i64 noundef %4, i32 noundef 1, i32 noundef 0, i64 noundef %9)
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %17, label %12

12:                                               ; preds = %7, %1
  %13 = tail call i32 @MmioWrite32(i64 noundef %4, i32 noundef 1) #2
  %14 = tail call i64 @MultU64x32(i64 noundef 3, i32 noundef 10000000) #2
  %15 = tail call i64 @UfsWaitMemSet(i64 noundef %4, i32 noundef 1, i32 noundef 1, i64 noundef %14)
  %16 = icmp slt i64 %15, 0
  %. = select i1 %16, i64 -9223372036854775801, i64 0
  br label %17

17:                                               ; preds = %12, %7
  %.0 = phi i64 [ -9223372036854775801, %7 ], [ %., %12 ]
  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" }
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 }

!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, !13, i64 104}
!6 = !{!"_UFS_PASS_THRU_PRIVATE_DATA", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 32, !10, i64 96, !13, i64 104, !7, i64 112, !8, i64 116, !10, i64 120, !8, i64 128, !10, i64 136, !10, i64 144, !8, i64 152, !10, i64 160, !14, i64 168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!12 = !{!"_EFI_EXT_SCSI_PASS_THRU_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"", !8, i64 0, !15, i64 12, !15, i64 13}
!15 = !{!"short", !8, i64 0}


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