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

; 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_GENERIC_TABLE = type { i8, ptr }

@.str.32 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.33 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.34 = external hidden unnamed_addr constant [2 x i32], align 4
@mUefiDevicePathLibToTextTableGeneric = external dso_local constant [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], align 16
@.str.153 = external hidden unnamed_addr constant [11 x i32], align 4
@.str.154 = external hidden unnamed_addr constant [6 x i32], align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @UefiDevicePathLibCatPrint(ptr noundef, ptr noundef, ...) #0

; 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 i8 @DevicePathType(ptr noundef) #2

declare i64 @DevicePathNodeLength(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextNodeGeneric(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i8 %3, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %10, align 8, !tbaa !10
  br label %12

12:                                               ; preds = %30, %4
  %13 = load i64, ptr %10, align 8, !tbaa !10
  %14 = getelementptr inbounds [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], ptr @mUefiDevicePathLibToTextTableGeneric, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %33

18:                                               ; preds = %12
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = call zeroext i8 @DevicePathType(ptr noundef %19)
  %21 = zext i8 %20 to i32
  %22 = load i64, ptr %10, align 8, !tbaa !10
  %23 = getelementptr inbounds [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], ptr @mUefiDevicePathLibToTextTableGeneric, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE, ptr %23, i32 0, i32 0
  %25 = load i8, ptr %24, align 16, !tbaa !14
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %21, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %18
  br label %33

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29
  %31 = load i64, ptr %10, align 8, !tbaa !10
  %32 = add i64 %31, 1
  store i64 %32, ptr %10, align 8, !tbaa !10
  br label %12, !llvm.loop !15

33:                                               ; preds = %28, %12
  %34 = load i64, ptr %10, align 8, !tbaa !10
  %35 = getelementptr inbounds [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], ptr @mUefiDevicePathLibToTextTableGeneric, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %48

39:                                               ; preds = %33
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = call zeroext i8 @DevicePathType(ptr noundef %41)
  %43 = zext i8 %42 to i32
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = call zeroext i8 @DevicePathSubType(ptr noundef %44)
  %46 = zext i8 %45 to i32
  %47 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %40, ptr noundef @.str.153, i32 noundef %43, i32 noundef %46)
  br label %58

48:                                               ; preds = %33
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %10, align 8, !tbaa !10
  %51 = getelementptr inbounds [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], ptr @mUefiDevicePathLibToTextTableGeneric, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !12
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = call zeroext i8 @DevicePathSubType(ptr noundef %54)
  %56 = zext i8 %55 to i32
  %57 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %49, ptr noundef @.str.154, ptr noundef %53, i32 noundef %56)
  br label %58

58:                                               ; preds = %48, %39
  store i64 4, ptr %10, align 8, !tbaa !10
  %59 = load i64, ptr %10, align 8, !tbaa !10
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = call i64 @DevicePathNodeLength(ptr noundef %60)
  %62 = icmp ult i64 %59, %61
  br i1 %62, label %63, label %83

63:                                               ; preds = %58
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %64, ptr noundef @.str.32)
  br label %66

66:                                               ; preds = %79, %63
  %67 = load i64, ptr %10, align 8, !tbaa !10
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = call i64 @DevicePathNodeLength(ptr noundef %68)
  %70 = icmp ult i64 %67, %69
  br i1 %70, label %71, label %82

71:                                               ; preds = %66
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load i64, ptr %10, align 8, !tbaa !10
  %75 = getelementptr inbounds i8, ptr %73, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !9
  %77 = zext i8 %76 to i32
  %78 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %72, ptr noundef @.str.33, i32 noundef %77)
  br label %79

79:                                               ; preds = %71
  %80 = load i64, ptr %10, align 8, !tbaa !10
  %81 = add i64 %80, 1
  store i64 %81, ptr %10, align 8, !tbaa !10
  br label %66, !llvm.loop !17

82:                                               ; preds = %66
  br label %83

83:                                               ; preds = %82, %58
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %84, ptr noundef @.str.34)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

declare zeroext i8 @DevicePathSubType(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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"", !7, i64 0, !6, i64 8}
!14 = !{!13, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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_GENERIC_TABLE = type { i8, ptr }

@.str.32 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.33 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.34 = external hidden unnamed_addr constant [2 x i32], align 4
@mUefiDevicePathLibToTextTableGeneric = external dso_local local_unnamed_addr constant [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], align 16
@.str.153 = external hidden unnamed_addr constant [11 x i32], align 4
@.str.154 = external hidden unnamed_addr constant [6 x i32], align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @UefiDevicePathLibCatPrint(ptr noundef, ptr noundef, ...) local_unnamed_addr #0

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

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextNodeGeneric(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @mUefiDevicePathLibToTextTableGeneric, i64 8), align 8, !tbaa !5
  %.not23 = icmp eq ptr %5, null
  br i1 %.not23, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %6 = tail call zeroext i8 @DevicePathType(ptr noundef %1) #2
  %7 = load i8, ptr @mUefiDevicePathLibToTextTableGeneric, align 16, !tbaa !10
  %8 = icmp eq i8 %6, %7
  br i1 %8, label %.lr.ph._crit_edge, label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.02431 = phi i64 [ %9, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %9 = add i64 %.02431, 1
  %10 = getelementptr inbounds [6 x %struct.DEVICE_PATH_TO_TEXT_GENERIC_TABLE], ptr @mUefiDevicePathLibToTextTableGeneric, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph32
  %13 = tail call zeroext i8 @DevicePathType(ptr noundef %1) #2
  %14 = load i8, ptr %10, align 16, !tbaa !10
  %15 = icmp eq i8 %13, %14
  br i1 %15, label %.lr.ph._crit_edge, label %.lr.ph32, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph32, %4
  %16 = tail call zeroext i8 @DevicePathType(ptr noundef %1) #2
  %17 = zext i8 %16 to i32
  %18 = tail call zeroext i8 @DevicePathSubType(ptr noundef %1) #2
  %19 = zext i8 %18 to i32
  %20 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.153, i32 noundef %17, i32 noundef %19)
  br label %24

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa = phi ptr [ %5, %.lr.ph.preheader ], [ %12, %.lr.ph ]
  %21 = tail call zeroext i8 @DevicePathSubType(ptr noundef %1) #2
  %22 = zext i8 %21 to i32
  %23 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.154, ptr noundef nonnull %.lcssa, i32 noundef %22)
  br label %24

24:                                               ; preds = %.lr.ph._crit_edge, %._crit_edge
  %25 = tail call i64 @DevicePathNodeLength(ptr noundef %1) #2
  %26 = icmp ugt i64 %25, 4
  br i1 %26, label %27, label %.loopexit

27:                                               ; preds = %24
  %28 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.32)
  %29 = tail call i64 @DevicePathNodeLength(ptr noundef %1) #2
  %30 = icmp ugt i64 %29, 4
  br i1 %30, label %.lr.ph27, label %.loopexit

.lr.ph27:                                         ; preds = %27, %.lr.ph27
  %.125 = phi i64 [ %35, %.lr.ph27 ], [ 4, %27 ]
  %31 = getelementptr inbounds i8, ptr %1, i64 %.125
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.33, i32 noundef %33)
  %35 = add nuw i64 %.125, 1
  %36 = tail call i64 @DevicePathNodeLength(ptr noundef %1) #2
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %.lr.ph27, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph27, %27, %24
  %38 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.34)
  ret void
}

declare zeroext i8 @DevicePathSubType(ptr noundef) local_unnamed_addr #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 = { "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 }

!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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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