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

; 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_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_OPEN_PROTOCOL_INFORMATION_ENTRY = type { ptr, ptr, i32, i32 }

@gBS = external global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@.str.7 = external hidden unnamed_addr constant [10 x i32], align 4
@.str.8 = external hidden unnamed_addr constant [10 x i32], align 4
@gEfiGraphicsOutputProtocolGuid = external global %struct.GUID, align 4
@gEfiPciIoProtocolGuid = 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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @ConPlatformUpdateGopCandidate(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %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 i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = 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 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  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 %3, align 8, !tbaa !5
  store ptr %13, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %14, i32 0, i32 21
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = call i64 %16(ptr noundef @gEfiGraphicsOutputProtocolGuid, ptr noundef %11, ptr noundef %6)
  store i64 %17, ptr %4, align 8, !tbaa !14
  %18 = load i64, ptr %4, align 8, !tbaa !14
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %1
  store i8 0, ptr %2, align 1
  store i32 1, ptr %12, align 4
  br label %75

21:                                               ; preds = %1
  %22 = load ptr, ptr @gBS, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %22, i32 0, i32 21
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call i64 %24(ptr noundef @gEfiPciIoProtocolGuid, ptr noundef %3, ptr noundef %5)
  store i64 %25, ptr %4, align 8, !tbaa !14
  %26 = load i64, ptr %4, align 8, !tbaa !14
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  store i8 0, ptr %2, align 1
  store i32 1, ptr %12, align 4
  br label %75

29:                                               ; preds = %21
  %30 = load ptr, ptr @gBS, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %30, i32 0, i32 35
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i64 %32(ptr noundef %33, ptr noundef @gEfiPciIoProtocolGuid, ptr noundef %7, ptr noundef %8)
  store i64 %34, ptr %4, align 8, !tbaa !14
  %35 = load i64, ptr %4, align 8, !tbaa !14
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %29
  store i8 0, ptr %2, align 1
  store i32 1, ptr %12, align 4
  br label %75

38:                                               ; preds = %29
  store i64 0, ptr %9, align 8, !tbaa !14
  br label %39

39:                                               ; preds = %70, %38
  %40 = load i64, ptr %9, align 8, !tbaa !14
  %41 = load i64, ptr %8, align 8, !tbaa !14
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %43, label %73

43:                                               ; preds = %39
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !14
  %46 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %44, i64 %45
  %47 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 8, !tbaa !16
  %49 = and i32 %48, 8
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %69

51:                                               ; preds = %43
  %52 = load ptr, ptr @gBS, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %52, i32 0, i32 33
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i64, ptr %9, align 8, !tbaa !14
  %57 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %55, i64 %56
  %58 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = call i64 %54(ptr noundef %59, ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %10, ptr noundef null, ptr noundef null, i32 noundef 2)
  store i64 %60, ptr %4, align 8, !tbaa !14
  %61 = load i64, ptr %4, align 8, !tbaa !14
  %62 = icmp slt i64 %61, 0
  br i1 %62, label %68, label %63

63:                                               ; preds = %51
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef @.str.7, ptr noundef %64, i32 noundef 1)
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef @.str.8, ptr noundef %66, i32 noundef 1)
  br label %68

68:                                               ; preds = %63, %51
  br label %69

69:                                               ; preds = %68, %43
  br label %70

70:                                               ; preds = %69
  %71 = load i64, ptr %9, align 8, !tbaa !14
  %72 = add i64 %71, 1
  store i64 %72, ptr %9, align 8, !tbaa !14
  br label %39, !llvm.loop !20

73:                                               ; preds = %39
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  call void @FreePool(ptr noundef %74)
  store i8 1, ptr %2, align 1
  store i32 1, ptr %12, align 4
  br label %75

75:                                               ; preds = %73, %37, %28, %20
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  %76 = load i8, ptr %2, align 1
  ret i8 %76
}

declare void @FreePool(ptr noundef) #2

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 = { "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, !6, i64 184}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !6, i64 296}
!16 = !{!17, !13, i64 16}
!17 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20}
!18 = !{!10, !6, i64 280}
!19 = !{!17, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY = type { ptr, ptr, i32, i32 }

@gBS = external local_unnamed_addr global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@.str.7 = external hidden unnamed_addr constant [10 x i32], align 4
@.str.8 = external hidden unnamed_addr constant [10 x i32], align 4
@gEfiGraphicsOutputProtocolGuid = external global %struct.GUID, align 4
@gEfiPciIoProtocolGuid = 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @ConPlatformUpdateDeviceVariable(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @ConPlatformUpdateGopCandidate(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  store ptr %0, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr @gBS, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 184
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = call i64 %11(ptr noundef nonnull @gEfiGraphicsOutputProtocolGuid, ptr noundef nonnull %8, ptr noundef nonnull %4) #3
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %51, label %14

14:                                               ; preds = %1
  %15 = load ptr, ptr @gBS, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 184
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call i64 %17(ptr noundef nonnull @gEfiPciIoProtocolGuid, ptr noundef nonnull %2, ptr noundef nonnull %3) #3
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %51, label %20

20:                                               ; preds = %14
  %21 = load ptr, ptr @gBS, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 296
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call i64 %23(ptr noundef %24, ptr noundef nonnull @gEfiPciIoProtocolGuid, ptr noundef nonnull %5, ptr noundef nonnull %6) #3
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %51, label %.preheader

.preheader:                                       ; preds = %20
  %27 = load i64, ptr %6, align 8, !tbaa !15
  %.not11 = icmp eq i64 %27, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %46
  %.010 = phi i64 [ %47, %46 ], [ 0, %.preheader ]
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %28, i64 %.010
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !16
  %32 = and i32 %31, 8
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %46, label %33

33:                                               ; preds = %.lr.ph
  %34 = load ptr, ptr @gBS, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 280
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = getelementptr inbounds i8, ptr %29, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = call i64 %36(ptr noundef %38, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef nonnull %7, ptr noundef null, ptr noundef null, i32 noundef 2) #3
  %40 = icmp slt i64 %39, 0
  br i1 %40, label %46, label %41

41:                                               ; preds = %33
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef nonnull @.str.7, ptr noundef %42, i32 noundef 1)
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef nonnull @.str.8, ptr noundef %44, i32 noundef 1)
  br label %46

46:                                               ; preds = %.lr.ph, %41, %33
  %47 = add nuw i64 %.010, 1
  %48 = load i64, ptr %6, align 8, !tbaa !15
  %49 = icmp ult i64 %47, %48
  br i1 %49, label %.lr.ph, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %46, %.preheader
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  call void @FreePool(ptr noundef %50) #3
  br label %51

51:                                               ; preds = %20, %14, %1, %._crit_edge
  %.09 = phi i8 [ 1, %._crit_edge ], [ 0, %1 ], [ 0, %14 ], [ 0, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i8 %.09
}

declare void @FreePool(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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, !6, i64 184}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 296}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !13, i64 16}
!17 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20}
!18 = !{!10, !6, i64 280}
!19 = !{!17, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass