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

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

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.1 = 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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @GetNextParamStr(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Strtoi(ptr noundef) #1

declare ptr @CreateDeviceNode(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @DevPathFromTextAcpiAdr(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  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
  %7 = call ptr @CreateDeviceNode(i8 noundef zeroext 2, i8 noundef zeroext 3, i16 noundef zeroext 8)
  store ptr %7, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %1
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %16

11:                                               ; preds = %8
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1115, ptr noundef @.str.1)
  br label %15

15:                                               ; preds = %14, %11
  br label %16

16:                                               ; preds = %15, %8
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %60, %18
  %20 = call ptr @GetNextParamStr(ptr noundef %2)
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i16, ptr %21, align 2, !tbaa !11
  %23 = zext i16 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  br label %63

26:                                               ; preds = %19
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = icmp ugt i64 %27, 0
  br i1 %28, label %29, label %52

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i64 @DevicePathNodeLength(ptr noundef %30)
  store i64 %31, ptr %6, align 8, !tbaa !9
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = add i64 %33, 4
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call ptr @ReallocatePool(i64 noundef %32, i64 noundef %34, ptr noundef %35)
  store ptr %36, ptr %4, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %29
  %38 = call zeroext i8 @DebugAssertEnabled()
  %39 = icmp ne i8 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %37
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1129, ptr noundef @.str.1)
  br label %44

44:                                               ; preds = %43, %40
  br label %45

45:                                               ; preds = %44, %37
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = add i64 %49, 4
  %51 = call zeroext i16 @SetDevicePathNodeLength(ptr noundef %48, i64 noundef %50)
  br label %52

52:                                               ; preds = %47, %26
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call i64 @Strtoi(ptr noundef %53)
  %55 = trunc i64 %54 to i32
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ACPI_ADR_DEVICE_PATH, ptr %56, i32 0, i32 1
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = getelementptr inbounds i32, ptr %57, i64 %58
  store i32 %55, ptr %59, align 1, !tbaa !13
  br label %60

60:                                               ; preds = %52
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %5, align 8, !tbaa !9
  br label %19

63:                                               ; preds = %25
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %64
}

declare zeroext i8 @DebugAssertEnabled() #2

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

declare i64 @DevicePathNodeLength(ptr noundef) #2

declare ptr @ReallocatePool(i64 noundef, i64 noundef, ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !16, i64 4}
!14 = !{!"", !15, i64 0, !16, i64 4}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!16 = !{!"int", !7, i64 0}


; 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.1 = external hidden unnamed_addr constant [24 x i8], align 1

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

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

declare ptr @CreateDeviceNode(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @DevPathFromTextAcpiAdr(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = tail call ptr @CreateDeviceNode(i8 noundef zeroext 2, i8 noundef zeroext 3, i16 noundef zeroext 8) #2
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %5 = icmp eq i8 %4, 0
  %6 = icmp ne ptr %3, null
  %or.cond = select i1 %5, i1 true, i1 %6
  br i1 %or.cond, label %8, label %7

7:                                                ; preds = %1
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1115, ptr noundef nonnull @.str.1) #2
  br label %8

8:                                                ; preds = %7, %1
  %9 = call ptr @GetNextParamStr(ptr noundef nonnull %2)
  %10 = load i16, ptr %9, align 2, !tbaa !9
  %11 = icmp eq i16 %10, 0
  br i1 %11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %23
  %12 = phi ptr [ %29, %23 ], [ %9, %8 ]
  %.019 = phi ptr [ %.1, %23 ], [ %3, %8 ]
  %.01718 = phi i64 [ %28, %23 ], [ 0, %8 ]
  %.not = icmp eq i64 %.01718, 0
  br i1 %.not, label %23, label %13

13:                                               ; preds = %.lr.ph
  %14 = call i64 @DevicePathNodeLength(ptr noundef %.019) #2
  %15 = add i64 %14, 4
  %16 = call ptr @ReallocatePool(i64 noundef %14, i64 noundef %15, ptr noundef %.019) #2
  %17 = call zeroext i8 @DebugAssertEnabled() #2
  %18 = icmp eq i8 %17, 0
  %19 = icmp ne ptr %16, null
  %or.cond3 = select i1 %18, i1 true, i1 %19
  br i1 %or.cond3, label %21, label %20

20:                                               ; preds = %13
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1129, ptr noundef nonnull @.str.1) #2
  br label %21

21:                                               ; preds = %20, %13
  %22 = call zeroext i16 @SetDevicePathNodeLength(ptr noundef %16, i64 noundef %15) #2
  br label %23

23:                                               ; preds = %21, %.lr.ph
  %.1 = phi ptr [ %16, %21 ], [ %.019, %.lr.ph ]
  %24 = call i64 @Strtoi(ptr noundef nonnull %12)
  %25 = trunc i64 %24 to i32
  %26 = getelementptr inbounds i8, ptr %.1, i64 4
  %27 = getelementptr inbounds i32, ptr %26, i64 %.01718
  store i32 %25, ptr %27, align 1, !tbaa !11
  %28 = add i64 %.01718, 1
  %29 = call ptr @GetNextParamStr(ptr noundef nonnull %2)
  %30 = load i16, ptr %29, align 2, !tbaa !9
  %31 = icmp eq i16 %30, 0
  br i1 %31, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %23, %8
  %.0.lcssa = phi ptr [ %3, %8 ], [ %.1, %23 ]
  ret ptr %.0.lcssa
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #1

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

declare zeroext i16 @SetDevicePathNodeLength(ptr noundef, i64 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 = !{!"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, !14, i64 4}
!12 = !{!"", !13, i64 0, !14, i64 4}
!13 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!14 = !{!"int", !7, i64 0}


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