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

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

@.str.34 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.97 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.141 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.142 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.143 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.144 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.145 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.146 = external hidden unnamed_addr constant [8 x i32], align 4
@.str.147 = external hidden unnamed_addr constant [10 x i32], align 4
@.str.148 = external hidden unnamed_addr constant [12 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

; 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
define dso_local void @DevPathToTextBBS(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 i32, align 4
  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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %12, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.BBS_BBS_DEVICE_PATH, ptr %13, i32 0, i32 1
  %15 = load i16, ptr %14, align 1, !tbaa !10
  %16 = zext i16 %15 to i32
  switch i32 %16, label %23 [
    i32 1, label %17
    i32 2, label %18
    i32 3, label %19
    i32 4, label %20
    i32 5, label %21
    i32 6, label %22
  ]

17:                                               ; preds = %4
  store ptr @.str.141, ptr %10, align 8, !tbaa !5
  br label %24

18:                                               ; preds = %4
  store ptr @.str.142, ptr %10, align 8, !tbaa !5
  br label %24

19:                                               ; preds = %4
  store ptr @.str.143, ptr %10, align 8, !tbaa !5
  br label %24

20:                                               ; preds = %4
  store ptr @.str.144, ptr %10, align 8, !tbaa !5
  br label %24

21:                                               ; preds = %4
  store ptr @.str.145, ptr %10, align 8, !tbaa !5
  br label %24

22:                                               ; preds = %4
  store ptr @.str.146, ptr %10, align 8, !tbaa !5
  br label %24

23:                                               ; preds = %4
  store ptr null, ptr %10, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %23, %22, %21, %20, %19, %18, %17
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.BBS_BBS_DEVICE_PATH, ptr %30, i32 0, i32 3
  %32 = getelementptr inbounds [1 x i8], ptr %31, i64 0, i64 0
  %33 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %28, ptr noundef @.str.147, ptr noundef %29, ptr noundef %32)
  br label %44

34:                                               ; preds = %24
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.BBS_BBS_DEVICE_PATH, ptr %36, i32 0, i32 1
  %38 = load i16, ptr %37, align 1, !tbaa !10
  %39 = zext i16 %38 to i32
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.BBS_BBS_DEVICE_PATH, ptr %40, i32 0, i32 3
  %42 = getelementptr inbounds [1 x i8], ptr %41, i64 0, i64 0
  %43 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %35, ptr noundef @.str.148, i32 noundef %39, ptr noundef %42)
  br label %44

44:                                               ; preds = %34, %27
  %45 = load i8, ptr %7, align 1, !tbaa !9
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %48, ptr noundef @.str.34)
  store i32 1, ptr %11, align 4
  br label %57

50:                                               ; preds = %44
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.BBS_BBS_DEVICE_PATH, ptr %52, i32 0, i32 2
  %54 = load i16, ptr %53, align 1, !tbaa !14
  %55 = zext i16 %54 to i32
  %56 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %51, ptr noundef @.str.97, i32 noundef %55)
  store i32 0, ptr %11, align 4
  br label %57

57:                                               ; preds = %50, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %58 = load i32, ptr %11, align 4
  switch i32 %58, label %60 [
    i32 0, label %59
    i32 1, label %59
  ]

59:                                               ; preds = %57, %57
  ret void

60:                                               ; preds = %57
  unreachable
}

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


; 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.34 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.97 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.141 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.142 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.143 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.144 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.145 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.146 = external hidden unnamed_addr constant [8 x i32], align 4
@.str.147 = external hidden unnamed_addr constant [10 x i32], align 4
@.str.148 = external hidden unnamed_addr constant [12 x i32], align 4
@switch.table.DevPathToTextBBS = private unnamed_addr constant [6 x ptr] [ptr @.str.141, ptr @.str.142, ptr @.str.143, ptr @.str.144, ptr @.str.145, ptr @.str.146], align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextBBS(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 4
  %6 = load i16, ptr %5, align 1, !tbaa !5
  %switch.tableidx = add i16 %6, -1
  %7 = icmp ult i16 %switch.tableidx, 6
  br i1 %7, label %switch.lookup, label %11

switch.lookup:                                    ; preds = %4
  %8 = zext nneg i16 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [6 x ptr], ptr @switch.table.DevPathToTextBBS, i64 0, i64 %8
  %switch.load = load ptr, ptr %switch.gep, align 8
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.147, ptr noundef nonnull %switch.load, ptr noundef nonnull %9)
  br label %15

11:                                               ; preds = %4
  %12 = zext i16 %6 to i32
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.148, i32 noundef %12, ptr noundef nonnull %13)
  br label %15

15:                                               ; preds = %11, %switch.lookup
  %.not12 = icmp eq i8 %2, 0
  br i1 %.not12, label %18, label %16

16:                                               ; preds = %15
  %17 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.34)
  br label %23

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %1, i64 6
  %20 = load i16, ptr %19, align 1, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.97, i32 noundef %21)
  br label %23

23:                                               ; preds = %18, %16
  ret void
}

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

!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, !10, i64 4}
!6 = !{!"", !7, i64 0, !10, i64 4, !10, i64 6, !8, i64 8}
!7 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 6}


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