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

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

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@mUefiDevicePathLibDevPathFromTextTable = external dso_local global [74 x %struct.DEVICE_PATH_FROM_TEXT_TABLE], align 16
@.str.103 = external hidden unnamed_addr constant [30 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @GetParamByNodeName(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 @DebugAssertEnabled() #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @UefiDevicePathLibConvertTextToDeviceNode(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 i64, align 8
  %9 = 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
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %17, label %12

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

17:                                               ; preds = %12, %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %71

18:                                               ; preds = %12
  store ptr null, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call ptr @UefiDevicePathLibStrDuplicate(ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %18
  %22 = call zeroext i8 @DebugAssertEnabled()
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %29

24:                                               ; preds = %21
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @DebugAssert(ptr noundef @.str, i64 noundef 3185, ptr noundef @.str.103)
  br label %28

28:                                               ; preds = %27, %24
  br label %29

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

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %53, %31
  %33 = load i64, ptr %8, align 8, !tbaa !11
  %34 = getelementptr inbounds [74 x %struct.DEVICE_PATH_FROM_TEXT_TABLE], ptr @mUefiDevicePathLibDevPathFromTextTable, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.DEVICE_PATH_FROM_TEXT_TABLE, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %56

38:                                               ; preds = %32
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = getelementptr inbounds [74 x %struct.DEVICE_PATH_FROM_TEXT_TABLE], ptr @mUefiDevicePathLibDevPathFromTextTable, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.DEVICE_PATH_FROM_TEXT_TABLE, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 16, !tbaa !15
  %44 = call ptr @GetParamByNodeName(ptr noundef %39, ptr noundef %43)
  store ptr %44, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %52

47:                                               ; preds = %38
  %48 = load i64, ptr %8, align 8, !tbaa !11
  %49 = getelementptr inbounds [74 x %struct.DEVICE_PATH_FROM_TEXT_TABLE], ptr @mUefiDevicePathLibDevPathFromTextTable, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.DEVICE_PATH_FROM_TEXT_TABLE, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  store ptr %51, ptr %4, align 8, !tbaa !5
  br label %56

52:                                               ; preds = %38
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %8, align 8, !tbaa !11
  %55 = add i64 %54, 1
  store i64 %55, ptr %8, align 8, !tbaa !11
  br label %32, !llvm.loop !16

56:                                               ; preds = %47, %32
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %63

59:                                               ; preds = %56
  store ptr @DevPathFromTextFilePath, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = call ptr %60(ptr noundef %61)
  store ptr %62, ptr %6, align 8, !tbaa !5
  br label %68

63:                                               ; preds = %56
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = call ptr %64(ptr noundef %65)
  store ptr %66, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  call void @FreePool(ptr noundef %67)
  br label %68

68:                                               ; preds = %63, %59
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @FreePool(ptr noundef %69)
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %70, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %71

71:                                               ; preds = %68, %17
  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
  %72 = load ptr, ptr %2, align 8
  ret ptr %72
}

declare void @FreePool(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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.DEVICE_PATH_FROM_TEXT_TABLE = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@mUefiDevicePathLibDevPathFromTextTable = external dso_local local_unnamed_addr global [74 x %struct.DEVICE_PATH_FROM_TEXT_TABLE], align 16
@.str.103 = external hidden unnamed_addr constant [30 x i8], align 1

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

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @UefiDevicePathLibConvertTextToDeviceNode(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %30, label %3

3:                                                ; preds = %1
  %4 = load i16, ptr %0, align 2, !tbaa !5
  %5 = icmp eq i16 %4, 0
  br i1 %5, label %30, label %6

6:                                                ; preds = %3
  %7 = tail call ptr @UefiDevicePathLibStrDuplicate(ptr noundef nonnull %0)
  %8 = tail call zeroext i8 @DebugAssertEnabled() #2
  %9 = icmp eq i8 %8, 0
  %10 = icmp ne ptr %7, null
  %or.cond = select i1 %9, i1 true, i1 %10
  br i1 %or.cond, label %12, label %11

11:                                               ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 3185, ptr noundef nonnull @.str.103) #2
  br label %12

12:                                               ; preds = %11, %6
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @mUefiDevicePathLibDevPathFromTextTable, i64 8), align 8, !tbaa !9
  %.not31 = icmp eq ptr %13, null
  br i1 %.not31, label %.thread, label %.lr.ph

14:                                               ; preds = %.lr.ph
  %15 = add i64 %.032, 1
  %16 = getelementptr inbounds [74 x %struct.DEVICE_PATH_FROM_TEXT_TABLE], ptr @mUefiDevicePathLibDevPathFromTextTable, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !12

.lr.ph:                                           ; preds = %12, %14
  %19 = phi ptr [ %16, %14 ], [ @mUefiDevicePathLibDevPathFromTextTable, %12 ]
  %.032 = phi i64 [ %15, %14 ], [ 0, %12 ]
  %20 = load ptr, ptr %19, align 16, !tbaa !14
  %21 = tail call ptr @GetParamByNodeName(ptr noundef %7, ptr noundef %20)
  %.not26 = icmp eq ptr %21, null
  br i1 %.not26, label %14, label %22

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i8, ptr %19, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp eq ptr %24, null
  br i1 %25, label %.thread, label %27

.thread:                                          ; preds = %14, %12, %22
  %26 = tail call ptr @DevPathFromTextFilePath(ptr noundef %7)
  br label %29

27:                                               ; preds = %22
  %28 = tail call ptr %24(ptr noundef nonnull %21) #2
  tail call void @FreePool(ptr noundef nonnull %21) #2
  br label %29

29:                                               ; preds = %27, %.thread
  %.020 = phi ptr [ %26, %.thread ], [ %28, %27 ]
  tail call void @FreePool(ptr noundef %7) #2
  br label %30

30:                                               ; preds = %1, %3, %29
  %.019 = phi ptr [ %.020, %29 ], [ null, %3 ], [ null, %1 ]
  ret ptr %.019
}

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


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