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

; 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.DEBUGPORT_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.GUID }
%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 }
%struct._EFI_SERIAL_IO_PROTOCOL = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@mDebugPortDevice = external dso_local global %struct.DEBUGPORT_DEVICE, align 8
@gBS = external global ptr, align 8
@gEfiDebugPortProtocolGuid = external global %struct.GUID, align 4
@gEfiSerialIoProtocolGuid = external global %struct.GUID, align 4
@gEfiDebugPortDevicePathGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @DebugPortStart(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 %struct.DEBUGPORT_DEVICE_PATH, align 4
  %10 = alloca %struct.EFI_DEVICE_PATH_PROTOCOL, align 1
  %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 20, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %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 @gEfiSerialIoProtocolGuid, ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), ptr noundef %19, ptr noundef %20, i32 noundef 48)
  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 %136

26:                                               ; preds = %3
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 5), align 8, !tbaa !17
  %28 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), align 8, !tbaa !20
  %29 = getelementptr inbounds %struct._EFI_SERIAL_IO_PROTOCOL, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  %31 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), align 8, !tbaa !20
  %32 = load i64, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 7), align 8, !tbaa !23
  %33 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 8), align 8, !tbaa !24
  %34 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 9), align 4, !tbaa !25
  %35 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 10), align 8, !tbaa !26
  %36 = load i8, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 11), align 4, !tbaa !27
  %37 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 12), align 8, !tbaa !28
  %38 = call i64 %30(ptr noundef %31, i64 noundef %32, i32 noundef %33, i32 noundef %34, i32 noundef %35, i8 noundef zeroext %36, i32 noundef %37)
  store i64 %38, ptr %8, align 8, !tbaa !16
  %39 = load i64, ptr %8, align 8, !tbaa !16
  %40 = icmp slt i64 %39, 0
  br i1 %40, label %41, label %67

41:                                               ; preds = %26
  store i64 0, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 7), align 8, !tbaa !23
  store i32 0, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 10), align 8, !tbaa !26
  store i8 0, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 11), align 4, !tbaa !27
  store i32 0, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 12), align 8, !tbaa !28
  store i32 0, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 8), align 8, !tbaa !24
  %42 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), align 8, !tbaa !20
  %43 = getelementptr inbounds %struct._EFI_SERIAL_IO_PROTOCOL, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  %45 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), align 8, !tbaa !20
  %46 = load i64, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 7), align 8, !tbaa !23
  %47 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 8), align 8, !tbaa !24
  %48 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 9), align 4, !tbaa !25
  %49 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 10), align 8, !tbaa !26
  %50 = load i8, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 11), align 4, !tbaa !27
  %51 = load i32, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 12), align 8, !tbaa !28
  %52 = call i64 %44(ptr noundef %45, i64 noundef %46, i32 noundef %47, i32 noundef %48, i32 noundef %49, i8 noundef zeroext %50, i32 noundef %51)
  store i64 %52, ptr %8, align 8, !tbaa !16
  %53 = load i64, ptr %8, align 8, !tbaa !16
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %66

55:                                               ; preds = %41
  %56 = load ptr, ptr @gBS, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %56, i32 0, i32 34
  %58 = load ptr, ptr %57, align 8, !tbaa !29
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = call i64 %58(ptr noundef %59, ptr noundef @gEfiSerialIoProtocolGuid, ptr noundef %62, ptr noundef %63)
  %65 = load i64, ptr %8, align 8, !tbaa !16
  store i64 %65, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %136

66:                                               ; preds = %41
  br label %67

67:                                               ; preds = %66, %26
  %68 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), align 8, !tbaa !20
  %69 = getelementptr inbounds %struct._EFI_SERIAL_IO_PROTOCOL, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !30
  %71 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), align 8, !tbaa !20
  %72 = call i64 %70(ptr noundef %71)
  %73 = getelementptr inbounds %struct.DEBUGPORT_DEVICE_PATH, ptr %9, i32 0, i32 0
  %74 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %73, i32 0, i32 0
  store i8 3, ptr %74, align 4, !tbaa !31
  %75 = getelementptr inbounds %struct.DEBUGPORT_DEVICE_PATH, ptr %9, i32 0, i32 0
  %76 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %75, i32 0, i32 1
  store i8 10, ptr %76, align 1, !tbaa !36
  %77 = getelementptr inbounds %struct.DEBUGPORT_DEVICE_PATH, ptr %9, i32 0, i32 0
  %78 = call zeroext i16 @SetDevicePathNodeLength(ptr noundef %77, i64 noundef 20)
  %79 = getelementptr inbounds %struct.DEBUGPORT_DEVICE_PATH, ptr %9, i32 0, i32 1
  %80 = call ptr @CopyGuid(ptr noundef %79, ptr noundef @gEfiDebugPortDevicePathGuid)
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = call ptr @DevicePathFromHandle(ptr noundef %81)
  store ptr %82, ptr %11, align 8, !tbaa !5
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = icmp eq ptr %83, null
  br i1 %84, label %85, label %87

