; LLVM IR from jrouwe/JoltPhysics :: TestFramework/Image/Surface.ll (ZNK17FormatDescription6DecodeEj)

; 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.JPH::Color" = type { %union.anon }
%union.anon = type { i32 }

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local i32 @_ZNK17FormatDescription6DecodeEj(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca %"class.JPH::Color", align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.memset.p0.i64(ptr align 4 %3, i8 0, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %44, %2
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 4
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %47

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %11, i32 noundef %17)
  store i32 %18, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %40

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %22)
  store i32 %23, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = and i32 %24, %25
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = lshr i32 %26, %27
  store i32 %28, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = lshr i32 %29, %30
  store i32 %31, ptr %10, align 4, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = mul i32 255, %32
  %34 = add i32 %33, 127
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = udiv i32 %34, %35
  %37 = trunc i32 %36 to i8
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %38)
  store i8 %37, ptr %39, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %43

40:                                               ; preds = %16
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %41)
  store i8 -1, ptr %42, align 1, !tbaa !11
  br label %43

43:                                               ; preds = %40, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !12

47:                                               ; preds = %15
  %48 = getelementptr inbounds %"class.JPH::Color", ptr %3, i32 0, i32 0
  %49 = getelementptr inbounds %union.anon, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 4
  ret i32 %50
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { inlinehint mustprogress 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 #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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.JPH::Color" = type { %union.anon }
%union.anon = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local i32 @_ZNK17FormatDescription6DecodeEj(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"class.JPH::Color", align 4
  store i32 0, ptr %3, align 4
  %4 = tail call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 0)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %14, label %5

5:                                                ; preds = %2
  %6 = tail call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %4)
  %7 = and i32 %4, %1
  %8 = lshr i32 %7, %6
  %9 = lshr i32 %4, %6
  %10 = mul i32 %8, 255
  %11 = add i32 %10, 127
  %12 = udiv i32 %11, %9
  %13 = trunc i32 %12 to i8
  br label %14

14:                                               ; preds = %2, %5
  %.sink = phi i8 [ %13, %5 ], [ -1, %2 ]
  %15 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 0)
  store i8 %.sink, ptr %15, align 1, !tbaa !5
  %16 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 1)
  %.not.1 = icmp eq i32 %16, 0
  br i1 %.not.1, label %26, label %17

17:                                               ; preds = %14
  %18 = call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %16)
  %19 = and i32 %16, %1
  %20 = lshr i32 %19, %18
  %21 = lshr i32 %16, %18
  %22 = mul i32 %20, 255
  %23 = add i32 %22, 127
  %24 = udiv i32 %23, %21
  %25 = trunc i32 %24 to i8
  br label %26

26:                                               ; preds = %14, %17
  %.sink17 = phi i8 [ %25, %17 ], [ -1, %14 ]
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 1)
  store i8 %.sink17, ptr %27, align 1, !tbaa !5
  %28 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 2)
  %.not.2 = icmp eq i32 %28, 0
  br i1 %.not.2, label %38, label %29

29:                                               ; preds = %26
  %30 = call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %28)
  %31 = and i32 %28, %1
  %32 = lshr i32 %31, %30
  %33 = lshr i32 %28, %30
  %34 = mul i32 %32, 255
  %35 = add i32 %34, 127
  %36 = udiv i32 %35, %33
  %37 = trunc i32 %36 to i8
  br label %38

38:                                               ; preds = %26, %29
  %.sink19 = phi i8 [ %37, %29 ], [ -1, %26 ]
  %39 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 2)
  store i8 %.sink19, ptr %39, align 1, !tbaa !5
  %40 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 3)
  %.not.3 = icmp eq i32 %40, 0
  br i1 %.not.3, label %50, label %41

41:                                               ; preds = %38
  %42 = call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %40)
  %43 = and i32 %40, %1
  %44 = lshr i32 %43, %42
  %45 = lshr i32 %40, %42
  %46 = mul i32 %44, 255
  %47 = add i32 %46, 127
  %48 = udiv i32 %47, %45
  %49 = trunc i32 %48 to i8
  br label %50

50:                                               ; preds = %38, %41
  %.sink21 = phi i8 [ %49, %41 ], [ -1, %38 ]
  %51 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 3)
  store i8 %.sink21, ptr %51, align 1, !tbaa !5
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { 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 #2 = { 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 = { inlinehint mustprogress 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass