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

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

@.str.12 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.50 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.98 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.121 = external hidden unnamed_addr constant [21 x i32], align 4
@.str.122 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.123 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.124 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.125 = external hidden unnamed_addr constant [8 x i32], align 4
@.str.126 = external hidden unnamed_addr constant [9 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 @DevPathToTextiSCSI(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 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) #2
  call void @llvm.lifetime.start.p0(i64 2, 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 %5, align 8, !tbaa !5
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ISCSI_DEVICE_PATH_WITH_NAME, ptr %13, i32 0, i32 5
  %15 = getelementptr inbounds [1 x i8], ptr %14, i64 0, i64 0
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ISCSI_DEVICE_PATH_WITH_NAME, ptr %16, i32 0, i32 4
  %18 = load i16, ptr %17, align 1, !tbaa !10
  %19 = zext i16 %18 to i32
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ISCSI_DEVICE_PATH_WITH_NAME, ptr %20, i32 0, i32 3
  %22 = load i64, ptr %21, align 1, !tbaa !15
  %23 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %12, ptr noundef @.str.121, ptr noundef %15, i32 noundef %19, i64 noundef %22)
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ISCSI_DEVICE_PATH_WITH_NAME, ptr %24, i32 0, i32 2
  %26 = load i16, ptr %25, align 1, !tbaa !16
  store i16 %26, ptr %10, align 2, !tbaa !17
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i16, ptr %10, align 2, !tbaa !17
  %29 = zext i16 %28 to i32
  %30 = ashr i32 %29, 1
  %31 = and i32 %30, 1
  %32 = icmp ne i32 %31, 0
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, ptr @.str.123, ptr @.str.12
  %35 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %27, ptr noundef @.str.122, ptr noundef %34)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i16, ptr %10, align 2, !tbaa !17
  %38 = zext i16 %37 to i32
  %39 = ashr i32 %38, 3
  %40 = and i32 %39, 1
  %41 = icmp ne i32 %40, 0
  %42 = zext i1 %41 to i64
  %43 = select i1 %41, ptr @.str.123, ptr @.str.12
  %44 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %36, ptr noundef @.str.122, ptr noundef %43)
  %45 = load i16, ptr %10, align 2, !tbaa !17
  %46 = zext i16 %45 to i32
  %47 = ashr i32 %46, 11
  %48 = and i32 %47, 1
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %4
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %51, ptr noundef @.str.122, ptr noundef @.str.12)
  br label %66

53:                                               ; preds = %4
  %54 = load i16, ptr %10, align 2, !tbaa !17
  %55 = zext i16 %54 to i32
  %56 = ashr i32 %55, 12
  %57 = and i32 %56, 1
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %53
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %60, ptr noundef @.str.122, ptr noundef @.str.124)
  br label %65

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

65:                                               ; preds = %62, %59
  br label %66

66:                                               ; preds = %65, %50
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ISCSI_DEVICE_PATH_WITH_NAME, ptr %68, i32 0, i32 1
  %70 = load i16, ptr %69, align 1, !tbaa !18
  %71 = zext i16 %70 to i32
  %72 = icmp eq i32 %71, 0
  %73 = zext i1 %72 to i64
  %74 = select i1 %72, ptr @.str.98, ptr @.str.126
  %75 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %67, ptr noundef @.str.50, ptr noundef %74)
  call void @llvm.lifetime.end.p0(i64 2, 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, !13, i64 16}
!11 = !{!"", !12, i64 0, !13, i64 4, !13, i64 6, !14, i64 8, !13, i64 16, !7, i64 18}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!11, !14, i64 8}
!16 = !{!11, !13, i64 6}
!17 = !{!13, !13, i64 0}
!18 = !{!11, !13, 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.12 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.50 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.98 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.121 = external hidden unnamed_addr constant [21 x i32], align 4
@.str.122 = external hidden unnamed_addr constant [4 x i32], align 4
@.str.123 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.124 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.125 = external hidden unnamed_addr constant [8 x i32], align 4
@.str.126 = external hidden unnamed_addr constant [9 x i32], align 4

; 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 @DevPathToTextiSCSI(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 18
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i16, ptr %6, align 1, !tbaa !5
  %8 = zext i16 %7 to i32
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i64, ptr %9, align 1, !tbaa !12
  %11 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.121, ptr noundef nonnull %5, i32 noundef %8, i64 noundef %10)
  %12 = getelementptr inbounds i8, ptr %1, i64 6
  %13 = load i16, ptr %12, align 1, !tbaa !13
  %14 = zext i16 %13 to i32
  %15 = and i32 %14, 2
  %.not = icmp eq i32 %15, 0
  %16 = select i1 %.not, ptr @.str.12, ptr @.str.123
  %17 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.122, ptr noundef nonnull %16)
  %18 = and i32 %14, 8
  %.not16 = icmp eq i32 %18, 0
  %19 = select i1 %.not16, ptr @.str.12, ptr @.str.123
  %20 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.122, ptr noundef nonnull %19)
  %21 = and i32 %14, 2048
  %.not17 = icmp eq i32 %21, 0
  %22 = and i32 %14, 4096
  %.not18 = icmp eq i32 %22, 0
  %.str.125..str.124 = select i1 %.not18, ptr @.str.125, ptr @.str.124
  %.str.124.sink = select i1 %.not17, ptr %.str.125..str.124, ptr @.str.12
  %23 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.122, ptr noundef nonnull %.str.124.sink)
  %24 = getelementptr inbounds i8, ptr %1, i64 4
  %25 = load i16, ptr %24, align 1, !tbaa !14
  %26 = icmp eq i16 %25, 0
  %27 = select i1 %26, ptr @.str.98, ptr @.str.126
  %28 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.50, ptr noundef nonnull %27)
  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 16}
!6 = !{!"", !7, i64 0, !10, i64 4, !10, i64 6, !11, i64 8, !10, i64 16, !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 = !{!"short", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!6, !11, i64 8}
!13 = !{!6, !10, i64 6}
!14 = !{!6, !10, i64 4}


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