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

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.BLOCKIO_VENDOR_DEVICE_PATH = type <{ %struct.VENDOR_DEVICE_PATH, i8 }>
%struct.VENDOR_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.GUID }
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }
%struct.BIOS_LEGACY_DRIVE = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, ptr, i8, i8, i8, i8, i16, i16, %struct.EDD_DRIVE_PARAMETERS }
%struct.EDD_DRIVE_PARAMETERS = type <{ i16, i16, i32, i32, i32, i64, i16, i32, i16, i8, i8, i16, [4 x i8], [8 x i8], %union.EDD_INTERFACE_PATH, %union.EDD_DEVICE_PATH, i8, i8 }>
%union.EDD_INTERFACE_PATH = type { %struct.EDD_PCI }
%struct.EDD_PCI = type { i8, i8, i8, i8, i32 }
%union.EDD_DEVICE_PATH = type { %struct.EDD_USB }
%struct.EDD_USB = type { i64, i64 }

@gBlockIoVendorGuid = external global %struct.GUID, align 4

; 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 ptr @ZeroMem(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @SetBiosInitBlockIoDevicePath(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca %struct.BLOCKIO_VENDOR_DEVICE_PATH, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 21, ptr %8) #3
  store i64 -9223372036854775805, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.BIOS_LEGACY_DRIVE, ptr %9, i32 0, i32 2
  %11 = load i8, ptr %10, align 2, !tbaa !11
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 48
  br i1 %13, label %14, label %19

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = call i64 @BuildEdd30DevicePath(ptr noundef %15, ptr noundef %16, ptr noundef %17)
  store i64 %18, ptr %7, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %14, %3
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %45

22:                                               ; preds = %19
  %23 = call ptr @ZeroMem(ptr noundef %8, i64 noundef 21)
  %24 = getelementptr inbounds %struct.BLOCKIO_VENDOR_DEVICE_PATH, ptr %8, i32 0, i32 0
  %25 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %25, i32 0, i32 0
  store i8 1, ptr %26, align 1, !tbaa !16
  %27 = getelementptr inbounds %struct.BLOCKIO_VENDOR_DEVICE_PATH, ptr %8, i32 0, i32 0
  %28 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %28, i32 0, i32 1
  store i8 4, ptr %29, align 1, !tbaa !21
  %30 = getelementptr inbounds %struct.BLOCKIO_VENDOR_DEVICE_PATH, ptr %8, i32 0, i32 0
  %31 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %30, i32 0, i32 0
  %32 = call zeroext i16 @SetDevicePathNodeLength(ptr noundef %31, i64 noundef 21)
  %33 = getelementptr inbounds %struct.BLOCKIO_VENDOR_DEVICE_PATH, ptr %8, i32 0, i32 0
  %34 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %33, i32 0, i32 1
  %35 = call ptr @CopyMem(ptr noundef %34, ptr noundef @gBlockIoVendorGuid, i64 noundef 16)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.BIOS_LEGACY_DRIVE, ptr %36, i32 0, i32 1
  %38 = load i8, ptr %37, align 1, !tbaa !22
  %39 = getelementptr inbounds %struct.BLOCKIO_VENDOR_DEVICE_PATH, ptr %8, i32 0, i32 1
  store i8 %38, ptr %39, align 1, !tbaa !23
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.BLOCKIO_VENDOR_DEVICE_PATH, ptr %8, i32 0, i32 0
  %42 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %41, i32 0, i32 0
  %43 = call ptr @AppendDevicePathNode(ptr noundef %40, ptr noundef %42)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %43, ptr %44, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %22, %19
  call void @llvm.lifetime.end.p0(i64 21, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

declare zeroext i16 @SetDevicePathNodeLength(ptr noundef, i64 noundef) #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

declare ptr @AppendDevicePathNode(ptr noundef, ptr noundef) #1

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 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 2}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !13, i64 28, !13, i64 30, !14, i64 32}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 2, !15, i64 4, !15, i64 8, !15, i64 12, !10, i64 16, !13, i64 24, !15, i64 26, !13, i64 30, !7, i64 32, !7, i64 33, !13, i64 34, !7, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 72, !7, i64 73}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !18, i64 0, !7, i64 20}
!18 = !{!"", !19, i64 0, !20, i64 4}
!19 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!20 = !{!"", !15, i64 0, !13, i64 4, !13, i64 6, !7, i64 8}
!21 = !{!17, !7, i64 1}
!22 = !{!12, !7, i64 1}
!23 = !{!17, !7, i64 20}


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

%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.BLOCKIO_VENDOR_DEVICE_PATH = type <{ %struct.VENDOR_DEVICE_PATH, i8 }>
%struct.VENDOR_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.GUID }
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }

@gBlockIoVendorGuid = external global %struct.GUID, align 4

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

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

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @SetBiosInitBlockIoDevicePath(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.BLOCKIO_VENDOR_DEVICE_PATH, align 1
  call void @llvm.lifetime.start.p0(i64 21, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %1, i64 2
  %6 = load i8, ptr %5, align 2, !tbaa !5
  %7 = icmp eq i8 %6, 48
  br i1 %7, label %8, label %.critedge

8:                                                ; preds = %3
  %9 = tail call i64 @BuildEdd30DevicePath(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %2)
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %.critedge, label %20

.critedge:                                        ; preds = %3, %8
  %11 = call ptr @ZeroMem(ptr noundef nonnull %4, i64 noundef 21) #3
  store i8 1, ptr %4, align 1, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 4, ptr %12, align 1, !tbaa !19
  %13 = call zeroext i16 @SetDevicePathNodeLength(ptr noundef nonnull %4, i64 noundef 21) #3
  %14 = getelementptr inbounds i8, ptr %4, i64 4
  %15 = call ptr @CopyMem(ptr noundef nonnull %14, ptr noundef nonnull @gBlockIoVendorGuid, i64 noundef 16) #3
  %16 = getelementptr inbounds i8, ptr %1, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %4, i64 20
  store i8 %17, ptr %18, align 1, !tbaa !21
  %19 = call ptr @AppendDevicePathNode(ptr noundef %0, ptr noundef nonnull %4) #3
  store ptr %19, ptr %2, align 8, !tbaa !22
  br label %20

20:                                               ; preds = %.critedge, %8
  call void @llvm.lifetime.end.p0(i64 21, ptr nonnull %4) #3
  ret void
}

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

declare zeroext i16 @SetDevicePathNodeLength(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @AppendDevicePathNode(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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, !7, i64 2}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !9, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !10, i64 28, !10, i64 30, !11, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 2, !12, i64 4, !12, i64 8, !12, i64 12, !13, i64 16, !10, i64 24, !12, i64 26, !10, i64 30, !7, i64 32, !7, i64 33, !10, i64 34, !7, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 72, !7, i64 73}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"", !16, i64 0, !7, i64 20}
!16 = !{!"", !17, i64 0, !18, i64 4}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!18 = !{!"", !12, i64 0, !10, i64 4, !10, i64 6, !7, i64 8}
!19 = !{!15, !7, i64 1}
!20 = !{!6, !7, i64 1}
!21 = !{!15, !7, i64 20}
!22 = !{!9, !9, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass