; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg (Undi16GetPacketFilterSetting)

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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @Undi16GetPacketFilterSetting(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i16, align 2
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #2
  store i16 0, ptr %3, align 2, !tbaa !9
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = and i64 %4, 1
  %6 = icmp ne i64 %5, 0
  br i1 %6, label %7, label %12

7:                                                ; preds = %1
  %8 = load i16, ptr %3, align 2, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = or i32 %9, 1
  %11 = trunc i32 %10 to i16
  store i16 %11, ptr %3, align 2, !tbaa !9
  br label %12

12:                                               ; preds = %7, %1
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = and i64 %13, 2
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  %17 = load i16, ptr %3, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = or i32 %18, 1
  %20 = trunc i32 %19 to i16
  store i16 %20, ptr %3, align 2, !tbaa !9
  br label %21

21:                                               ; preds = %16, %12
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = and i64 %22, 4
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %21
  %26 = load i16, ptr %3, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = or i32 %27, 2
  %29 = trunc i32 %28 to i16
  store i16 %29, ptr %3, align 2, !tbaa !9
  br label %30

30:                                               ; preds = %25, %21
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = and i64 %31, 8
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i16, ptr %3, align 2, !tbaa !9
  %36 = zext i16 %35 to i32
  %37 = or i32 %36, 4
  %38 = trunc i32 %37 to i16
  store i16 %38, ptr %3, align 2, !tbaa !9
  br label %39

39:                                               ; preds = %34, %30
  %40 = load i64, ptr %2, align 8, !tbaa !5
  %41 = and i64 %40, 16
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %48

43:                                               ; preds = %39
  %44 = load i16, ptr %3, align 2, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = or i32 %45, 4
  %47 = trunc i32 %46 to i16
  store i16 %47, ptr %3, align 2, !tbaa !9
  br label %48

48:                                               ; preds = %43, %39
  %49 = load i16, ptr %3, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret i16 %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local zeroext range(i16 0, 8) i16 @Undi16GetPacketFilterSetting(i64 noundef %0) local_unnamed_addr #0 {
  %2 = trunc i64 %0 to i16
  %spec.select = and i16 %2, 1
  %3 = and i64 %0, 2
  %.not11 = icmp eq i64 %3, 0
  %.1 = select i1 %.not11, i16 %spec.select, i16 1
  %4 = lshr i16 %2, 1
  %5 = and i16 %4, 2
  %.2 = or disjoint i16 %.1, %5
  %6 = or disjoint i16 %.2, 4
  %7 = and i64 %0, 24
  %8 = icmp eq i64 %7, 0
  %.4 = select i1 %8, i16 %.2, i16 %6
  ret i16 %.4
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


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