; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Graphics/R3Scene.ll (ZNK7R3Scene10LoadLightsEii)

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

@_ZZNK7R3Scene10LoadLightsEiiE7ambient = external hidden global [4 x float], 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK7R3Scene7NLightsEv(ptr noundef nonnull align 8 dereferenceable(352)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7R3Scene10LoadLightsEii(ptr noundef nonnull align 8 dereferenceable(352) %0, i32 noundef %1, i32 noundef %2) #2 align 2 {
  %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 ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352) %11)
  %13 = call noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = fptrunc double %13 to float
  store float %14, ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, align 16, !tbaa !11
  %15 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352) %11)
  %16 = call noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %17 = fptrunc double %16 to float
  store float %17, ptr getelementptr inbounds ([4 x float], ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, i64 0, i64 1), align 4, !tbaa !11
  %18 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352) %11)
  %19 = call noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24) %18)
  %20 = fptrunc double %19 to float
  store float %20, ptr getelementptr inbounds ([4 x float], ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, i64 0, i64 2), align 8, !tbaa !11
  store float 1.000000e+00, ptr getelementptr inbounds ([4 x float], ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, i64 0, i64 3), align 4, !tbaa !11
  call void @glLightModelfv(i32 noundef 2899, ptr noundef @_ZZNK7R3Scene10LoadLightsEiiE7ambient)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %48, %3
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = call noundef i32 @_ZNK7R3Scene7NLightsEv(ptr noundef nonnull align 8 dereferenceable(352) %11)
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %9, align 4
  br label %51

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = call noundef ptr @_ZNK7R3Scene5LightEi(ptr noundef nonnull align 8 dereferenceable(352) %11, i32 noundef %27)
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = add nsw i32 %29, %30
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp sgt i32 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %26
  store i32 2, ptr %9, align 4
  br label %45

35:                                               ; preds = %26
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = add nsw i32 %37, %38
  %40 = load ptr, ptr %36, align 8, !tbaa !13
  %41 = getelementptr inbounds ptr, ptr %40, i64 14
  %42 = load ptr, ptr %41, align 8
  call void %42(ptr noundef nonnull align 8 dereferenceable(76) %36, i32 noundef %39)
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %45

45:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %46 = load i32, ptr %9, align 4
  switch i32 %46, label %51 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !15

51:                                               ; preds = %45, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %7, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %53
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

declare void @glLightModelfv(i32 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #4 = { "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 #5 = { 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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@_ZZNK7R3Scene10LoadLightsEiiE7ambient = external hidden global [4 x float], align 16

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK7R3Scene7NLightsEv(ptr noundef nonnull align 8 dereferenceable(352)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK7R3Scene5LightEi(ptr noundef nonnull align 8 dereferenceable(352), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7R3Scene10LoadLightsEii(ptr noundef nonnull align 8 dereferenceable(352) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352) %0)
  %5 = tail call noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = fptrunc double %5 to float
  store float %6, ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, align 16, !tbaa !5
  %7 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352) %0)
  %8 = tail call noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %9 = fptrunc double %8 to float
  store float %9, ptr getelementptr inbounds (i8, ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, i64 4), align 4, !tbaa !5
  %10 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352) %0)
  %11 = tail call noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  %12 = fptrunc double %11 to float
  store float %12, ptr getelementptr inbounds (i8, ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, i64 8), align 8, !tbaa !5
  store float 1.000000e+00, ptr getelementptr inbounds (i8, ptr @_ZZNK7R3Scene10LoadLightsEiiE7ambient, i64 12), align 4, !tbaa !5
  tail call void @glLightModelfv(i32 noundef 2899, ptr noundef nonnull @_ZZNK7R3Scene10LoadLightsEiiE7ambient)
  %13 = tail call noundef i32 @_ZNK7R3Scene7NLightsEv(ptr noundef nonnull align 8 dereferenceable(352) %0)
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %3, %17
  %.017 = phi i32 [ %21, %17 ], [ 0, %3 ]
  %15 = tail call noundef ptr @_ZNK7R3Scene5LightEi(ptr noundef nonnull align 8 dereferenceable(352) %0, i32 noundef %.017)
  %16 = add nsw i32 %.017, %1
  %.not = icmp sgt i32 %16, %2
  br i1 %.not, label %.thread, label %17

17:                                               ; preds = %.lr.ph
  %18 = load ptr, ptr %15, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 112
  %20 = load ptr, ptr %19, align 8
  tail call void %20(ptr noundef nonnull align 8 dereferenceable(76) %15, i32 noundef %16)
  %21 = add nuw nsw i32 %.017, 1
  %22 = tail call noundef i32 @_ZNK7R3Scene7NLightsEv(ptr noundef nonnull align 8 dereferenceable(352) %0)
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %.lr.ph, label %.thread, !llvm.loop !11

.thread:                                          ; preds = %17, %.lr.ph, %3
  %.0.lcssa = phi i32 [ 0, %3 ], [ %.017, %.lr.ph ], [ %21, %17 ]
  ret i32 %.0.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Scene7AmbientEv(ptr noundef nonnull align 8 dereferenceable(352)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5RNRgb1REv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5RNRgb1GEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5RNRgb1BEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

declare void @glLightModelfv(i32 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 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 = { "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 = !{!"vtable pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass