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

; 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.DEBUGPORT_DEVICE = type { i32, ptr, ptr, ptr, %struct._EFI_DEBUGPORT_PROTOCOL, ptr, ptr, i64, i32, i32, i32, i8, i32 }
%struct._EFI_DEBUGPORT_PROTOCOL = type { ptr, ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.UART_DEVICE_PATH = type <{ %struct.EFI_DEVICE_PATH_PROTOCOL, i32, i64, i8, i8, i8 }>
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }

@mDebugPortDevice = external dso_local global %struct.DEBUGPORT_DEVICE, align 8
@.str = external hidden unnamed_addr constant [10 x i32], align 4
@gEfiDebugPortVariableGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @GetDebugPortVariable() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = call i64 @GetVariable2(ptr noundef @.str, ptr noundef @gEfiDebugPortVariableGuid, ptr noundef %3, ptr noundef %2)
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %0
  store ptr null, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %54

10:                                               ; preds = %0
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %31, %10
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call zeroext i8 @IsDevicePathEnd(ptr noundef %13)
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %29, label %16

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call zeroext i8 @DevicePathType(ptr noundef %17)
  %19 = zext i8 %18 to i32
  %20 = icmp eq i32 %19, 3
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call zeroext i8 @DevicePathSubType(ptr noundef %22)
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 14
  br label %26

26:                                               ; preds = %21, %16
  %27 = phi i1 [ false, %16 ], [ %25, %21 ]
  %28 = xor i1 %27, true
  br label %29

29:                                               ; preds = %26, %12
  %30 = phi i1 [ false, %12 ], [ %28, %26 ]
  br i1 %30, label %31, label %34

31:                                               ; preds = %29
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call ptr @NextDevicePathNode(ptr noundef %32)
  store ptr %33, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !9

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call zeroext i8 @IsDevicePathEnd(ptr noundef %35)
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %34
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  call void @FreePool(ptr noundef %39)
  store ptr null, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %54

40:                                               ; preds = %34
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %41, i32 0, i32 2
  %43 = call ptr @CopyMem(ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 7), ptr noundef %42, i64 noundef 8)
  store i32 16, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 8), align 8, !tbaa !11
  store i32 50000, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 9), align 4, !tbaa !16
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %44, i32 0, i32 4
  %46 = call ptr @CopyMem(ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 10), ptr noundef %45, i64 noundef 1)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %47, i32 0, i32 3
  %49 = call ptr @CopyMem(ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 11), ptr noundef %48, i64 noundef 1)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %50, i32 0, i32 5
  %52 = call ptr @CopyMem(ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 12), ptr noundef %51, i64 noundef 1)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %53, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %54

54:                                               ; preds = %40, %38, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %55 = load ptr, ptr %1, align 8
  ret ptr %55
}

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

declare i64 @GetVariable2(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare zeroext i8 @IsDevicePathEnd(ptr noundef) #2

declare zeroext i8 @DevicePathType(ptr noundef) #2

declare zeroext i8 @DevicePathSubType(ptr noundef) #2

declare ptr @NextDevicePathNode(ptr noundef) #2

declare void @FreePool(ptr noundef) #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 88}
!12 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !6, i64 64, !6, i64 72, !15, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !7, i64 100, !13, i64 104}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_EFI_DEBUGPORT_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"long long", !7, i64 0}
!16 = !{!12, !13, i64 92}


; 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.DEBUGPORT_DEVICE = type { i32, ptr, ptr, ptr, %struct._EFI_DEBUGPORT_PROTOCOL, ptr, ptr, i64, i32, i32, i32, i8, i32 }
%struct._EFI_DEBUGPORT_PROTOCOL = type { ptr, ptr, ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }

@mDebugPortDevice = external dso_local global %struct.DEBUGPORT_DEVICE, align 8
@.str = external hidden unnamed_addr constant [10 x i32], align 4
@gEfiDebugPortVariableGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @GetDebugPortVariable() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = call i64 @GetVariable2(ptr noundef nonnull @.str, ptr noundef nonnull @gEfiDebugPortVariableGuid, ptr noundef nonnull %2, ptr noundef nonnull %1) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %27, label %.preheader

.preheader:                                       ; preds = %0
  %6 = call zeroext i8 @IsDevicePathEnd(ptr noundef nonnull %4) #3
  %.not15 = icmp eq i8 %6, 0
  br i1 %.not15, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %.critedge14
  %.016 = phi ptr [ %12, %.critedge14 ], [ %4, %.preheader ]
  %7 = call zeroext i8 @DevicePathType(ptr noundef %.016) #3
  %8 = icmp eq i8 %7, 3
  br i1 %8, label %9, label %.critedge14

9:                                                ; preds = %.lr.ph
  %10 = call zeroext i8 @DevicePathSubType(ptr noundef %.016) #3
  %11 = icmp eq i8 %10, 14
  br i1 %11, label %.critedge, label %.critedge14

.critedge14:                                      ; preds = %.lr.ph, %9
  %12 = call ptr @NextDevicePathNode(ptr noundef %.016) #3
  %13 = call zeroext i8 @IsDevicePathEnd(ptr noundef %12) #3
  %.not = icmp eq i8 %13, 0
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %9, %.critedge14, %.preheader
  %.0.lcssa = phi ptr [ %4, %.preheader ], [ %12, %.critedge14 ], [ %.016, %9 ]
  %14 = call zeroext i8 @IsDevicePathEnd(ptr noundef %.0.lcssa) #3
  %.not12 = icmp eq i8 %14, 0
  br i1 %.not12, label %17, label %15

15:                                               ; preds = %.critedge
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %16) #3
  br label %27

17:                                               ; preds = %.critedge
  %18 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  %19 = call ptr @CopyMem(ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 80), ptr noundef nonnull %18, i64 noundef 8) #3
  store i32 16, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 88), align 8, !tbaa !11
  store i32 50000, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 92), align 4, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %.0.lcssa, i64 17
  %21 = call ptr @CopyMem(ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 96), ptr noundef nonnull %20, i64 noundef 1) #3
  %22 = getelementptr inbounds i8, ptr %.0.lcssa, i64 16
  %23 = call ptr @CopyMem(ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 100), ptr noundef nonnull %22, i64 noundef 1) #3
  %24 = getelementptr inbounds i8, ptr %.0.lcssa, i64 18
  %25 = call ptr @CopyMem(ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 104), ptr noundef nonnull %24, i64 noundef 1) #3
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %0, %17, %15
  %.010 = phi ptr [ null, %15 ], [ %26, %17 ], [ null, %0 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret ptr %.010
}

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

declare i64 @GetVariable2(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

declare ptr @NextDevicePathNode(ptr noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 88}
!12 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !6, i64 64, !6, i64 72, !15, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !7, i64 100, !13, i64 104}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_EFI_DEBUGPORT_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"long long", !7, i64 0}
!16 = !{!12, !13, i64 92}


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