85:                                               ; preds = %67
  store ptr %10, ptr %11, align 8, !tbaa !5
  %86 = load ptr, ptr %11, align 8, !tbaa !5
  call void @SetDevicePathEndNode(ptr noundef %86)
  br label %87

87:                                               ; preds = %85, %67
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = call ptr @AppendDevicePathNode(ptr noundef %88, ptr noundef %9)
  store ptr %89, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 3), align 8, !tbaa !37
  %90 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 3), align 8, !tbaa !37
  %91 = icmp eq ptr %90, null
  br i1 %91, label %92, label %93

92:                                               ; preds = %87
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %136

93:                                               ; preds = %87
  %94 = load ptr, ptr @gBS, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %94, i32 0, i32 39
  %96 = load ptr, ptr %95, align 8, !tbaa !38
  %97 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 3), align 8, !tbaa !37
  %98 = call i64 (ptr, ...) %96(ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 2), ptr noundef @gEfiDevicePathProtocolGuid, ptr noundef %97, ptr noundef @gEfiDebugPortProtocolGuid, ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 4), ptr noundef null)
  store i64 %98, ptr %8, align 8, !tbaa !16
  %99 = load i64, ptr %8, align 8, !tbaa !16
  %100 = icmp slt i64 %99, 0
  br i1 %100, label %101, label %112

101:                                              ; preds = %93
  %102 = load ptr, ptr @gBS, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %102, i32 0, i32 34
  %104 = load ptr, ptr %103, align 8, !tbaa !29
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %106, i32 0, i32 5
  %108 = load ptr, ptr %107, align 8, !tbaa !14
  %109 = load ptr, ptr %6, align 8, !tbaa !5
  %110 = call i64 %104(ptr noundef %105, ptr noundef @gEfiSerialIoProtocolGuid, ptr noundef %108, ptr noundef %109)
  %111 = load i64, ptr %8, align 8, !tbaa !16
  store i64 %111, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %136

112:                                              ; preds = %93
  %113 = load ptr, ptr @gBS, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %113, i32 0, i32 33
  %115 = load ptr, ptr %114, align 8, !tbaa !9
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = load ptr, ptr %5, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %117, i32 0, i32 5
  %119 = load ptr, ptr %118, align 8, !tbaa !14
  %120 = load ptr, ptr getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 2), align 8, !tbaa !39
  %121 = call i64 %115(ptr noundef %116, ptr noundef @gEfiSerialIoProtocolGuid, ptr noundef getelementptr inbounds (%struct.DEBUGPORT_DEVICE, ptr @mDebugPortDevice, i32 0, i32 6), ptr noundef %119, ptr noundef %120, i32 noundef 8)
  store i64 %121, ptr %8, align 8, !tbaa !16
  %122 = load i64, ptr %8, align 8, !tbaa !16
  %123 = icmp slt i64 %122, 0
  br i1 %123, label %124, label %135

124:                                              ; preds = %112
  %125 = load ptr, ptr @gBS, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %125, i32 0, i32 34
  %127 = load ptr, ptr %126, align 8, !tbaa !29
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  %129 = load ptr, ptr %5, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct._EFI_DRIVER_BINDING_PROTOCOL, ptr %129, i32 0, i32 5
  %131 = load ptr, ptr %130, align 8, !tbaa !14
  %132 = load ptr, ptr %6, align 8, !tbaa !5
  %133 = call i64 %127(ptr noundef %128, ptr noundef @gEfiSerialIoProtocolGuid, ptr noundef %131, ptr noundef %132)
  %134 = load i64, ptr %8, align 8, !tbaa !16
  store i64 %134, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %136

135:                                              ; preds = %112
  store i64 0, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %136

