; LLVM IR from ysyesilyurt/ComputerGraphics :: RayTracing/Scene.ll (Z9renderRowP5ImageiP5Scenei)

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

%union.Color = type { %struct.anon }
%struct.anon = type { i8, i8, i8 }
%class.Scene = type { i32, float, float, %struct.Vector3f, %struct.Vector3f, %"class.std::vector.2", %"class.std::vector.7", %"class.std::vector.12", %"class.std::vector.17", %"class.std::vector" }
%struct.Vector3f = type { %union.anon, %union.anon.0, %union.anon.1 }
%union.anon = type { float }
%union.anon.0 = type { float }
%union.anon.1 = type { float }
%"class.std::vector.2" = type { %"struct.std::_Vector_base.3" }
%"struct.std::_Vector_base.3" = type { %"struct.std::_Vector_base<Camera *, std::allocator<Camera *>>::_Vector_impl" }
%"struct.std::_Vector_base<Camera *, std::allocator<Camera *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Camera *, std::allocator<Camera *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Camera *, std::allocator<Camera *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.7" = type { %"struct.std::_Vector_base.8" }
%"struct.std::_Vector_base.8" = type { %"struct.std::_Vector_base<PointLight *, std::allocator<PointLight *>>::_Vector_impl" }
%"struct.std::_Vector_base<PointLight *, std::allocator<PointLight *>>::_Vector_impl" = type { %"struct.std::_Vector_base<PointLight *, std::allocator<PointLight *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<PointLight *, std::allocator<PointLight *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.12" = type { %"struct.std::_Vector_base.13" }
%"struct.std::_Vector_base.13" = type { %"struct.std::_Vector_base<Material *, std::allocator<Material *>>::_Vector_impl" }
%"struct.std::_Vector_base<Material *, std::allocator<Material *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Material *, std::allocator<Material *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Material *, std::allocator<Material *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.17" = type { %"struct.std::_Vector_base.18" }
%"struct.std::_Vector_base.18" = type { %"struct.std::_Vector_base<Vector3f, std::allocator<Vector3f>>::_Vector_impl" }
%"struct.std::_Vector_base<Vector3f, std::allocator<Vector3f>>::_Vector_impl" = type { %"struct.std::_Vector_base<Vector3f, std::allocator<Vector3f>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Vector3f, std::allocator<Vector3f>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Shape *, std::allocator<Shape *>>::_Vector_impl" }
%"struct.std::_Vector_base<Shape *, std::allocator<Shape *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Shape *, std::allocator<Shape *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Shape *, std::allocator<Shape *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.Camera = type { [32 x i8], i32, %struct.ImagePlane, %struct.Vector3f, %struct.Vector3f, %struct.Vector3f, %struct.Vector3f }
%struct.ImagePlane = type { float, float, float, float, float, i32, 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
declare dso_local i24 @_Z11renderPixeliiP5Scenei(i32 noundef, i32 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP6CameraSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9renderRowP5ImageiP5Scenei(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %union.Color, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %34, %4
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.Scene, ptr %13, i32 0, i32 5
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP6CameraSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %14, i64 noundef %16) #5
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.Camera, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds %struct.ImagePlane, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = icmp slt i32 %12, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %37

24:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 3, ptr %10) #5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = call i24 @_Z11renderPixeliiP5Scenei(i32 noundef %25, i32 noundef %26, ptr noundef %27, i32 noundef %28)
  %30 = getelementptr inbounds %union.Color, ptr %10, i32 0, i32 0
  store i24 %29, ptr %30, align 1
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN5Image13setPixelValueEiiRK5Color(ptr noundef nonnull align 8 dereferenceable(16) %31, i32 noundef %32, i32 noundef %33, ptr noundef nonnull align 1 dereferenceable(3) %10)
  call void @llvm.lifetime.end.p0(i64 3, ptr %10) #5
  br label %34

34:                                               ; preds = %24
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %11, !llvm.loop !16

37:                                               ; preds = %23
  ret void
}

declare void @_ZN5Image13setPixelValueEiiRK5Color(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, ptr noundef nonnull align 1 dereferenceable(3)) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { 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 = { "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, !10, i64 56}
!12 = !{!"_ZTS6Camera", !7, i64 0, !10, i64 32, !13, i64 36, !15, i64 64, !15, i64 76, !15, i64 88, !15, i64 100}
!13 = !{!"_ZTS10ImagePlane", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !10, i64 20, !10, i64 24}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTS8Vector3f", !7, i64 0, !7, i64 4, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%union.Color = type { %struct.anon }
%struct.anon = type { i8, i8, i8 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local i24 @_Z11renderPixeliiP5Scenei(i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP6CameraSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9renderRowP5ImageiP5Scenei(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca %union.Color, align 4
  %6 = getelementptr inbounds i8, ptr %2, i64 40
  %7 = sext i32 %3 to i64
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP6CameraSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %7) #5
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 56
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %4
  ret void

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.010 = phi i32 [ %14, %.lr.ph ], [ 0, %4 ]
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %5) #5
  %13 = call i24 @_Z11renderPixeliiP5Scenei(i32 noundef %.010, i32 noundef %1, ptr noundef %2, i32 noundef %3)
  store i24 %13, ptr %5, align 4
  call void @_ZN5Image13setPixelValueEiiRK5Color(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.010, i32 noundef %1, ptr noundef nonnull align 1 dereferenceable(3) %5)
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %5) #5
  %14 = add nuw nsw i32 %.010, 1
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP6CameraSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %7) #5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 56
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp slt i32 %14, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !15
}

declare void @_ZN5Image13setPixelValueEiiRK5Color(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { 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 = { "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, !11, i64 56}
!10 = !{!"_ZTS6Camera", !7, i64 0, !11, i64 32, !12, i64 36, !14, i64 64, !14, i64 76, !14, i64 88, !14, i64 100}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS10ImagePlane", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !11, i64 20, !11, i64 24}
!13 = !{!"float", !7, i64 0}
!14 = !{!"_ZTS8Vector3f", !7, i64 0, !7, i64 4, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass