; LLVM IR from Dovyski/opengl-demos :: src/model-md2/md2.ll (ZN9CMD2Model15ProcessLightingEv)

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

@_ZN9CMD2Model11anorms_dotsE = external dso_local global [16 x [256 x float]], align 16
@g_lightcolor = external dso_local global [3 x float], align 4
@g_ambientlight = external dso_local global i32, align 4
@g_shadelight = external dso_local global float, align 4
@g_angle = external dso_local global float, align 4
@_ZL6lcolor = external hidden global [3 x float], align 4
@_ZL9shadedots = external hidden global ptr, align 8

; 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
define dso_local void @_ZN9CMD2Model15ProcessLightingEv(ptr noundef nonnull align 8 dereferenceable(84) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %5 = load float, ptr @g_shadelight, align 4, !tbaa !9
  %6 = load i32, ptr @g_ambientlight, align 4, !tbaa !11
  %7 = sitofp i32 %6 to float
  %8 = fadd float %5, %7
  %9 = fpext float %8 to double
  %10 = fdiv double %9, 2.560000e+02
  %11 = fptrunc double %10 to float
  store float %11, ptr %3, align 4, !tbaa !9
  %12 = load float, ptr @g_lightcolor, align 4, !tbaa !9
  %13 = load float, ptr %3, align 4, !tbaa !9
  %14 = fmul float %12, %13
  store float %14, ptr @_ZL6lcolor, align 4, !tbaa !9
  %15 = load float, ptr getelementptr inbounds ([3 x float], ptr @g_lightcolor, i64 0, i64 1), align 4, !tbaa !9
  %16 = load float, ptr %3, align 4, !tbaa !9
  %17 = fmul float %15, %16
  store float %17, ptr getelementptr inbounds ([3 x float], ptr @_ZL6lcolor, i64 0, i64 1), align 4, !tbaa !9
  %18 = load float, ptr getelementptr inbounds ([3 x float], ptr @g_lightcolor, i64 0, i64 2), align 4, !tbaa !9
  %19 = load float, ptr %3, align 4, !tbaa !9
  %20 = fmul float %18, %19
  store float %20, ptr getelementptr inbounds ([3 x float], ptr @_ZL6lcolor, i64 0, i64 2), align 4, !tbaa !9
  %21 = load float, ptr @g_angle, align 4, !tbaa !9
  %22 = fpext float %21 to double
  %23 = fmul double %22, 0x3FA6C16C16C16C17
  %24 = fptosi double %23 to i32
  %25 = and i32 %24, 15
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [16 x [256 x float]], ptr @_ZN9CMD2Model11anorms_dotsE, i64 0, i64 %26
  %28 = getelementptr inbounds [256 x float], ptr %27, i64 0, i64 0
  store ptr %28, ptr @_ZL9shadedots, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

@_ZN9CMD2Model11anorms_dotsE = external dso_local global [16 x [256 x float]], align 16
@g_lightcolor = external dso_local local_unnamed_addr global [3 x float], align 4
@g_ambientlight = external dso_local local_unnamed_addr global i32, align 4
@g_shadelight = external dso_local local_unnamed_addr global float, align 4
@g_angle = external dso_local local_unnamed_addr global float, align 4
@_ZL6lcolor = external hidden local_unnamed_addr global [3 x float], align 4
@_ZL9shadedots = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_ZN9CMD2Model15ProcessLightingEv(ptr nocapture noundef nonnull readnone align 8 dereferenceable(84) %0) local_unnamed_addr #0 align 2 {
  %2 = load float, ptr @g_shadelight, align 4, !tbaa !5
  %3 = load i32, ptr @g_ambientlight, align 4, !tbaa !9
  %4 = sitofp i32 %3 to float
  %5 = fadd float %2, %4
  %6 = fmul float %5, 3.906250e-03
  %7 = load <2 x float>, ptr @g_lightcolor, align 4, !tbaa !5
  %8 = insertelement <2 x float> poison, float %6, i64 0
  %9 = shufflevector <2 x float> %8, <2 x float> poison, <2 x i32> zeroinitializer
  %10 = fmul <2 x float> %7, %9
  store <2 x float> %10, ptr @_ZL6lcolor, align 4, !tbaa !5
  %11 = load float, ptr getelementptr inbounds (i8, ptr @g_lightcolor, i64 8), align 4, !tbaa !5
  %12 = fmul float %6, %11
  store float %12, ptr getelementptr inbounds (i8, ptr @_ZL6lcolor, i64 8), align 4, !tbaa !5
  %13 = load float, ptr @g_angle, align 4, !tbaa !5
  %14 = fpext float %13 to double
  %15 = fmul double %14, 0x3FA6C16C16C16C17
  %16 = fptosi double %15 to i32
  %17 = and i32 %16, 15
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds [16 x [256 x float]], ptr @_ZN9CMD2Model11anorms_dotsE, i64 0, i64 %18
  store ptr %19, ptr @_ZL9shadedots, align 8, !tbaa !11
  ret void
}

attributes #0 = { 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass