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

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

@gEfiSimpleTextInProtocolGuid = external global %struct.GUID, align 4
@gBS = external global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@.str.3 = external hidden unnamed_addr constant [6 x i32], align 4
@gEfiConsoleInDeviceGuid = external global %struct.GUID, align 4
@.str.4 = external hidden unnamed_addr constant [9 x i32], align 4

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

24:                                               ; preds = %3
  %25 = load i64, ptr %8, align 8, !tbaa !16
  store i64 %25, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %83

26:                                               ; preds = %3
  %27 = load ptr, ptr @gBS, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %27, i32 0, i32 33
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i64 %29(ptr noundef %30, ptr noundef @gEfiSimpleTextInProtocolGuid, ptr noundef %10, ptr noundef %33, ptr noundef %34, i32 noundef 16)
  store i64 %35, ptr %8, align 8, !tbaa !16
  %36 = load i64, ptr %8, align 8, !tbaa !16
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %26
  %39 = load i64, ptr %8, align 8, !tbaa !16
  store i64 %39, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %83

40:                                               ; preds = %26
  store i8 0, ptr %11, align 1, !tbaa !17
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef @.str.3, ptr noundef %41, i32 noundef 0)
  store i64 %42, ptr %8, align 8, !tbaa !16
  %43 = load i64, ptr %8, align 8, !tbaa !16
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %40
  store i8 1, ptr %11, align 1, !tbaa !17
  br label %46

46:                                               ; preds = %45, %40
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = call zeroext i8 @IsHotPlugDevice(ptr noundef %47)
  %49 = icmp ne i8 %48, 0
  br i1 %49, label %50, label %61

50:                                               ; preds = %46
  %51 = load ptr, ptr @gBS, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %51, i32 0, i32 39
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = call i64 (ptr, ...) %53(ptr noundef %6, ptr noundef @gEfiConsoleInDeviceGuid, ptr noundef null, ptr noundef null)
  %55 = load i8, ptr %11, align 1, !tbaa !17
  %56 = icmp ne i8 %55, 0
  br i1 %56, label %57, label %60

57:                                               ; preds = %50
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef @.str.4, ptr noundef %58, i32 noundef 1)
  br label %60

60:                                               ; preds = %57, %50
  br label %82

61:                                               ; preds = %46
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef @.str.4, ptr noundef %62, i32 noundef 1)
  %64 = load i8, ptr %11, align 1, !tbaa !17
  %65 = icmp ne i8 %64, 0
  br i1 %65, label %66, label %71

66:                                               ; preds = %61
  %67 = load ptr, ptr @gBS, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %67, i32 0, i32 39
  %69 = load ptr, ptr %68, align 8, !tbaa !18
  %70 = call i64 (ptr, ...) %69(ptr noundef %6, ptr noundef @gEfiConsoleInDeviceGuid, ptr noundef null, ptr noundef null)
  br label %81

71:                                               ; preds = %61
  %72 = load ptr, ptr @gBS, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %72, i32 0, i32 34
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %76, i32 0, i32 5
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call i64 %74(ptr noundef %75, ptr noundef @gEfiSimpleTextInProtocolGuid, ptr noundef %78, ptr noundef %79)
  br label %81

81:                                               ; preds = %71, %66
  br label %82

82:                                               ; preds = %81, %60
  store i64 0, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %83

83:                                               ; preds = %82, %38, %24
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %84 = load i64, ptr %4, align 8
  ret i64 %84
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IsHotPlugDevice(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 280}
!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 = !{!15, !6, i64 40}
!15 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!12, !12, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !6, i64 328}
!19 = !{!10, !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] }

@gEfiSimpleTextInProtocolGuid = external global %struct.GUID, align 4
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4
@.str.3 = external hidden unnamed_addr constant [6 x i32], align 4
@gEfiConsoleInDeviceGuid = external global %struct.GUID, align 4
@.str.4 = external hidden unnamed_addr constant [9 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @ConPlatformTextInDriverBindingStart(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #2
  %7 = load ptr, ptr @gBS, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 280
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = call i64 %9(ptr noundef %1, ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef nonnull %5, ptr noundef %11, ptr noundef %1, i32 noundef 2) #2
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %49, label %14

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

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef nonnull @.str.3, ptr noundef %22, i32 noundef 0)
  %24 = icmp slt i64 %23, 0
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call zeroext i8 @IsHotPlugDevice(ptr noundef %25)
  %.not = icmp eq i8 %26, 0
  br i1 %.not, label %35, label %27

27:                                               ; preds = %21
  %28 = load ptr, ptr @gBS, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 328
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = call i64 (ptr, ...) %30(ptr noundef nonnull %4, ptr noundef nonnull @gEfiConsoleInDeviceGuid, ptr noundef null, ptr noundef null) #2
  br i1 %24, label %49, label %32

32:                                               ; preds = %27
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef nonnull @.str.4, ptr noundef %33, i32 noundef 1)
  br label %49

35:                                               ; preds = %21
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i64 @ConPlatformUpdateDeviceVariable(ptr noundef nonnull @.str.4, ptr noundef %36, i32 noundef 1)
  %38 = load ptr, ptr @gBS, align 8, !tbaa !5
  br i1 %24, label %43, label %39

39:                                               ; preds = %35
  %40 = getelementptr inbounds i8, ptr %38, i64 328
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = call i64 (ptr, ...) %41(ptr noundef nonnull %4, ptr noundef nonnull @gEfiConsoleInDeviceGuid, ptr noundef null, ptr noundef null) #2
  br label %49

43:                                               ; preds = %35
  %44 = getelementptr inbounds i8, ptr %38, i64 288
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !14
  %48 = call i64 %45(ptr noundef %46, ptr noundef nonnull @gEfiSimpleTextInProtocolGuid, ptr noundef %47, ptr noundef %46) #2
  br label %49

49:                                               ; preds = %32, %27, %43, %39, %14, %3
  %.010 = phi i64 [ %12, %3 ], [ %19, %14 ], [ 0, %39 ], [ 0, %43 ], [ 0, %27 ], [ 0, %32 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #2
  ret i64 %.010
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IsHotPlugDevice(ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 280}
!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 = !{!15, !6, i64 40}
!15 = !{!"_EFI_DRIVER_BINDING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!10, !6, i64 328}
!17 = !{!10, !6, i64 288}


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