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

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

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [29 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

declare zeroext i8 @DebugAssertEnabled() #2

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

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

declare i64 @DevicePathNodeLength(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextUsbWWID(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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i16, align 2
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %13, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 10
  store ptr %15, ptr %10, align 8, !tbaa !5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = call i64 @DevicePathNodeLength(ptr noundef %16)
  %18 = sub i64 %17, 10
  %19 = udiv i64 %18, 2
  %20 = trunc i64 %19 to i16
  store i16 %20, ptr %12, align 2, !tbaa !10
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load i16, ptr %12, align 2, !tbaa !10
  %23 = zext i16 %22 to i32
  %24 = sub nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i16, ptr %21, i64 %25
  %27 = load i16, ptr %26, align 2, !tbaa !10
  %28 = zext i16 %27 to i32
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %54

30:                                               ; preds = %4
  %31 = load i16, ptr %12, align 2, !tbaa !10
  %32 = zext i16 %31 to i32
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = mul i64 %34, 2
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call ptr @AllocateCopyPool(i64 noundef %35, ptr noundef %36)
  store ptr %37, ptr %11, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %30
  %39 = call zeroext i8 @DebugAssertEnabled()
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @DebugAssert(ptr noundef @.str, i64 noundef 853, ptr noundef @.str.74)
  br label %45

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

46:                                               ; preds = %45, %38
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load i16, ptr %12, align 2, !tbaa !10
  %51 = zext i16 %50 to i64
  %52 = getelementptr inbounds i16, ptr %49, i64 %51
  store i16 0, ptr %52, align 2, !tbaa !10
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %53, ptr %10, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %48, %4
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.USB_WWID_DEVICE_PATH, ptr %56, i32 0, i32 2
  %58 = load i16, ptr %57, align 1, !tbaa !12
  %59 = zext i16 %58 to i32
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.USB_WWID_DEVICE_PATH, ptr %60, i32 0, i32 3
  %62 = load i16, ptr %61, align 1, !tbaa !15
  %63 = zext i16 %62 to i32
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.USB_WWID_DEVICE_PATH, ptr %64, i32 0, i32 1
  %66 = load i16, ptr %65, align 1, !tbaa !16
  %67 = zext i16 %66 to i32
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %55, ptr noundef @.str.75, i32 noundef %59, i32 noundef %63, i32 noundef %67, ptr noundef %68)
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  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 ptr @AllocateCopyPool(i64 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !11, i64 6}
!13 = !{!"", !14, i64 0, !11, i64 4, !11, i64 6, !11, i64 8}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!13, !11, i64 8}
!16 = !{!13, !11, i64 4}


; 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 [153 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [29 x i32], align 4

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

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextUsbWWID(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 10
  %6 = tail call i64 @DevicePathNodeLength(ptr noundef %1) #2
  %7 = add i64 %6, 131062
  %8 = lshr i64 %7, 1
  %9 = and i64 %8, 65535
  %10 = getelementptr i16, ptr %5, i64 %9
  %11 = getelementptr i8, ptr %10, i64 -2
  %12 = load i16, ptr %11, align 2, !tbaa !5
  %.not = icmp eq i16 %12, 0
  br i1 %.not, label %23, label %13

13:                                               ; preds = %4
  %14 = and i64 %7, 131070
  %15 = add nuw nsw i64 %14, 2
  %16 = tail call ptr @AllocateCopyPool(i64 noundef %15, ptr noundef nonnull %5) #2
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %18 = icmp eq i8 %17, 0
  %19 = icmp ne ptr %16, null
  %or.cond = select i1 %18, i1 true, i1 %19
  br i1 %or.cond, label %21, label %20

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

21:                                               ; preds = %20, %13
  %22 = getelementptr inbounds i16, ptr %16, i64 %9
  store i16 0, ptr %22, align 2, !tbaa !5
  br label %23

23:                                               ; preds = %21, %4
  %.0 = phi ptr [ %16, %21 ], [ %5, %4 ]
  %24 = getelementptr inbounds i8, ptr %1, i64 6
  %25 = load i16, ptr %24, align 1, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = getelementptr inbounds i8, ptr %1, i64 8
  %28 = load i16, ptr %27, align 1, !tbaa !12
  %29 = zext i16 %28 to i32
  %30 = getelementptr inbounds i8, ptr %1, i64 4
  %31 = load i16, ptr %30, align 1, !tbaa !13
  %32 = zext i16 %31 to i32
  %33 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.75, i32 noundef %26, i32 noundef %29, i32 noundef %32, ptr noundef nonnull %.0)
  ret void
}

declare ptr @AllocateCopyPool(i64 noundef, 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, !6, i64 6}
!10 = !{!"", !11, i64 0, !6, i64 4, !6, i64 6, !6, i64 8}
!11 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass