; LLVM IR from sejja/3D-Software-Rasterizer :: Rasterizer/Engine/System/Main.ll (Z29ConvertFrameBufferToSFMLImageRN2sf5ImageE)

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

%"struct.Graphics::Color" = type { float, float, float }
%"class.sf::Color" = type { i8, i8, i8, i8 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z29ConvertFrameBufferToSFMLImageRN2sf5ImageE(ptr noundef nonnull align 8 dereferenceable(32) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca float, align 4
  %13 = alloca %"struct.Graphics::Color", align 4
  %14 = alloca %"struct.Graphics::Color", align 4
  %15 = alloca { <2 x float>, float }, align 8
  %16 = alloca %"class.sf::Color", align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %17 = call noundef i32 @_ZN11FrameBuffer8GetWidthEv()
  store i32 %17, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %18 = call noundef i32 @_ZN11FrameBuffer9GetHeightEv()
  store i32 %18, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %19 = call noundef nonnull align 8 dereferenceable(208) ptr @_ZN9GFXSystem11GetInstanceEv() #6
  %20 = call noundef ptr @_ZN9GFXSystem14GetPostProcessEv(ptr noundef nonnull align 8 dereferenceable(208) %19) #6
  store ptr %20, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %70, %1
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %73

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %66, %26
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %69

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = call noundef float @_ZN11FrameBuffer8GetPixelEjjRhS0_S0_(i32 noundef %33, i32 noundef %34, ptr noundef nonnull align 1 dereferenceable(1) %9, ptr noundef nonnull align 1 dereferenceable(1) %11, ptr noundef nonnull align 1 dereferenceable(1) %10)
  store float %35, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 12, ptr %13) #6
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #6
  %37 = getelementptr inbounds %"struct.Graphics::Color", ptr %14, i32 0, i32 0
  %38 = load i8, ptr %9, align 1, !tbaa !13
  %39 = uitofp i8 %38 to float
  store float %39, ptr %37, align 4, !tbaa !14
  %40 = getelementptr inbounds %"struct.Graphics::Color", ptr %14, i32 0, i32 1
  %41 = load i8, ptr %11, align 1, !tbaa !13
  %42 = uitofp i8 %41 to float
  store float %42, ptr %40, align 4, !tbaa !16
  %43 = getelementptr inbounds %"struct.Graphics::Color", ptr %14, i32 0, i32 2
  %44 = load i8, ptr %10, align 1, !tbaa !13
  %45 = uitofp i8 %44 to float
  store float %45, ptr %43, align 4, !tbaa !17
  %46 = load float, ptr %12, align 4, !tbaa !11
  %47 = load ptr, ptr %36, align 8, !tbaa !18
  %48 = getelementptr inbounds ptr, ptr %47, i64 0
  %49 = load ptr, ptr %48, align 8
  %50 = call { <2 x float>, float } %49(ptr noundef nonnull align 8 dereferenceable(8) %36, ptr noundef nonnull align 4 dereferenceable(12) %14, float noundef %46) #6
  store { <2 x float>, float } %50, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 8 %15, i64 12, i1 false)
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #6
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = sub nsw i32 %53, %54
  %56 = sub nsw i32 %55, 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %57 = getelementptr inbounds %"struct.Graphics::Color", ptr %13, i32 0, i32 0
  %58 = load float, ptr %57, align 4, !tbaa !14
  %59 = fptoui float %58 to i8
  %60 = getelementptr inbounds %"struct.Graphics::Color", ptr %13, i32 0, i32 1
  %61 = load float, ptr %60, align 4, !tbaa !16
  %62 = fptoui float %61 to i8
  %63 = getelementptr inbounds %"struct.Graphics::Color", ptr %13, i32 0, i32 2
  %64 = load float, ptr %63, align 4, !tbaa !17
  %65 = fptoui float %64 to i8
  call void @_ZN2sf5ColorC1Ehhhh(ptr noundef nonnull align 1 dereferenceable(4) %16, i8 noundef zeroext %59, i8 noundef zeroext %62, i8 noundef zeroext %65, i8 noundef zeroext -1)
  call void @_ZN2sf5Image8setPixelEjjRKNS_5ColorE(ptr noundef nonnull align 8 dereferenceable(32) %51, i32 noundef %52, i32 noundef %56, ptr noundef nonnull align 1 dereferenceable(4) %16)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #6
  br label %66

66:                                               ; preds = %32
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %8, align 4, !tbaa !9
  br label %27, !llvm.loop !20

69:                                               ; preds = %31
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %6, align 4, !tbaa !9
  br label %21, !llvm.loop !22

73:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11FrameBuffer8GetWidthEv() #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11FrameBuffer9GetHeightEv() #2 align 2

; Function Attrs: nounwind
declare noundef nonnull align 8 dereferenceable(208) ptr @_ZN9GFXSystem11GetInstanceEv() #3

; Function Attrs: nounwind
declare noundef ptr @_ZN9GFXSystem14GetPostProcessEv(ptr noundef nonnull align 8 dereferenceable(208)) #3

declare noundef float @_ZN11FrameBuffer8GetPixelEjjRhS0_S0_(i32 noundef, i32 noundef, ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1)) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

declare void @_ZN2sf5Image8setPixelEjjRKNS_5ColorE(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, ptr noundef nonnull align 1 dereferenceable(4)) #4