136:                                              ; preds = %135, %124, %101, %92, %55, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %137 = load i64, ptr %4, align 8
  ret i64 %137
}

; 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

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

declare ptr @CopyGuid(ptr noundef, ptr noundef) #2

declare ptr @DevicePathFromHandle(ptr noundef) #2

declare void @SetDevicePathEndNode(ptr noundef) #2

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

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 = !{!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 = !{!18, !6, i64 64}
!18 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !19, i64 32, !6, i64 64, !6, i64 72, !12, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !7, i64 100, !13, i64 104}
!19 = !{!"_EFI_DEBUGPORT_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!18, !6, i64 72}
!21 = !{!22, !6, i64 16}
!22 = !{!"_EFI_SERIAL_IO_PROTOCOL", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!23 = !{!18, !12, i64 80}
!24 = !{!18, !13, i64 88}
!25 = !{!18, !13, i64 92}
!26 = !{!18, !13, i64 96}
!27 = !{!18, !7, i64 100}
!28 = !{!18, !13, i64 104}
!29 = !{!10, !6, i64 288}
!30 = !{!22, !6, i64 8}
!31 = !{!32, !7, i64 0}
!32 = !{!"", !33, i64 0, !34, i64 4}
!33 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!34 = !{!"", !13, i64 0, !35, i64 4, !35, i64 6, !7, i64 8}
!35 = !{!"short", !7, i64 0}
!36 = !{!32, !7, i64 1}
!37 = !{!18, !6, i64 24}
!38 = !{!10, !6, i64 328}
!39 = !{!18, !6, i64 16}


; 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] }
%struct.DEBUGPORT_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.GUID }
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }

@mDebugPortDevice = external dso_local global %struct.DEBUGPORT_DEVICE, align 8
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiDebugPortProtocolGuid = external global %struct.GUID, align 4
@gEfiSerialIoProtocolGuid = external global %struct.GUID, align 4
@gEfiDebugPortDevicePathGuid = external global %struct.GUID, align 4
@gEfiDevicePathProtocolGuid = external global %struct.GUID, align 4

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

13:                                               ; preds = %3
  store ptr %1, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 64), align 8, !tbaa !16
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 72), align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 80), align 8, !tbaa !22
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 88), align 8, !tbaa !23
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 92), align 4, !tbaa !24
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 96), align 8, !tbaa !25
  %21 = load i8, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 100), align 4, !tbaa !26
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 104), align 8, !tbaa !27
  %23 = tail call i64 %16(ptr noundef %14, i64 noundef %17, i32 noundef %18, i32 noundef %19, i32 noundef %20, i8 noundef zeroext %21, i32 noundef %22) #3
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %38

25:                                               ; preds = %13
  store i64 0, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 80), align 8, !tbaa !22
  store i32 0, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 96), align 8, !tbaa !25
  store i8 0, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 100), align 4, !tbaa !26
  store i32 0, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 104), align 8, !tbaa !27
  store i32 0, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 88), align 8, !tbaa !23
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 72), align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 92), align 4, !tbaa !24
  %30 = tail call i64 %28(ptr noundef %26, i64 noundef 0, i32 noundef 0, i32 noundef %29, i32 noundef 0, i8 noundef zeroext 0, i32 noundef 0) #3
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %38

32:                                               ; preds = %25
  %33 = load ptr, ptr @gBS, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 288
  %35 = load ptr, ptr %34, align 8, !tbaa !28
  %36 = load ptr, ptr %9, align 8, !tbaa !14
  %37 = tail call i64 %35(ptr noundef %1, ptr noundef nonnull @gEfiSerialIoProtocolGuid, ptr noundef %36, ptr noundef %1) #3
  br label %77

38:                                               ; preds = %25, %13
  %39 = load ptr, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 72), align 8, !tbaa !19
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load ptr, ptr %40, align 8, !tbaa !29
  %42 = tail call i64 %41(ptr noundef %39) #3
  store i8 3, ptr %4, align 4, !tbaa !30
  %43 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 10, ptr %43, align 1, !tbaa !35
  %44 = call zeroext i16 @SetDevicePathNodeLength(ptr noundef nonnull %4, i64 noundef 20) #3
  %45 = getelementptr inbounds i8, ptr %4, i64 4
  %46 = call ptr @CopyGuid(ptr noundef nonnull %45, ptr noundef nonnull @gEfiDebugPortDevicePathGuid) #3
  %47 = call ptr @DevicePathFromHandle(ptr noundef %1) #3
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %50

