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

; 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.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct._EFI_DRIVER_BINDING_PROTOCOL = type { ptr, ptr, ptr, i32, ptr, ptr }

@gBS = external global ptr, align 8
@gEfiDiskIoProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiBlockIoProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @PartitionDriverBindingSupported(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %39

15:                                               ; preds = %3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = call zeroext i8 @IsDevicePathEnd(ptr noundef %16)
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %38, label %19

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %20, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %21, i32 0, i32 0
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = icmp ne i32 %24, 4
  br i1 %25, label %36, label %26

26:                                               ; preds = %19
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %27, i32 0, i32 1
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %36, label %32

32:                                               ; preds = %26
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = call i64 @DevicePathNodeLength(ptr noundef %33)
  %35 = icmp ne i64 %34, 42
  br i1 %35, label %36, label %37

36:                                               ; preds = %32, %26, %19
  store i64 -9223372036854775805, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %104

37:                                               ; preds = %32
  br label %38

38:                                               ; preds = %37, %15
  br label %39

39:                                               ; preds = %38, %3
  %40 = load ptr, ptr @gBS, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %40, i32 0, i32 33
  %42 = load ptr, ptr %41, align 8, !tbaa !10
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %44, i32 0, i32 5
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i64 %42(ptr noundef %43, ptr noundef @gEfiDiskIoProtocolGuid, ptr noundef %10, ptr noundef %46, ptr noundef %47, i32 noundef 16)
  store i64 %48, ptr %8, align 8, !tbaa !17
  %49 = load i64, ptr %8, align 8, !tbaa !17
  %50 = icmp eq i64 %49, -9223372036854775788
  br i1 %50, label %51, label %52

51:                                               ; preds = %39
  store i64 0, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %104

52:                                               ; preds = %39
  %53 = load i64, ptr %8, align 8, !tbaa !17
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = load i64, ptr %8, align 8, !tbaa !17
  store i64 %56, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %104

57:                                               ; preds = %52
  %58 = load ptr, ptr @gBS, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %58, i32 0, i32 34
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %62, i32 0, i32 5
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call i64 %60(ptr noundef %61, ptr noundef @gEfiDiskIoProtocolGuid, ptr noundef %64, ptr noundef %65)
  %67 = load ptr, ptr @gBS, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %67, i32 0, i32 33
  %69 = load ptr, ptr %68, align 8, !tbaa !10
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %71, i32 0, i32 5
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = call i64 %69(ptr noundef %70, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %9, ptr noundef %73, ptr noundef %74, i32 noundef 16)
  store i64 %75, ptr %8, align 8, !tbaa !17
  %76 = load i64, ptr %8, align 8, !tbaa !17
  %77 = icmp eq i64 %76, -9223372036854775788
  br i1 %77, label %78, label %79

78:                                               ; preds = %57
  store i64 0, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %104

79:                                               ; preds = %57
  %80 = load i64, ptr %8, align 8, !tbaa !17
  %81 = icmp slt i64 %80, 0
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = load i64, ptr %8, align 8, !tbaa !17
  store i64 %83, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %104

84:                                               ; preds = %79
  %85 = load ptr, ptr @gBS, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %85, i32 0, i32 34
  %87 = load ptr, ptr %86, align 8, !tbaa !18
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %89, i32 0, i32 5
  %91 = load ptr, ptr %90, align 8, !tbaa !15
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = call i64 %87(ptr noundef %88, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %91, ptr noundef %92)
  %94 = load ptr, ptr @gBS, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %94, i32 0, i32 33
  %96 = load ptr, ptr %95, align 8, !tbaa !10
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %98, i32 0, i32 5
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = call i64 %96(ptr noundef %97, ptr noundef @gEfiBlockIoProtocolGuid, ptr noundef null, ptr noundef %100, ptr noundef %101, i32 noundef 4)
  store i64 %102, ptr %8, align 8, !tbaa !17
  %103 = load i64, ptr %8, align 8, !tbaa !17
  store i64 %103, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %104

104:                                              ; preds = %84, %82, %78, %55, %51, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %105 = load i64, ptr %4, align 8
  ret i64 %105
}

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

declare zeroext i8 @IsDevicePathEnd(ptr noundef) #2

declare i64 @DevicePathNodeLength(ptr noundef) #2

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

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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 280}
!11 = !{!"", !12, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 40}
!16 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!13, !13, i64 0}
!18 = !{!11, !6, i64 288}


; 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] }

