; LLVM IR from ssloy/tinyraycaster :: framebuffer.ll (ZN11FrameBuffer14draw_rectangleEmmmmj)

; 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.FrameBuffer = type { i64, i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned int, std::allocator<unsigned int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._ZN11FrameBuffer14draw_rectangleEmmmmj = external hidden unnamed_addr constant [105 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11FrameBuffer9set_pixelEmmj(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef, i32 noundef) #0 align 2

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11FrameBuffer14draw_rectangleEmmmmj(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i32 noundef %5) #0 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i64 %4, ptr %11, align 8, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !11
  %18 = load ptr, ptr %7, align 8
  %19 = getelementptr inbounds %struct.FrameBuffer, ptr %18, i32 0, i32 2
  %20 = call noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19) #3
  %21 = getelementptr inbounds %struct.FrameBuffer, ptr %18, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.FrameBuffer, ptr %18, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !19
  %25 = mul i64 %22, %24
  %26 = icmp eq i64 %20, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %6
  br label %30

28:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 12, ptr noundef @__PRETTY_FUNCTION__._ZN11FrameBuffer14draw_rectangleEmmmmj) #4
  unreachable

29:                                               ; No predecessors!
  br label %30

30:                                               ; preds = %29, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %67, %30
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = load i64, ptr %10, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %70

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %63, %36
  %38 = load i64, ptr %15, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %66

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = load i64, ptr %13, align 8, !tbaa !9
  %45 = add i64 %43, %44
  store i64 %45, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = add i64 %46, %47
  store i64 %48, ptr %17, align 8, !tbaa !9
  %49 = load i64, ptr %16, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.FrameBuffer, ptr %18, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !13
  %52 = icmp ult i64 %49, %51
  br i1 %52, label %53, label %62

53:                                               ; preds = %42
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.FrameBuffer, ptr %18, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !19
  %57 = icmp ult i64 %54, %56
  br i1 %57, label %58, label %62

58:                                               ; preds = %53
  %59 = load i64, ptr %16, align 8, !tbaa !9
  %60 = load i64, ptr %17, align 8, !tbaa !9
  %61 = load i32, ptr %12, align 4, !tbaa !11
  call void @_ZN11FrameBuffer9set_pixelEmmj(ptr noundef nonnull align 8 dereferenceable(40) %18, i64 noundef %59, i64 noundef %60, i32 noundef %61)
  br label %62

62:                                               ; preds = %58, %53, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %15, align 8, !tbaa !9
  %65 = add i64 %64, 1
  store i64 %65, ptr %15, align 8, !tbaa !9
  br label %37, !llvm.loop !20

66:                                               ; preds = %41
  br label %67

67:                                               ; preds = %66
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = add i64 %68, 1
  store i64 %69, ptr %13, align 8, !tbaa !9
  br label %31, !llvm.loop !22

70:                                               ; preds = %35
  ret void
}

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

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

attributes #0 = { 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 #1 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS11FrameBuffer", !10, i64 0, !10, i64 8, !15, i64 16}
!15 = !{!"_ZTSSt6vectorIjSaIjEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIjSaIjEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIjSaIjEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIjSaIjEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!14, !10, i64 8}
!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"

@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._ZN11FrameBuffer14draw_rectangleEmmmmj = external hidden unnamed_addr constant [105 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11FrameBuffer9set_pixelEmmj(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11FrameBuffer14draw_rectangleEmmmmj(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i32 noundef %5) local_unnamed_addr #0 align 2 {
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = tail call noundef i64 @_ZNKSt6vectorIjSaIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #2
  %9 = load i64, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !15
  %12 = mul i64 %11, %9
  %13 = icmp eq i64 %8, %12
  br i1 %13, label %.preheader19, label %25

.preheader19:                                     ; preds = %6
  %.not = icmp eq i64 %3, 0
  %.not23 = icmp eq i64 %4, 0
  %or.cond = or i1 %.not, %.not23
  br i1 %or.cond, label %._crit_edge22, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader19, %._crit_edge.us
  %.021.us = phi i64 [ %24, %._crit_edge.us ], [ 0, %.preheader19 ]
  %14 = add i64 %.021.us, %1
  br label %15

15:                                               ; preds = %.preheader.us, %22
  %.01520.us = phi i64 [ 0, %.preheader.us ], [ %23, %22 ]
  %16 = add i64 %.01520.us, %2
  %17 = load i64, ptr %0, align 8, !tbaa !5
  %18 = icmp ult i64 %14, %17
  %19 = load i64, ptr %10, align 8
  %20 = icmp ult i64 %16, %19
  %or.cond.us = select i1 %18, i1 %20, i1 false
  br i1 %or.cond.us, label %21, label %22

21:                                               ; preds = %15
  tail call void @_ZN11FrameBuffer9set_pixelEmmj(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %14, i64 noundef %16, i32 noundef %5)
  br label %22

22:                                               ; preds = %21, %15
  %23 = add nuw i64 %.01520.us, 1
  %exitcond.not = icmp eq i64 %23, %4
  br i1 %exitcond.not, label %._crit_edge.us, label %15, !llvm.loop !16

._crit_edge.us:                                   ; preds = %22
  %24 = add nuw i64 %.021.us, 1
  %exitcond25.not = icmp eq i64 %24, %3
  br i1 %exitcond25.not, label %._crit_edge22, label %.preheader.us, !llvm.loop !18

25:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 12, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN11FrameBuffer14draw_rectangleEmmmmj) #3
  unreachable

._crit_edge22:                                    ; preds = %._crit_edge.us, %.preheader19
  ret void
}

attributes #0 = { 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 #1 = { noreturn 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 #2 = { nounwind }
attributes #3 = { noreturn 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, !7, i64 0}
!6 = !{!"_ZTS11FrameBuffer", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIjSaIjEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIjSaIjEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIjSaIjEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIjSaIjEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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