49:                                               ; preds = %38
  call void @SetDevicePathEndNode(ptr noundef nonnull %5) #3
  br label %50

50:                                               ; preds = %49, %38
  %.0 = phi ptr [ %5, %49 ], [ %47, %38 ]
  %51 = call ptr @AppendDevicePathNode(ptr noundef nonnull %.0, ptr noundef nonnull %4) #3
  store ptr %51, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 24), align 8, !tbaa !36
  %52 = icmp eq ptr %51, null
  br i1 %52, label %77, label %53

53:                                               ; preds = %50
  %54 = load ptr, ptr @gBS, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 328
  %56 = load ptr, ptr %55, align 8, !tbaa !37
  %57 = call i64 (ptr, ...) %56(ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 16), ptr noundef nonnull @gEfiDevicePathProtocolGuid, ptr noundef nonnull %51, ptr noundef nonnull @gEfiDebugPortProtocolGuid, ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 32), ptr noundef null) #3
  %58 = icmp slt i64 %57, 0
  %59 = load ptr, ptr @gBS, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !14
  br i1 %58, label %61, label %65

61:                                               ; preds = %53
  %62 = getelementptr inbounds i8, ptr %59, i64 288
  %63 = load ptr, ptr %62, align 8, !tbaa !28
  %64 = call i64 %63(ptr noundef %1, ptr noundef nonnull @gEfiSerialIoProtocolGuid, ptr noundef %60, ptr noundef %1) #3
  br label %77

65:                                               ; preds = %53
  %66 = getelementptr inbounds i8, ptr %59, i64 280
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = load ptr, ptr getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 16), align 8, !tbaa !38
  %69 = call i64 %67(ptr noundef %1, ptr noundef nonnull @gEfiSerialIoProtocolGuid, ptr noundef nonnull getelementptr inbounds (i8, ptr @mDebugPortDevice, i64 72), ptr noundef %60, ptr noundef %68, i32 noundef 8) #3
  %70 = icmp slt i64 %69, 0
  br i1 %70, label %71, label %77

71:                                               ; preds = %65
  %72 = load ptr, ptr @gBS, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 288
  %74 = load ptr, ptr %73, align 8, !tbaa !28
  %75 = load ptr, ptr %9, align 8, !tbaa !14
  %76 = call i64 %74(ptr noundef %1, ptr noundef nonnull @gEfiSerialIoProtocolGuid, ptr noundef %75, ptr noundef %1) #3
  br label %77

77:                                               ; preds = %65, %50, %3, %71, %61, %32
  %.028 = phi i64 [ %30, %32 ], [ %57, %61 ], [ %69, %71 ], [ %11, %3 ], [ -9223372036854775799, %50 ], [ 0, %65 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %4) #3
  ret i64 %.028
}

; 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

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

declare ptr @CopyGuid(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @DevicePathFromHandle(ptr noundef) local_unnamed_addr #2

declare void @SetDevicePathEndNode(ptr noundef) local_unnamed_addr #2

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

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 = !{!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 = !{!17, !6, i64 64}
!17 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !18, i64 32, !6, i64 64, !6, i64 72, !12, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !7, i64 100, !13, i64 104}
!18 = !{!"_EFI_DEBUGPORT_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!19 = !{!17, !6, i64 72}
!20 = !{!21, !6, i64 16}
!21 = !{!"_EFI_SERIAL_IO_PROTOCOL", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!22 = !{!17, !12, i64 80}
!23 = !{!17, !13, i64 88}
!24 = !{!17, !13, i64 92}
!25 = !{!17, !13, i64 96}
!26 = !{!17, !7, i64 100}
!27 = !{!17, !13, i64 104}
!28 = !{!10, !6, i64 288}
!29 = !{!21, !6, i64 8}
!30 = !{!31, !7, i64 0}
!31 = !{!"", !32, i64 0, !33, i64 4}
!32 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!33 = !{!"", !13, i64 0, !34, i64 4, !34, i64 6, !7, i64 8}
!34 = !{!"short", !7, i64 0}
!35 = !{!31, !7, i64 1}
!36 = !{!17, !6, i64 24}
!37 = !{!10, !6, i64 328}
!38 = !{!17, !6, i64 16}


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