@gBS = external local_unnamed_addr global ptr, align 8
@gEfiDiskIoProtocolGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@gEfiBlockIoProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @PartitionDriverBindingSupported(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %15, label %6

6:                                                ; preds = %3
  %7 = tail call zeroext i8 @IsDevicePathEnd(ptr noundef nonnull %2) #3
  %.not31 = icmp eq i8 %7, 0
  br i1 %.not31, label %8, label %15

8:                                                ; preds = %6
  %9 = load i8, ptr %2, align 1, !tbaa !5
  %.not32 = icmp eq i8 %9, 4
  br i1 %.not32, label %10, label %50

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %2, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not33 = icmp eq i8 %12, 1
  br i1 %.not33, label %13, label %50

13:                                               ; preds = %10
  %14 = tail call i64 @DevicePathNodeLength(ptr noundef nonnull %2) #3
  %.not34 = icmp eq i64 %14, 42
  br i1 %.not34, label %15, label %50

15:                                               ; preds = %6, %13, %3
  %16 = load ptr, ptr @gBS, align 8, !tbaa !8
  %17 = getelementptr inbounds i8, ptr %16, i64 280
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = call i64 %18(ptr noundef %1, ptr noundef nonnull @gEfiDiskIoProtocolGuid, ptr noundef nonnull %5, ptr noundef %20, ptr noundef %1, i32 noundef 16) #3
  %22 = icmp eq i64 %21, -9223372036854775788
  br i1 %22, label %50, label %23

23:                                               ; preds = %15
  %24 = icmp slt i64 %21, 0
  br i1 %24, label %50, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr @gBS, align 8, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %26, i64 288
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load ptr, ptr %19, align 8, !tbaa !15
  %30 = call i64 %28(ptr noundef %1, ptr noundef nonnull @gEfiDiskIoProtocolGuid, ptr noundef %29, ptr noundef %1) #3
  %31 = load ptr, ptr @gBS, align 8, !tbaa !8
  %32 = getelementptr inbounds i8, ptr %31, i64 280
  %33 = load ptr, ptr %32, align 8, !tbaa !10
  %34 = load ptr, ptr %19, align 8, !tbaa !15
  %35 = call i64 %33(ptr noundef %1, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef nonnull %4, ptr noundef %34, ptr noundef %1, i32 noundef 16) #3
  %36 = icmp eq i64 %35, -9223372036854775788
  br i1 %36, label %50, label %37

37:                                               ; preds = %25
  %38 = icmp slt i64 %35, 0
  br i1 %38, label %50, label %39

39:                                               ; preds = %37
  %40 = load ptr, ptr @gBS, align 8, !tbaa !8
  %41 = getelementptr inbounds i8, ptr %40, i64 288
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = load ptr, ptr %19, align 8, !tbaa !15
  %44 = call i64 %42(ptr noundef %1, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef %43, ptr noundef %1) #3
  %45 = load ptr, ptr @gBS, align 8, !tbaa !8
  %46 = getelementptr inbounds i8, ptr %45, i64 280
  %47 = load ptr, ptr %46, align 8, !tbaa !10
  %48 = load ptr, ptr %19, align 8, !tbaa !15
  %49 = call i64 %47(ptr noundef %1, ptr noundef nonnull @gEfiBlockIoProtocolGuid, ptr noundef null, ptr noundef %48, ptr noundef %1, i32 noundef 4) #3
  br label %50

50:                                               ; preds = %37, %25, %23, %15, %8, %10, %13, %39
  %.0 = phi i64 [ %49, %39 ], [ -9223372036854775805, %13 ], [ -9223372036854775805, %10 ], [ -9223372036854775805, %8 ], [ 0, %15 ], [ %21, %23 ], [ 0, %25 ], [ %35, %37 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i64 %.0
}

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

declare zeroext i8 @IsDevicePathEnd(ptr noundef) local_unnamed_addr #2

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #2

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

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 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 280}
!11 = !{!"", !12, i64 0, !9, i64 24, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !9, i64 120, !9, i64 128, !9, i64 136, !9, i64 144, !9, i64 152, !9, i64 160, !9, i64 168, !9, i64 176, !9, i64 184, !9, i64 192, !9, i64 200, !9, i64 208, !9, i64 216, !9, i64 224, !9, i64 232, !9, i64 240, !9, i64 248, !9, i64 256, !9, i64 264, !9, i64 272, !9, i64 280, !9, i64 288, !9, i64 296, !9, i64 304, !9, i64 312, !9, i64 320, !9, i64 328, !9, i64 336, !9, i64 344, !9, i64 352, !9, i64 360, !9, i64 368}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!13 = !{!"long long", !6, i64 0}
!14 = !{!"int", !6, i64 0}
!15 = !{!16, !9, i64 40}
!16 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !9, i64 0, !9, i64 8, !9, i64 16, !14, i64 24, !9, i64 32, !9, i64 40}
!17 = !{!11, !9, i64 288}


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