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

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

@.str.111 = external hidden unnamed_addr constant [14 x i32], align 4
@.str.112 = external hidden unnamed_addr constant [10 x i32], align 4
@.str.113 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.114 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.115 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.116 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.117 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.118 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.119 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.120 = external hidden unnamed_addr constant [3 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 @DevPathToTextUart(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 i8, align 1
  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 1, ptr %10) #2
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %12, i32 0, i32 4
  %14 = load i8, ptr %13, align 1, !tbaa !10
  %15 = zext i8 %14 to i32
  switch i32 %15, label %22 [
    i32 0, label %16
    i32 1, label %17
    i32 2, label %18
    i32 3, label %19
    i32 4, label %20
    i32 5, label %21
  ]

16:                                               ; preds = %4
  store i8 68, ptr %10, align 1, !tbaa !9
  br label %23

17:                                               ; preds = %4
  store i8 78, ptr %10, align 1, !tbaa !9
  br label %23

18:                                               ; preds = %4
  store i8 69, ptr %10, align 1, !tbaa !9
  br label %23

19:                                               ; preds = %4
  store i8 79, ptr %10, align 1, !tbaa !9
  br label %23

20:                                               ; preds = %4
  store i8 77, ptr %10, align 1, !tbaa !9
  br label %23

21:                                               ; preds = %4
  store i8 83, ptr %10, align 1, !tbaa !9
  br label %23

22:                                               ; preds = %4
  store i8 120, ptr %10, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %22, %21, %20, %19, %18, %17, %16
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 1, !tbaa !15
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %29, ptr noundef @.str.111)
  br label %37

31:                                               ; preds = %23
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %33, i32 0, i32 2
  %35 = load i64, ptr %34, align 1, !tbaa !15
  %36 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %32, ptr noundef @.str.112, i64 noundef %35)
  br label %37

37:                                               ; preds = %31, %28
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %38, i32 0, i32 3
  %40 = load i8, ptr %39, align 1, !tbaa !16
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %37
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %44, ptr noundef @.str.113)
  br label %53

46:                                               ; preds = %37
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %48, i32 0, i32 3
  %50 = load i8, ptr %49, align 1, !tbaa !16
  %51 = zext i8 %50 to i32
  %52 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %47, ptr noundef @.str.114, i32 noundef %51)
  br label %53

53:                                               ; preds = %46, %43
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i8, ptr %10, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %54, ptr noundef @.str.115, i32 noundef %56)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.UART_DEVICE_PATH, ptr %58, i32 0, i32 5
  %60 = load i8, ptr %59, align 1, !tbaa !17
  %61 = zext i8 %60 to i32
  switch i32 %61, label %74 [
    i32 0, label %62
    i32 1, label %65
    i32 2, label %68
    i32 3, label %71
  ]

62:                                               ; preds = %53
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %63, ptr noundef @.str.116)
  br label %77

65:                                               ; preds = %53
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %66, ptr noundef @.str.117)
  br label %77

68:                                               ; preds = %53
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %69, ptr noundef @.str.118)
  br label %77

71:                                               ; preds = %53
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %72, ptr noundef @.str.119)
  br label %77

74:                                               ; preds = %53
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %75, ptr noundef @.str.120)
  br label %77

77:                                               ; preds = %74, %71, %68, %65, %62
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  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" }
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, !7, i64 17}
!11 = !{!"", !12, i64 0, !13, i64 4, !14, i64 8, !7, i64 16, !7, i64 17, !7, i64 18}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!11, !14, i64 8}
!16 = !{!11, !7, i64 16}
!17 = !{!11, !7, i64 18}


; 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.111 = external hidden unnamed_addr constant [14 x i32], align 4
@.str.112 = external hidden unnamed_addr constant [10 x i32], align 4
@.str.113 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.114 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.115 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.116 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.117 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.118 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.119 = external hidden unnamed_addr constant [3 x i32], align 4
@.str.120 = external hidden unnamed_addr constant [3 x i32], align 4
@switch.table.DevPathToTextUart = private unnamed_addr constant [6 x i32] [i32 68, i32 78, i32 69, i32 79, i32 77, i32 83], align 4
@switch.table.DevPathToTextUart.1 = private unnamed_addr constant [4 x ptr] [ptr @.str.116, ptr @.str.117, ptr @.str.118, ptr @.str.119], 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 @DevPathToTextUart(ptr noundef %0, ptr nocapture noundef readonly %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 17
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = icmp ult i8 %6, 6
  br i1 %7, label %switch.lookup, label %9

switch.lookup:                                    ; preds = %4
  %8 = zext nneg i8 %6 to i64
  %switch.gep = getelementptr inbounds [6 x i32], ptr @switch.table.DevPathToTextUart, i64 0, i64 %8
  %switch.load = load i32, ptr %switch.gep, align 4
  br label %9

9:                                                ; preds = %4, %switch.lookup
  %.0 = phi i32 [ %switch.load, %switch.lookup ], [ 120, %4 ]
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i64, ptr %10, align 1, !tbaa !12
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.111)
  br label %17

15:                                               ; preds = %9
  %16 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.112, i64 noundef %11)
  br label %17

17:                                               ; preds = %15, %13
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = icmp eq i8 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.113)
  br label %26

23:                                               ; preds = %17
  %24 = zext i8 %19 to i32
  %25 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.114, i32 noundef %24)
  br label %26

26:                                               ; preds = %23, %21
  %27 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.115, i32 noundef %.0)
  %28 = getelementptr inbounds i8, ptr %1, i64 18
  %29 = load i8, ptr %28, align 1, !tbaa !14
  %30 = icmp ult i8 %29, 4
  br i1 %30, label %switch.lookup19, label %32

switch.lookup19:                                  ; preds = %26
  %31 = zext nneg i8 %29 to i64
  %switch.gep20 = getelementptr inbounds [4 x ptr], ptr @switch.table.DevPathToTextUart.1, i64 0, i64 %31
  %switch.load21 = load ptr, ptr %switch.gep20, align 8
  br label %32

32:                                               ; preds = %26, %switch.lookup19
  %.str.120.sink = phi ptr [ %switch.load21, %switch.lookup19 ], [ @.str.120, %26 ]
  %33 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull %.str.120.sink)
  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, !8, i64 17}
!6 = !{!"", !7, i64 0, !10, i64 4, !11, i64 8, !8, i64 16, !8, i64 17, !8, i64 18}
!7 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!6, !11, i64 8}
!13 = !{!6, !8, i64 16}
!14 = !{!6, !8, i64 18}


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