; LLVM IR from AngelJumbo/lavat :: lavat (set_pallete2)

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

@baseColor = external dso_local global [3 x i32], align 4
@baseColor2 = external dso_local global [3 x i32], align 4
@pallete = external dso_local global [11 x i32], align 16

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind uwtable
define dso_local void @set_pallete2() #2 {
  %1 = alloca i32, align 4
  %2 = alloca float, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %54, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 11
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %57

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sitofp i32 %11 to float
  %13 = fdiv float %12, 1.000000e+01
  store float %13, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %14 = load float, ptr %2, align 4, !tbaa !9
  %15 = fsub float 1.000000e+00, %14
  %16 = load i32, ptr @baseColor, align 4, !tbaa !5
  %17 = sitofp i32 %16 to float
  %18 = load float, ptr %2, align 4, !tbaa !9
  %19 = load i32, ptr @baseColor2, align 4, !tbaa !5
  %20 = sitofp i32 %19 to float
  %21 = fmul float %18, %20
  %22 = call float @llvm.fmuladd.f32(float %15, float %17, float %21)
  %23 = fptosi float %22 to i32
  store i32 %23, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %24 = load float, ptr %2, align 4, !tbaa !9
  %25 = fsub float 1.000000e+00, %24
  %26 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @baseColor, i64 0, i64 1), align 4, !tbaa !5
  %27 = sitofp i32 %26 to float
  %28 = load float, ptr %2, align 4, !tbaa !9
  %29 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @baseColor2, i64 0, i64 1), align 4, !tbaa !5
  %30 = sitofp i32 %29 to float
  %31 = fmul float %28, %30
  %32 = call float @llvm.fmuladd.f32(float %25, float %27, float %31)
  %33 = fptosi float %32 to i32
  store i32 %33, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %34 = load float, ptr %2, align 4, !tbaa !9
  %35 = fsub float 1.000000e+00, %34
  %36 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @baseColor, i64 0, i64 2), align 4, !tbaa !5
  %37 = sitofp i32 %36 to float
  %38 = load float, ptr %2, align 4, !tbaa !9
  %39 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @baseColor2, i64 0, i64 2), align 4, !tbaa !5
  %40 = sitofp i32 %39 to float
  %41 = fmul float %38, %40
  %42 = call float @llvm.fmuladd.f32(float %35, float %37, float %41)
  %43 = fptosi float %42 to i32
  store i32 %43, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = shl i32 %44, 16
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = shl i32 %46, 8
  %48 = or i32 %45, %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = or i32 %48, %49
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [11 x i32], ptr @pallete, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %54

54:                                               ; preds = %10
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !11

57:                                               ; preds = %9
  ret void
}

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