declare void @_ZN2sf5ColorC1Ehhhh(ptr noundef nonnull align 1 dereferenceable(4), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #4

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"_ZTSN8Graphics5ColorE", !12, i64 0, !12, i64 4, !12, i64 8}
!16 = !{!15, !12, i64 4}
!17 = !{!15, !12, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

%"struct.Graphics::Color" = type { float, float, float }
%"class.sf::Color" = type { i8, i8, i8, i8 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z29ConvertFrameBufferToSFMLImageRN2sf5ImageE(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 {
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca %"struct.Graphics::Color", align 4
  %6 = alloca %"class.sf::Color", align 1
  %7 = tail call noundef i32 @_ZN11FrameBuffer8GetWidthEv()
  %8 = tail call noundef i32 @_ZN11FrameBuffer9GetHeightEv()
  %9 = tail call noundef nonnull align 8 dereferenceable(208) ptr @_ZN9GFXSystem11GetInstanceEv() #5
  %10 = tail call noundef ptr @_ZN9GFXSystem14GetPostProcessEv(ptr noundef nonnull align 8 dereferenceable(208) %9) #5
  %11 = icmp sgt i32 %7, 0
  br i1 %11, label %.preheader.lr.ph, label %._crit_edge18

.preheader.lr.ph:                                 ; preds = %1
  %12 = icmp sgt i32 %8, 0
  %13 = getelementptr inbounds i8, ptr %5, i64 4
  %14 = getelementptr inbounds i8, ptr %5, i64 8
  br i1 %12, label %.preheader.us, label %._crit_edge18

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %.017.us = phi i32 [ %32, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  br label %15

15:                                               ; preds = %.preheader.us, %15
  %.01416.us = phi i32 [ 0, %.preheader.us ], [ %31, %15 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #5
  %16 = call noundef float @_ZN11FrameBuffer8GetPixelEjjRhS0_S0_(i32 noundef %.017.us, i32 noundef %.01416.us, ptr noundef nonnull align 1 dereferenceable(1) %2, ptr noundef nonnull align 1 dereferenceable(1) %4, ptr noundef nonnull align 1 dereferenceable(1) %3)
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #5
  %17 = load i8, ptr %2, align 1, !tbaa !5
  %18 = uitofp i8 %17 to float
  store float %18, ptr %5, align 4, !tbaa !8
  %19 = load i8, ptr %4, align 1, !tbaa !5
  %20 = uitofp i8 %19 to float
  store float %20, ptr %13, align 4, !tbaa !11
  %21 = load i8, ptr %3, align 1, !tbaa !5
  %22 = uitofp i8 %21 to float
  store float %22, ptr %14, align 4, !tbaa !12
  %23 = load ptr, ptr %10, align 8, !tbaa !13
  %24 = load ptr, ptr %23, align 8
  %25 = call { <2 x float>, float } %24(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(12) %5, float noundef %16) #5
  %.fca.0.extract.us = extractvalue { <2 x float>, float } %25, 0
  %.fca.1.extract.us = extractvalue { <2 x float>, float } %25, 1
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #5
  %26 = xor i32 %.01416.us, -1
  %27 = add nsw i32 %8, %26
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  %.sroa.01.0.vec.extract.us = extractelement <2 x float> %.fca.0.extract.us, i64 0
  %28 = fptoui float %.sroa.01.0.vec.extract.us to i8
  %.sroa.01.4.vec.extract.us = extractelement <2 x float> %.fca.0.extract.us, i64 1
  %29 = fptoui float %.sroa.01.4.vec.extract.us to i8
  %30 = fptoui float %.fca.1.extract.us to i8
  call void @_ZN2sf5ColorC1Ehhhh(ptr noundef nonnull align 1 dereferenceable(4) %6, i8 noundef zeroext %28, i8 noundef zeroext %29, i8 noundef zeroext %30, i8 noundef zeroext -1)
  call void @_ZN2sf5Image8setPixelEjjRKNS_5ColorE(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %.017.us, i32 noundef %27, ptr noundef nonnull align 1 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #5
  %31 = add nuw nsw i32 %.01416.us, 1
  %exitcond.not = icmp eq i32 %31, %8
  br i1 %exitcond.not, label %._crit_edge.us, label %15, !llvm.loop !15

._crit_edge.us:                                   ; preds = %15
  %32 = add nuw nsw i32 %.017.us, 1
  %exitcond20.not = icmp eq i32 %32, %7
  br i1 %exitcond20.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !17

._crit_edge18:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %1
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11FrameBuffer8GetWidthEv() local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11FrameBuffer9GetHeightEv() local_unnamed_addr #2 align 2

; Function Attrs: nounwind
declare noundef nonnull align 8 dereferenceable(208) ptr @_ZN9GFXSystem11GetInstanceEv() local_unnamed_addr #3

; Function Attrs: nounwind
declare noundef ptr @_ZN9GFXSystem14GetPostProcessEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #3

declare noundef float @_ZN11FrameBuffer8GetPixelEjjRhS0_S0_(i32 noundef, i32 noundef, ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #4

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

declare void @_ZN2sf5Image8setPixelEjjRKNS_5ColorE(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, ptr noundef nonnull align 1 dereferenceable(4)) local_unnamed_addr #4

declare void @_ZN2sf5ColorC1Ehhhh(ptr noundef nonnull align 1 dereferenceable(4), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"_ZTSN8Graphics5ColorE", !10, i64 0, !10, i64 4, !10, i64 8}
!10 = !{!"float", !6, i64 0}
!11 = !{!9, !10, i64 4}
!12 = !{!9, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass