; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (PartitionWriteBlocks)

; 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.PARTITION_PRIVATE_DATA = type { i64, ptr, ptr, %struct._EFI_BLOCK_IO_PROTOCOL, %struct._EFI_BLOCK_IO2_PROTOCOL, %struct.EFI_BLOCK_IO_MEDIA, %struct.EFI_BLOCK_IO_MEDIA, ptr, ptr, ptr, ptr, i64, i64, i32, ptr }
%struct._EFI_BLOCK_IO_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_BLOCK_IO2_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct.EFI_BLOCK_IO_MEDIA = type { i32, i8, i8, i8, i8, i8, i32, i32, i64, i64, i32, i32 }
%struct._EFI_DISK_IO_PROTOCOL = type { i64, ptr, ptr }

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

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @ProbeMediaStatus(ptr noundef, i32 noundef, i64 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @PartitionWriteBlocks(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !11
  store i64 %3, ptr %10, align 8, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %15 = call zeroext i8 @DebugAssertEnabled()
  %16 = zext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %28

18:                                               ; preds = %5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = sub i64 %20, ptrtoint (ptr getelementptr inbounds (%struct.PARTITION_PRIVATE_DATA, ptr null, i32 0, i32 3) to i64)
  %22 = inttoptr i64 %21 to ptr
  %23 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = icmp ne i64 %24, 1953653072
  br i1 %25, label %26, label %28

26:                                               ; preds = %18
  call void @DebugAssert(ptr noundef @.str, i64 noundef 734, ptr noundef @.str.1)
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  br label %33

28:                                               ; preds = %18, %5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = ptrtoint ptr %29 to i64
  %31 = sub i64 %30, ptrtoint (ptr getelementptr inbounds (%struct.PARTITION_PRIVATE_DATA, ptr null, i32 0, i32 3) to i64)
  %32 = inttoptr i64 %31 to ptr
  br label %33

33:                                               ; preds = %28, %26
  %34 = phi ptr [ %27, %26 ], [ %32, %28 ]
  store ptr %34, ptr %12, align 8, !tbaa !5
  %35 = load i64, ptr %10, align 8, !tbaa !11
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %36, i32 0, i32 13
  %38 = load i32, ptr %37, align 8, !tbaa !18
  %39 = zext i32 %38 to i64
  %40 = urem i64 %35, %39
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %33
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %43, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !19
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = call i64 @ProbeMediaStatus(ptr noundef %45, i32 noundef %46, i64 noundef -9223372036854775804)
  store i64 %47, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %85

48:                                               ; preds = %33
  %49 = load i64, ptr %9, align 8, !tbaa !11
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %50, i32 0, i32 13
  %52 = load i32, ptr %51, align 8, !tbaa !18
  %53 = call i64 @MultU64x32(i64 noundef %49, i32 noundef %52)
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %54, i32 0, i32 11
  %56 = load i64, ptr %55, align 8, !tbaa !20
  %57 = add i64 %53, %56
  store i64 %57, ptr %13, align 8, !tbaa !11
  %58 = load i64, ptr %13, align 8, !tbaa !11
  %59 = load i64, ptr %10, align 8, !tbaa !11
  %60 = add i64 %58, %59
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %61, i32 0, i32 12
  %63 = load i64, ptr %62, align 8, !tbaa !21
  %64 = icmp ugt i64 %60, %63
  br i1 %64, label %65, label %71

65:                                               ; preds = %48
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %66, i32 0, i32 7
  %68 = load ptr, ptr %67, align 8, !tbaa !19
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = call i64 @ProbeMediaStatus(ptr noundef %68, i32 noundef %69, i64 noundef -9223372036854775806)
  store i64 %70, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %85

71:                                               ; preds = %48
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %72, i32 0, i32 7
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  %75 = getelementptr inbounds %struct._EFI_DISK_IO_PROTOCOL, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !22
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.PARTITION_PRIVATE_DATA, ptr %77, i32 0, i32 7
  %79 = load ptr, ptr %78, align 8, !tbaa !19
  %80 = load i32, ptr %8, align 4, !tbaa !9
  %81 = load i64, ptr %13, align 8, !tbaa !11
  %82 = load i64, ptr %10, align 8, !tbaa !11
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = call i64 %76(ptr noundef %79, i32 noundef %80, i64 noundef %81, i64 noundef %82, ptr noundef %83)
  store i64 %84, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %85

85:                                               ; preds = %71, %65, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %86 = load i64, ptr %6, align 8
  ret i64 %86
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !16, i64 72, !17, i64 112, !17, i64 160, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !12, i64 240, !12, i64 248, !10, i64 256, !6, i64 264}
!15 = !{!"_EFI_BLOCK_IO_PROTOCOL", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!"_EFI_BLOCK_IO2_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{!"", !10, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !10, i64 12, !10, i64 16, !12, i64 24, !12, i64 32, !10, i64 40, !10, i64 44}
!18 = !{!14, !10, i64 256}
!19 = !{!14, !6, i64 208}
!20 = !{!14, !12, i64 240}
!21 = !{!14, !12, i64 248}
!22 = !{!23, !6, i64 16}
!23 = !{!"_EFI_DISK_IO_PROTOCOL", !12, i64 0, !6, i64 8, !6, 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 [154 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 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
declare dso_local i64 @ProbeMediaStatus(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @PartitionWriteBlocks(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %6, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre23 = add i64 %.pre, -24
  %.pre25 = inttoptr i64 %.pre23 to ptr
  br i1 %.not, label %._crit_edge, label %7

7:                                                ; preds = %5
  %8 = load i64, ptr %.pre25, align 8, !tbaa !5
  %.not21 = icmp eq i64 %8, 1953653072
  br i1 %.not21, label %._crit_edge, label %9

9:                                                ; preds = %7
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 734, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %7, %9
  %10 = phi ptr [ %0, %9 ], [ %.pre25, %7 ], [ %.pre25, %5 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 256
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %13 = zext i32 %12 to i64
  %14 = urem i64 %3, %13
  %.not22 = icmp eq i64 %14, 0
  br i1 %.not22, label %19, label %15

15:                                               ; preds = %._crit_edge
  %16 = getelementptr inbounds i8, ptr %10, i64 208
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = tail call i64 @ProbeMediaStatus(ptr noundef %17, i32 noundef %1, i64 noundef -9223372036854775804)
  br label %36

19:                                               ; preds = %._crit_edge
  %20 = tail call i64 @MultU64x32(i64 noundef %2, i32 noundef %12) #2
  %21 = getelementptr inbounds i8, ptr %10, i64 240
  %22 = load i64, ptr %21, align 8, !tbaa !17
  %23 = add i64 %22, %20
  %24 = add i64 %23, %3
  %25 = getelementptr inbounds i8, ptr %10, i64 248
  %26 = load i64, ptr %25, align 8, !tbaa !18
  %27 = icmp ugt i64 %24, %26
  %28 = getelementptr inbounds i8, ptr %10, i64 208
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  br i1 %27, label %30, label %32

30:                                               ; preds = %19
  %31 = tail call i64 @ProbeMediaStatus(ptr noundef %29, i32 noundef %1, i64 noundef -9223372036854775806)
  br label %36

32:                                               ; preds = %19
  %33 = getelementptr inbounds i8, ptr %29, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = tail call i64 %34(ptr noundef %29, i32 noundef %1, i64 noundef %23, i64 noundef %3, ptr noundef %4) #2
  br label %36

36:                                               ; preds = %32, %30, %15
  %.0 = phi i64 [ %18, %15 ], [ %31, %30 ], [ %35, %32 ]
  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 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 72, !13, i64 112, !13, i64 160, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !7, i64 240, !7, i64 248, !14, i64 256, !10, i64 264}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_BLOCK_IO_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!12 = !{!"_EFI_BLOCK_IO2_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!"", !14, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !14, i64 12, !14, i64 16, !7, i64 24, !7, i64 32, !14, i64 40, !14, i64 44}
!14 = !{!"int", !8, i64 0}
!15 = !{!6, !14, i64 256}
!16 = !{!6, !10, i64 208}
!17 = !{!6, !7, i64 240}
!18 = !{!6, !7, i64 248}
!19 = !{!20, !10, i64 16}
!20 = !{!"_EFI_DISK_IO_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass