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

; 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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.104 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.105 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @UefiDevicePathLibStrDuplicate(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

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

declare zeroext i8 @DebugAssertEnabled() #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @UefiDevicePathLibConvertTextToDeviceNode(ptr noundef) #0

declare void @FreePool(ptr noundef) #2

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

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i16, ptr %15, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %14, %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %75

20:                                               ; preds = %14
  %21 = call ptr @AllocatePool(i64 noundef 4)
  store ptr %21, ptr %10, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %20
  %23 = call zeroext i8 @DebugAssertEnabled()
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %22
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str, i64 noundef 3242, ptr noundef @.str.104)
  br label %29

29:                                               ; preds = %28, %25
  br label %30

30:                                               ; preds = %29, %22
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SetDevicePathEndNode(ptr noundef %33)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = call ptr @UefiDevicePathLibStrDuplicate(ptr noundef %34)
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %36, ptr %7, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %71, %32
  %38 = call ptr @GetNextDeviceNodeStr(ptr noundef %7, ptr noundef %9)
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %72

40:                                               ; preds = %37
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call ptr @UefiDevicePathLibConvertTextToDeviceNode(ptr noundef %41)
  store ptr %42, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = call ptr @AppendDevicePathNode(ptr noundef %43, ptr noundef %44)
  store ptr %45, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FreePool(ptr noundef %46)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @FreePool(ptr noundef %47)
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %48, ptr %10, align 8, !tbaa !5
  %49 = load i8, ptr %9, align 1, !tbaa !11
  %50 = icmp ne i8 %49, 0
  br i1 %50, label %51, label %71

51:                                               ; preds = %40
  %52 = call ptr @AllocatePool(i64 noundef 4)
  store ptr %52, ptr %4, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %51
  %54 = call zeroext i8 @DebugAssertEnabled()
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %61

56:                                               ; preds = %53
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %60, label %59

59:                                               ; preds = %56
  call void @DebugAssert(ptr noundef @.str, i64 noundef 3258, ptr noundef @.str.105)
  br label %60

60:                                               ; preds = %59, %56
  br label %61

61:                                               ; preds = %60, %53
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  call void @SetDevicePathEndNode(ptr noundef %64)
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = call ptr @AppendDevicePathNode(ptr noundef %65, ptr noundef %66)
  store ptr %67, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FreePool(ptr noundef %68)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  call void @FreePool(ptr noundef %69)
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %70, ptr %10, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %63, %40
  br label %37, !llvm.loop !12

72:                                               ; preds = %37
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %73)
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %74, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %75

75:                                               ; preds = %72, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %76 = load ptr, ptr %2, align 8
  ret ptr %76
}

declare ptr @AllocatePool(i64 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.104 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.105 = external hidden unnamed_addr constant [27 x i8], align 1

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

; 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 ptr @GetNextDeviceNodeStr(ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

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

declare void @FreePool(ptr noundef) local_unnamed_addr #2

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

5:                                                ; preds = %1
  %6 = load i16, ptr %0, align 2, !tbaa !5
  %7 = icmp eq i16 %6, 0
  br i1 %7, label %31, label %8

8:                                                ; preds = %5
  %9 = tail call ptr @AllocatePool(i64 noundef 4) #3
  %10 = tail call zeroext i8 @DebugAssertEnabled() #3
  %11 = icmp eq i8 %10, 0
  %12 = icmp ne ptr %9, null
  %or.cond = select i1 %11, i1 true, i1 %12
  br i1 %or.cond, label %14, label %13

13:                                               ; preds = %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 3242, ptr noundef nonnull @.str.104) #3
  br label %14

14:                                               ; preds = %13, %8
  tail call void @SetDevicePathEndNode(ptr noundef %9) #3
  %15 = tail call ptr @UefiDevicePathLibStrDuplicate(ptr noundef nonnull %0)
  store ptr %15, ptr %2, align 8, !tbaa !9
  %16 = call ptr @GetNextDeviceNodeStr(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not29 = icmp eq ptr %16, null
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %14, %29
  %17 = phi ptr [ %30, %29 ], [ %16, %14 ]
  %.030 = phi ptr [ %.1, %29 ], [ %9, %14 ]
  %18 = call ptr @UefiDevicePathLibConvertTextToDeviceNode(ptr noundef nonnull %17)
  %19 = call ptr @AppendDevicePathNode(ptr noundef %.030, ptr noundef %18) #3
  call void @FreePool(ptr noundef %.030) #3
  call void @FreePool(ptr noundef %18) #3
  %20 = load i8, ptr %3, align 1, !tbaa !11
  %.not28 = icmp eq i8 %20, 0
  br i1 %.not28, label %29, label %21

21:                                               ; preds = %.lr.ph
  %22 = call ptr @AllocatePool(i64 noundef 4) #3
  %23 = call zeroext i8 @DebugAssertEnabled() #3
  %24 = icmp eq i8 %23, 0
  %25 = icmp ne ptr %22, null
  %or.cond3 = select i1 %24, i1 true, i1 %25
  br i1 %or.cond3, label %27, label %26

26:                                               ; preds = %21
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 3258, ptr noundef nonnull @.str.105) #3
  br label %27

27:                                               ; preds = %26, %21
  call void @SetDevicePathEndNode(ptr noundef %22) #3
  %28 = call ptr @AppendDevicePathNode(ptr noundef %19, ptr noundef %22) #3
  call void @FreePool(ptr noundef %19) #3
  call void @FreePool(ptr noundef %22) #3
  br label %29

29:                                               ; preds = %27, %.lr.ph
  %.1 = phi ptr [ %28, %27 ], [ %19, %.lr.ph ]
  %30 = call ptr @GetNextDeviceNodeStr(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not = icmp eq ptr %30, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %29, %14
  %.0.lcssa = phi ptr [ %9, %14 ], [ %.1, %29 ]
  call void @FreePool(ptr noundef %15) #3
  br label %31

31:                                               ; preds = %1, %5, %._crit_edge
  %.025 = phi ptr [ %.0.lcssa, %._crit_edge ], [ null, %5 ], [ null, %1 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret ptr %.025
}

declare ptr @AllocatePool(i64 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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