@baseColor = external dso_local local_unnamed_addr global [3 x i32], align 4
@baseColor2 = external dso_local local_unnamed_addr global [3 x i32], align 4
@pallete = external dso_local local_unnamed_addr global [11 x i32], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @set_pallete2() local_unnamed_addr #1 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @baseColor, i64 8), align 4, !tbaa !5
  %2 = sitofp i32 %1 to float
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @baseColor2, i64 8), align 4, !tbaa !5
  %4 = sitofp i32 %3 to float
  %5 = tail call float @llvm.copysign.f32(float 0.000000e+00, float %4)
  %6 = fadd float %5, %2
  %7 = fmul float %4, 0x3FB99999A0000000
  %8 = tail call float @llvm.fmuladd.f32(float %2, float 0x3FECCCCCC0000000, float %7)
  %9 = insertelement <2 x float> poison, float %4, i64 0
  %10 = shufflevector <2 x float> %9, <2 x float> poison, <2 x i32> zeroinitializer
  %11 = fmul <2 x float> %10, <float 0x3FC99999A0000000, float 0x3FD3333340000000>
  %12 = insertelement <2 x float> poison, float %2, i64 0
  %13 = shufflevector <2 x float> %12, <2 x float> poison, <2 x i32> zeroinitializer
  %14 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %13, <2 x float> <float 0x3FE99999A0000000, float 0x3FE6666660000000>, <2 x float> %11)
  %15 = insertelement <4 x float> poison, float %6, i64 0
  %16 = insertelement <4 x float> %15, float %8, i64 1
  %17 = shufflevector <2 x float> %14, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %18 = shufflevector <4 x float> %16, <4 x float> %17, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
  %19 = fptosi <4 x float> %18 to <4 x i32>
  %20 = load <2 x i32>, ptr @baseColor, align 4, !tbaa !5
  %21 = sitofp <2 x i32> %20 to <2 x float>
  %22 = shufflevector <2 x float> %21, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
  %23 = load <2 x i32>, ptr @baseColor2, align 4, !tbaa !5
  %24 = sitofp <2 x i32> %23 to <2 x float>
  %25 = shufflevector <2 x float> %24, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
  %26 = extractelement <2 x float> %24, i64 0
  %27 = tail call float @llvm.copysign.f32(float 0.000000e+00, float %26)
  %28 = extractelement <2 x float> %21, i64 0
  %29 = fadd float %27, %28
  %30 = extractelement <2 x float> %24, i64 1
  %31 = tail call float @llvm.copysign.f32(float 0.000000e+00, float %30)
  %32 = extractelement <2 x float> %21, i64 1
  %33 = fadd float %31, %32
  %34 = fmul float %26, 0x3FB99999A0000000
  %35 = tail call float @llvm.fmuladd.f32(float %28, float 0x3FECCCCCC0000000, float %34)
  %36 = fmul float %30, 0x3FB99999A0000000
  %37 = tail call float @llvm.fmuladd.f32(float %32, float 0x3FECCCCCC0000000, float %36)
  %38 = fmul <2 x float> %24, <float 0x3FD3333340000000, float 0x3FC99999A0000000>
  %39 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %21, <2 x float> <float 0x3FE6666660000000, float 0x3FE99999A0000000>, <2 x float> %38)
  %40 = fmul <2 x float> %24, <float 0x3FC99999A0000000, float 0x3FD3333340000000>
  %41 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %21, <2 x float> <float 0x3FE99999A0000000, float 0x3FE6666660000000>, <2 x float> %40)
  %42 = insertelement <4 x float> poison, float %33, i64 0
  %43 = insertelement <4 x float> %42, float %35, i64 1
  %44 = shufflevector <2 x float> %39, <2 x float> poison, <4 x i32> <i32 1, i32 0, i32 poison, i32 poison>
  %45 = shufflevector <4 x float> %43, <4 x float> %44, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
  %46 = fptosi <4 x float> %45 to <4 x i32>
  %47 = insertelement <4 x float> poison, float %29, i64 0
  %48 = insertelement <4 x float> %47, float %37, i64 1
  %49 = shufflevector <2 x float> %41, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %50 = shufflevector <4 x float> %48, <4 x float> %49, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
  %51 = fptosi <4 x float> %50 to <4 x i32>
  %52 = shl <4 x i32> %46, <i32 8, i32 16, i32 8, i32 16>
  %53 = shl <4 x i32> %51, <i32 16, i32 8, i32 16, i32 8>
  %54 = or <4 x i32> %53, %52
  %55 = or <4 x i32> %54, %19
  store <4 x i32> %55, ptr @pallete, align 16, !tbaa !5
  %56 = shufflevector <2 x float> %24, <2 x float> poison, <4 x i32> <i32 1, i32 0, i32 1, i32 0>
  %57 = fmul <4 x float> %56, <float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FE3333340000000, float 0x3FE6666660000000>
  %58 = shufflevector <2 x float> %21, <2 x float> poison, <4 x i32> <i32 1, i32 0, i32 1, i32 0>
  %59 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %58, <4 x float> <float 0x3FE3333340000000, float 5.000000e-01, float 0x3FD9999980000000, float 0x3FD3333340000000>, <4 x float> %57)
  %60 = fptosi <4 x float> %59 to <4 x i32>
  %61 = fmul <4 x float> %25, <float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FE3333340000000, float 0x3FE6666660000000>
  %62 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %22, <4 x float> <float 0x3FE3333340000000, float 5.000000e-01, float 0x3FD9999980000000, float 0x3FD3333340000000>, <4 x float> %61)
  %63 = fptosi <4 x float> %62 to <4 x i32>
  %64 = insertelement <4 x float> poison, float %4, i64 0
  %65 = shufflevector <4 x float> %64, <4 x float> poison, <4 x i32> zeroinitializer
  %66 = fmul <4 x float> %65, <float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FE3333340000000, float 0x3FE6666660000000>
  %67 = insertelement <4 x float> poison, float %2, i64 0
  %68 = shufflevector <4 x float> %67, <4 x float> poison, <4 x i32> zeroinitializer
  %69 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %68, <4 x float> <float 0x3FE3333340000000, float 5.000000e-01, float 0x3FD9999980000000, float 0x3FD3333340000000>, <4 x float> %66)
  %70 = fptosi <4 x float> %69 to <4 x i32>
  %71 = shl <4 x i32> %60, <i32 8, i32 16, i32 8, i32 16>
  %72 = shl <4 x i32> %63, <i32 16, i32 8, i32 16, i32 8>
  %73 = or <4 x i32> %72, %71
  %74 = or <4 x i32> %73, %70
  store <4 x i32> %74, ptr getelementptr inbounds (i8, ptr @pallete, i64 16), align 16, !tbaa !5
  %75 = fmul <2 x float> %24, <float 0x3FECCCCCC0000000, float 0x3FE99999A0000000>
  %76 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %21, <2 x float> <float 0x3FB9999A00000000, float 0x3FC9999980000000>, <2 x float> %75)
  %77 = fptosi <2 x float> %76 to <2 x i32>
  %78 = fmul <2 x float> %24, <float 0x3FE99999A0000000, float 0x3FECCCCCC0000000>
  %79 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %21, <2 x float> <float 0x3FC9999980000000, float 0x3FB9999A00000000>, <2 x float> %78)
  %80 = fptosi <2 x float> %79 to <2 x i32>
  %81 = fmul <2 x float> %10, <float 0x3FE99999A0000000, float 0x3FECCCCCC0000000>
  %82 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %13, <2 x float> <float 0x3FC9999980000000, float 0x3FB9999A00000000>, <2 x float> %81)
  %83 = fptosi <2 x float> %82 to <2 x i32>
  %84 = shl <2 x i32> %77, <i32 16, i32 8>
  %85 = shufflevector <2 x i32> %84, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  %86 = shl <2 x i32> %80, <i32 16, i32 8>
  %87 = or <2 x i32> %86, %85
  %88 = or <2 x i32> %87, %83
  store <2 x i32> %88, ptr getelementptr inbounds (i8, ptr @pallete, i64 32), align 16, !tbaa !5
  %89 = tail call float @llvm.fmuladd.f32(float %28, float 0.000000e+00, float %26)
  %90 = fptosi float %89 to i32
  %91 = tail call float @llvm.fmuladd.f32(float %32, float 0.000000e+00, float %30)
  %92 = fptosi float %91 to i32
  %93 = tail call float @llvm.fmuladd.f32(float %2, float 0.000000e+00, float %4)
  %94 = fptosi float %93 to i32
  %95 = shl i32 %90, 16
  %96 = shl i32 %92, 8
  %97 = or i32 %96, %95
  %98 = or i32 %97, %94
  store i32 %98, ptr getelementptr inbounds (i8, ptr @pallete, i64 40), align 8, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x float> @llvm.fmuladd.v2f32(<2 x float>, <2 x float>, <2 x float>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: 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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass