; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/basisu_etc.ll (ZN6basisu9etc_block13unpack_delta3Et)

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

%"class.basisu::color_rgba_i16" = type { %union.anon.1 }
%union.anon.1 = type { [4 x i16] }

; 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: mustprogress uwtable
define dso_local i64 @_ZN6basisu9etc_block13unpack_delta3Et(i16 noundef zeroext %0) #1 align 2 {
  %2 = alloca %"class.basisu::color_rgba_i16", align 2
  %3 = alloca i16, align 2
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i16 %0, ptr %3, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %7 = load i16, ptr %3, align 2, !tbaa !5
  %8 = zext i16 %7 to i32
  %9 = ashr i32 %8, 6
  %10 = and i32 %9, 7
  store i32 %10, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %11 = load i16, ptr %3, align 2, !tbaa !5
  %12 = zext i16 %11 to i32
  %13 = ashr i32 %12, 3
  %14 = and i32 %13, 7
  store i32 %14, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = load i16, ptr %3, align 2, !tbaa !5
  %16 = zext i16 %15 to i32
  %17 = and i32 %16, 7
  store i32 %17, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp sge i32 %18, 4
  br i1 %19, label %20, label %23

20:                                               ; preds = %1
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = sub nsw i32 %21, 8
  store i32 %22, ptr %4, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %20, %1
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp sge i32 %24, 4
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 8
  store i32 %28, ptr %5, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %26, %23
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp sge i32 %30, 4
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 8
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %32, %29
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN6basisu14color_rgba_i16C2Eiiii(ptr noundef nonnull align 2 dereferenceable(8) %2, i32 noundef %36, i32 noundef %37, i32 noundef %38, i32 noundef 255)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %39 = getelementptr inbounds %"class.basisu::color_rgba_i16", ptr %2, i32 0, i32 0
  %40 = getelementptr inbounds %union.anon.1, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 2
  ret i64 %41
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu14color_rgba_i16C2Eiiii(ptr noundef nonnull align 2 dereferenceable(8), i32 noundef, i32 noundef, i32 noundef, i32 noundef) unnamed_addr #2 align 2

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

%"class.basisu::color_rgba_i16" = type { %union.anon.1 }
%union.anon.1 = type { [4 x i16] }

; Function Attrs: mustprogress uwtable
define dso_local i64 @_ZN6basisu9etc_block13unpack_delta3Et(i16 noundef zeroext %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %"class.basisu::color_rgba_i16", align 8
  %3 = zext i16 %0 to i32
  %4 = lshr i32 %3, 6
  %5 = and i32 %4, 7
  %6 = lshr i32 %3, 3
  %7 = and i32 %6, 7
  %8 = and i32 %3, 7
  %9 = icmp ugt i32 %5, 3
  %masksel = select i1 %9, i32 -8, i32 0
  %spec.select = or disjoint i32 %masksel, %5
  %10 = icmp ugt i32 %7, 3
  %masksel19 = select i1 %10, i32 -8, i32 0
  %.012 = or disjoint i32 %masksel19, %7
  %11 = icmp ugt i32 %8, 3
  %masksel20 = select i1 %11, i32 -8, i32 0
  %.0 = or disjoint i32 %masksel20, %8
  call void @_ZN6basisu14color_rgba_i16C2Eiiii(ptr noundef nonnull align 2 dereferenceable(8) %2, i32 noundef %spec.select, i32 noundef %.012, i32 noundef %.0, i32 noundef 255)
  %12 = load i64, ptr %2, align 8
  ret i64 %12
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu14color_rgba_i16C2Eiiii(ptr noundef nonnull align 2 dereferenceable(8), i32 noundef, i32 noundef, i32 noundef, i32 noundef) unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass