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

; 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 uwtable
define dso_local noundef i32 @_ZNK17FormatDescription6EncodeEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 %1) #1 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 = getelementptr inbounds %"class.JPH::Color", ptr %3, i32 0, i32 0
  %11 = getelementptr inbounds %union.anon, ptr %10, i32 0, i32 0
  store i32 %1, ptr %11, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

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

16:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %50

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

24:                                               ; preds = %17
  store i32 4, ptr %8, align 4
  br label %44

25:                                               ; preds = %17
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = or i32 %27, %26
  store i32 %28, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = uitofp i32 %29 to float
  %31 = fmul float 0x3F70101020000000, %30
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %32)
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = sitofp i32 %35 to float
  %37 = fmul float %31, %36
  %38 = call noundef float @_ZSt5roundf(float noundef %37)
  %39 = fptosi float %38 to i32
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = and i32 %39, %40
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = or i32 %42, %41
  store i32 %43, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %8, align 4
  br label %44

44:                                               ; preds = %25, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %45 = load i32, ptr %8, align 4
  switch i32 %45, label %52 [
    i32 0, label %46
    i32 4, label %47
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46, %44
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !12

50:                                               ; preds = %16
  %51 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %51

52:                                               ; preds = %44
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float noundef) #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) #3 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 = { 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 #3 = { 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 #4 = { 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 uwtable
define dso_local noundef i32 @_ZNK17FormatDescription6EncodeEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"class.JPH::Color", align 4
  store i32 %1, ptr %3, align 4
  %4 = tail call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 0)
  %5 = uitofp i32 %4 to float
  %6 = fmul float %5, 0x3F70101020000000
  %7 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 0)
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = uitofp i8 %8 to float
  %10 = fmul float %6, %9
  %11 = call noundef float @_ZSt5roundf(float noundef %10)
  %12 = fptosi float %11 to i32
  %13 = and i32 %4, %12
  %14 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 1)
  %15 = and i32 %14, %4
  %.not.1 = icmp eq i32 %15, 0
  br i1 %.not.1, label %16, label %28

16:                                               ; preds = %2
  %17 = or i32 %14, %4
  %18 = uitofp i32 %14 to float
  %19 = fmul float %18, 0x3F70101020000000
  %20 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 1)
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = uitofp i8 %21 to float
  %23 = fmul float %19, %22
  %24 = call noundef float @_ZSt5roundf(float noundef %23)
  %25 = fptosi float %24 to i32
  %26 = and i32 %14, %25
  %27 = or i32 %26, %13
  br label %28

28:                                               ; preds = %16, %2
  %.114.1 = phi i32 [ %17, %16 ], [ %4, %2 ]
  %.1.1 = phi i32 [ %27, %16 ], [ %13, %2 ]
  %29 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 2)
  %30 = and i32 %29, %.114.1
  %.not.2 = icmp eq i32 %30, 0
  br i1 %.not.2, label %31, label %43

31:                                               ; preds = %28
  %32 = or i32 %29, %.114.1
  %33 = uitofp i32 %29 to float
  %34 = fmul float %33, 0x3F70101020000000
  %35 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 2)
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = uitofp i8 %36 to float
  %38 = fmul float %34, %37
  %39 = call noundef float @_ZSt5roundf(float noundef %38)
  %40 = fptosi float %39 to i32
  %41 = and i32 %29, %40
  %42 = or i32 %41, %.1.1
  br label %43

43:                                               ; preds = %31, %28
  %.114.2 = phi i32 [ %32, %31 ], [ %.114.1, %28 ]
  %.1.2 = phi i32 [ %42, %31 ], [ %.1.1, %28 ]
  %44 = call noundef i32 @_ZNK17FormatDescription16GetComponentMaskEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 3)
  %45 = and i32 %44, %.114.2
  %.not.3 = icmp eq i32 %45, 0
  br i1 %.not.3, label %46, label %57

46:                                               ; preds = %43
  %47 = uitofp i32 %44 to float
  %48 = fmul float %47, 0x3F70101020000000
  %49 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN3JPH5ColorclEj(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 3)
  %50 = load i8, ptr %49, align 1, !tbaa !5
  %51 = uitofp i8 %50 to float
  %52 = fmul float %48, %51
  %53 = call noundef float @_ZSt5roundf(float noundef %52)
  %54 = fptosi float %53 to i32
  %55 = and i32 %44, %54
  %56 = or i32 %55, %.1.2
  br label %57

57:                                               ; preds = %46, %43
  %.1.3 = phi i32 [ %56, %46 ], [ %.1.2, %43 ]
  ret i32 %.1.3
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float noundef) local_unnamed_addr #1

; 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 #2 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 = { 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" }

!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass