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

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

; 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 @SplitStr(ptr noundef, i16 noundef zeroext) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @DevPathFromTextNVMe(ptr noundef %0) #1 {
  %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 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = call ptr @GetNextParamStr(ptr noundef %2)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = call ptr @GetNextParamStr(ptr noundef %2)
  store ptr %9, ptr %4, align 8, !tbaa !5
  %10 = call ptr @CreateDeviceNode(i8 noundef zeroext 3, i8 noundef zeroext 23, i16 noundef zeroext 16)
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i64 @Strtoi(ptr noundef %11)
  %13 = trunc i64 %12 to i32
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.NVME_NAMESPACE_DEVICE_PATH, ptr %14, i32 0, i32 1
  store i32 %13, ptr %15, align 1, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.NVME_NAMESPACE_DEVICE_PATH, ptr %16, i32 0, i32 2
  store ptr %17, ptr %6, align 8, !tbaa !5
  store i64 8, ptr %7, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %22, %1
  %19 = load i64, ptr %7, align 8, !tbaa !14
  %20 = add i64 %19, -1
  store i64 %20, ptr %7, align 8, !tbaa !14
  %21 = icmp ne i64 %19, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %18
  %23 = call ptr @SplitStr(ptr noundef %4, i16 noundef zeroext 45)
  %24 = call i64 @StrHexToUintn(ptr noundef %23)
  %25 = trunc i64 %24 to i8
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  store i8 %25, ptr %28, align 1, !tbaa !15
  br label %18, !llvm.loop !16

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

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, !12, i64 4}
!10 = !{!"", !11, i64 0, !12, i64 4, !13, i64 8}
!11 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!7, !7, 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"

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

; Function Attrs: mustprogress 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 @SplitStr(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

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

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

declare i64 @StrHexToUintn(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @DevPathFromTextNVMe(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = call ptr @GetNextParamStr(ptr noundef nonnull %2)
  %5 = call ptr @GetNextParamStr(ptr noundef nonnull %2)
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = call ptr @CreateDeviceNode(i8 noundef zeroext 3, i8 noundef zeroext 23, i16 noundef zeroext 16) #3
  %7 = call i64 @Strtoi(ptr noundef %4)
  %8 = trunc i64 %7 to i32
  %9 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %8, ptr %9, align 1, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 8
  %11 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %12 = call i64 @StrHexToUintn(ptr noundef %11) #3
  %13 = trunc i64 %12 to i8
  %14 = getelementptr inbounds i8, ptr %6, i64 15
  store i8 %13, ptr %14, align 1, !tbaa !14
  %15 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %16 = call i64 @StrHexToUintn(ptr noundef %15) #3
  %17 = trunc i64 %16 to i8
  %18 = getelementptr inbounds i8, ptr %6, i64 14
  store i8 %17, ptr %18, align 1, !tbaa !14
  %19 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %20 = call i64 @StrHexToUintn(ptr noundef %19) #3
  %21 = trunc i64 %20 to i8
  %22 = getelementptr inbounds i8, ptr %6, i64 13
  store i8 %21, ptr %22, align 1, !tbaa !14
  %23 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %24 = call i64 @StrHexToUintn(ptr noundef %23) #3
  %25 = trunc i64 %24 to i8
  %26 = getelementptr inbounds i8, ptr %6, i64 12
  store i8 %25, ptr %26, align 1, !tbaa !14
  %27 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %28 = call i64 @StrHexToUintn(ptr noundef %27) #3
  %29 = trunc i64 %28 to i8
  %30 = getelementptr inbounds i8, ptr %6, i64 11
  store i8 %29, ptr %30, align 1, !tbaa !14
  %31 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %32 = call i64 @StrHexToUintn(ptr noundef %31) #3
  %33 = trunc i64 %32 to i8
  %34 = getelementptr inbounds i8, ptr %6, i64 10
  store i8 %33, ptr %34, align 1, !tbaa !14
  %35 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %36 = call i64 @StrHexToUintn(ptr noundef %35) #3
  %37 = trunc i64 %36 to i8
  %38 = getelementptr inbounds i8, ptr %6, i64 9
  store i8 %37, ptr %38, align 1, !tbaa !14
  %39 = call ptr @SplitStr(ptr noundef nonnull %3, i16 noundef zeroext 45)
  %40 = call i64 @StrHexToUintn(ptr noundef %39) #3
  %41 = trunc i64 %40 to i8
  store i8 %41, ptr %10, align 1, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret ptr %6
}

attributes #0 = { mustprogress 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, !12, i64 4}
!10 = !{!"", !11, i64 0, !12, i64 4, !13, i64 8}
!11 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass