; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library (UefiDevicePathLibConvertDeviceNodeToText)

; 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.DEVICE_PATH_TO_TEXT_TABLE = type { i8, i8, ptr }
%struct.POOL_PRINT = type { ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@mUefiDevicePathLibToTextTable = external dso_local constant [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], align 16
@.str.155 = external hidden unnamed_addr constant [24 x i8], align 1

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

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

declare zeroext i8 @DevicePathType(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @DevPathToTextNodeGeneric(ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext) #2

declare zeroext i8 @DevicePathSubType(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @UefiDevicePathLibConvertDeviceNodeToText(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca %struct.POOL_PRINT, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i8 %2, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, 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
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %71

15:                                               ; preds = %3
  %16 = call ptr @ZeroMem(ptr noundef %8, i64 noundef 24)
  store ptr @DevPathToTextNodeGeneric, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !10
  br label %17

17:                                               ; preds = %49, %15
  %18 = load i64, ptr %9, align 8, !tbaa !10
  %19 = getelementptr inbounds [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], ptr @mUefiDevicePathLibToTextTable, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_TABLE, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %52

23:                                               ; preds = %17
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call zeroext i8 @DevicePathType(ptr noundef %24)
  %26 = zext i8 %25 to i32
  %27 = load i64, ptr %9, align 8, !tbaa !10
  %28 = getelementptr inbounds [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], ptr @mUefiDevicePathLibToTextTable, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_TABLE, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 16, !tbaa !14
  %31 = zext i8 %30 to i32
  %32 = icmp eq i32 %26, %31
  br i1 %32, label %33, label %48

33:                                               ; preds = %23
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call zeroext i8 @DevicePathSubType(ptr noundef %34)
  %36 = zext i8 %35 to i32
  %37 = load i64, ptr %9, align 8, !tbaa !10
  %38 = getelementptr inbounds [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], ptr @mUefiDevicePathLibToTextTable, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_TABLE, ptr %38, i32 0, i32 1
  %40 = load i8, ptr %39, align 1, !tbaa !15
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %36, %41
  br i1 %42, label %43, label %48

43:                                               ; preds = %33
  %44 = load i64, ptr %9, align 8, !tbaa !10
  %45 = getelementptr inbounds [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], ptr @mUefiDevicePathLibToTextTable, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_TABLE, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  store ptr %47, ptr %10, align 8, !tbaa !5
  br label %52

48:                                               ; preds = %33, %23
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %9, align 8, !tbaa !10
  %51 = add i64 %50, 1
  store i64 %51, ptr %9, align 8, !tbaa !10
  br label %17, !llvm.loop !16

52:                                               ; preds = %43, %17
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i8, ptr %6, align 1, !tbaa !9
  %56 = load i8, ptr %7, align 1, !tbaa !9
  call void %53(ptr noundef %8, ptr noundef %54, i8 noundef zeroext %55, i8 noundef zeroext %56)
  br label %57

57:                                               ; preds = %52
  %58 = call zeroext i8 @DebugAssertEnabled()
  %59 = icmp ne i8 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = getelementptr inbounds %struct.POOL_PRINT, ptr %8, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = icmp ne ptr %62, null
  br i1 %63, label %65, label %64

64:                                               ; preds = %60
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1980, ptr noundef @.str.155)
  br label %65

65:                                               ; preds = %64, %60
  br label %66

66:                                               ; preds = %65, %57
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = getelementptr inbounds %struct.POOL_PRINT, ptr %8, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !18
  store ptr %70, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %71

71:                                               ; preds = %68, %14
  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 24, ptr %8) #3
  %72 = load ptr, ptr %4, align 8
  ret ptr %72
}

declare ptr @ZeroMem(ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"", !7, i64 0, !7, i64 1, !6, i64 8}
!14 = !{!13, !7, i64 0}
!15 = !{!13, !7, i64 1}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !11, i64 8, !11, 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.DEVICE_PATH_TO_TEXT_TABLE = type { i8, i8, ptr }
%struct.POOL_PRINT = type { ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@mUefiDevicePathLibToTextTable = external dso_local local_unnamed_addr constant [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], align 16
@.str.155 = external hidden unnamed_addr constant [24 x i8], align 1

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @DevPathToTextNodeGeneric(ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @UefiDevicePathLibConvertDeviceNodeToText(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = alloca %struct.POOL_PRINT, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  %5 = icmp eq ptr %0, null
  br i1 %5, label %29, label %6

6:                                                ; preds = %3
  %7 = call ptr @ZeroMem(ptr noundef nonnull %4, i64 noundef 24) #3
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @mUefiDevicePathLibToTextTable, i64 8), align 8, !tbaa !5
  %.not17 = icmp eq ptr %8, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %19
  %9 = phi ptr [ %23, %19 ], [ %8, %6 ]
  %10 = phi ptr [ %21, %19 ], [ @mUefiDevicePathLibToTextTable, %6 ]
  %.01418 = phi i64 [ %20, %19 ], [ 0, %6 ]
  %11 = call zeroext i8 @DevicePathType(ptr noundef nonnull %0) #3
  %12 = load i8, ptr %10, align 16, !tbaa !10
  %13 = icmp eq i8 %11, %12
  br i1 %13, label %14, label %19

14:                                               ; preds = %.lr.ph
  %15 = call zeroext i8 @DevicePathSubType(ptr noundef nonnull %0) #3
  %16 = getelementptr inbounds i8, ptr %10, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = icmp eq i8 %15, %17
  br i1 %18, label %._crit_edge, label %19

19:                                               ; preds = %.lr.ph, %14
  %20 = add i64 %.01418, 1
  %21 = getelementptr inbounds [41 x %struct.DEVICE_PATH_TO_TEXT_TABLE], ptr @mUefiDevicePathLibToTextTable, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %19, %14, %6
  %.0 = phi ptr [ @DevPathToTextNodeGeneric, %6 ], [ %9, %14 ], [ @DevPathToTextNodeGeneric, %19 ]
  call void %.0(ptr noundef nonnull %4, ptr noundef nonnull %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #3
  %24 = call zeroext i8 @DebugAssertEnabled() #3
  %25 = icmp eq i8 %24, 0
  %26 = load ptr, ptr %4, align 8
  %27 = icmp ne ptr %26, null
  %or.cond = select i1 %25, i1 true, i1 %27
  br i1 %or.cond, label %29, label %28

28:                                               ; preds = %._crit_edge
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1980, ptr noundef nonnull @.str.155) #3
  %.pre = load ptr, ptr %4, align 8, !tbaa !14
  br label %29

29:                                               ; preds = %._crit_edge, %28, %3
  %.015 = phi ptr [ null, %3 ], [ %.pre, %28 ], [ %26, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  ret ptr %.015
}

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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, !9, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 1, !9, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 1}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !9, i64 0}
!15 = !{!"", !9, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"long long", !7, i64 0}


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