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

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

@.str.32 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.34 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.65 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.106 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.107 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.108 = external hidden unnamed_addr constant [25 x i32], align 4
@.str.109 = external hidden unnamed_addr constant [24 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

declare i64 @DevicePathNodeLength(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @CatNetworkProtocol(ptr noundef, i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local void @CatIPv6Address(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextIPv6(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 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) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %12, ptr noundef @.str.106)
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.IPv6_DEVICE_PATH, ptr %15, i32 0, i32 2
  call void @CatIPv6Address(ptr noundef %14, ptr noundef %16)
  %17 = load i8, ptr %7, align 1, !tbaa !9
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %20, ptr noundef @.str.34)
  store i32 1, ptr %10, align 4
  br label %62

22:                                               ; preds = %4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %23, ptr noundef @.str.32)
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.IPv6_DEVICE_PATH, ptr %26, i32 0, i32 5
  %28 = load i16, ptr %27, align 1, !tbaa !10
  call void @CatNetworkProtocol(ptr noundef %25, i16 noundef zeroext %28)
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.IPv6_DEVICE_PATH, ptr %29, i32 0, i32 6
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = zext i8 %31 to i32
  switch i32 %32, label %39 [
    i32 0, label %33
    i32 1, label %36
  ]

33:                                               ; preds = %22
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %34, ptr noundef @.str.107)
  br label %42

36:                                               ; preds = %22
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %37, ptr noundef @.str.108)
  br label %42

39:                                               ; preds = %22
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %40, ptr noundef @.str.109)
  br label %42

42:                                               ; preds = %39, %36, %33
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IPv6_DEVICE_PATH, ptr %44, i32 0, i32 1
  call void @CatIPv6Address(ptr noundef %43, ptr noundef %45)
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call i64 @DevicePathNodeLength(ptr noundef %46)
  %48 = icmp eq i64 %47, 60
  br i1 %48, label %49, label %59

49:                                               ; preds = %42
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.IPv6_DEVICE_PATH, ptr %51, i32 0, i32 7
  %53 = load i8, ptr %52, align 1, !tbaa !16
  %54 = zext i8 %53 to i32
  %55 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %50, ptr noundef @.str.65, i32 noundef %54)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.IPv6_DEVICE_PATH, ptr %57, i32 0, i32 8
  call void @CatIPv6Address(ptr noundef %56, ptr noundef %58)
  br label %59

59:                                               ; preds = %49, %42
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %60, ptr noundef @.str.34)
  store i32 0, ptr %10, align 4
  br label %62

62:                                               ; preds = %59, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %63 = load i32, ptr %10, align 4
  switch i32 %63, label %65 [
    i32 0, label %64
    i32 1, label %64
  ]

64:                                               ; preds = %62, %62
  ret void

65:                                               ; preds = %62
  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 = { "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, !14, i64 40}
!11 = !{!"", !12, i64 0, !13, i64 4, !13, i64 20, !14, i64 36, !14, i64 38, !14, i64 40, !7, i64 42, !7, i64 43, !13, i64 44}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!"", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!11, !7, i64 42}
!16 = !{!11, !7, i64 43}


; 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.32 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.34 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.65 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.106 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.107 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.108 = external hidden unnamed_addr constant [25 x i32], align 4
@.str.109 = external hidden unnamed_addr constant [24 x i32], align 4

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

declare i64 @DevicePathNodeLength(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @CatNetworkProtocol(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextIPv6(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.106)
  %6 = getelementptr inbounds i8, ptr %1, i64 20
  tail call void @CatIPv6Address(ptr noundef %0, ptr noundef nonnull %6)
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %7, label %23

7:                                                ; preds = %4
  %8 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.32)
  %9 = getelementptr inbounds i8, ptr %1, i64 40
  %10 = load i16, ptr %9, align 1, !tbaa !5
  tail call void @CatNetworkProtocol(ptr noundef %0, i16 noundef zeroext %10)
  %11 = getelementptr inbounds i8, ptr %1, i64 42
  %12 = load i8, ptr %11, align 1, !tbaa !12
  %switch.selectcmp = icmp eq i8 %12, 1
  %switch.select = select i1 %switch.selectcmp, ptr @.str.108, ptr @.str.109
  %switch.selectcmp20 = icmp eq i8 %12, 0
  %switch.select21 = select i1 %switch.selectcmp20, ptr @.str.107, ptr %switch.select
  %13 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull %switch.select21)
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  tail call void @CatIPv6Address(ptr noundef %0, ptr noundef nonnull %14)
  %15 = tail call i64 @DevicePathNodeLength(ptr noundef nonnull %1) #2
  %16 = icmp eq i64 %15, 60
  br i1 %16, label %17, label %23

17:                                               ; preds = %7
  %18 = getelementptr inbounds i8, ptr %1, i64 43
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = zext i8 %19 to i32
  %21 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.65, i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %1, i64 44
  tail call void @CatIPv6Address(ptr noundef %0, ptr noundef nonnull %22)
  br label %23

23:                                               ; preds = %7, %17, %4
  %24 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.34)
  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 = { "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, !11, i64 40}
!6 = !{!"", !7, i64 0, !10, i64 4, !10, i64 20, !11, i64 36, !11, i64 38, !11, i64 40, !8, i64 42, !8, i64 43, !10, i64 44}
!7 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !8, i64 42}
!13 = !{!6, !8, i64 43}


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