; LLVM IR from jrouwe/JoltPhysics :: TestFramework/Image/Surface.ll (ZN7Surface5ClearEN3JPH5ColorE)

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

%"class.JPH::Color" = type { %union.anon }
%union.anon = type { 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 noundef i32 @_ZNK17FormatDescription6EncodeEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48), i32) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7Surface4LockE16ESurfaceLockMode(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7Surface6UnLockEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Surface5ClearEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 %1) #1 align 2 {
  %3 = alloca %"class.JPH::Color", align 4
  %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 %"class.JPH::Color", align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = getelementptr inbounds %"class.JPH::Color", ptr %3, i32 0, i32 0
  %14 = getelementptr inbounds %union.anon, ptr %13, i32 0, i32 0
  store i32 %1, ptr %14, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8
  call void @_ZNK7Surface4LockE16ESurfaceLockMode(ptr noundef nonnull align 8 dereferenceable(48) %15, i32 noundef 2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %16 = call noundef i32 @_ZNK7Surface16GetBytesPerPixelEv(ptr noundef nonnull align 8 dereferenceable(48) %15)
  store i32 %16, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %17 = call noundef i32 @_ZNK7Surface8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(48) %15)
  store i32 %17, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %18 = call noundef i32 @_ZNK7Surface9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(48) %15)
  store i32 %18, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %19 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNK7Surface20GetFormatDescriptionEv(ptr noundef nonnull align 8 dereferenceable(48) %15)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %3, i64 4, i1 false), !tbaa.struct !11
  %20 = getelementptr inbounds %"class.JPH::Color", ptr %9, i32 0, i32 0
  %21 = getelementptr inbounds %union.anon, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4
  %23 = call noundef i32 @_ZNK17FormatDescription6EncodeEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48) %19, i32 %22)
  store i32 %23, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %52, %2
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %55

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = call noundef ptr @_ZN7Surface11GetScanLineEi(ptr noundef nonnull align 8 dereferenceable(48) %15, i32 noundef %30)
  store ptr %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = call noundef ptr @_ZN7Surface11GetScanLineEi(ptr noundef nonnull align 8 dereferenceable(48) %15, i32 noundef %32)
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = mul nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %33, i64 %37
  store ptr %38, ptr %12, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %43, %29
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = icmp ult ptr %40, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %39
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %44, ptr align 4 %8, i64 %46, i1 false)
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = sext i32 %47 to i64
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  store ptr %50, ptr %11, align 8, !tbaa !5
  br label %39, !llvm.loop !13

51:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %10, align 4, !tbaa !9
  br label %24, !llvm.loop !15

55:                                               ; preds = %28
  call void @_ZNK7Surface6UnLockEv(ptr noundef nonnull align 8 dereferenceable(48) %15)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK7Surface16GetBytesPerPixelEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Surface8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Surface9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(48) ptr @_ZNK7Surface20GetFormatDescriptionEv(ptr noundef nonnull align 8 dereferenceable(48)) #3 align 2

; 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) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN7Surface11GetScanLineEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) #5 align 2

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


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

; 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 noundef i32 @_ZNK17FormatDescription6EncodeEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48), i32) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7Surface4LockE16ESurfaceLockMode(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7Surface6UnLockEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Surface5ClearEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 %1) local_unnamed_addr #1 align 2 {
  %3 = alloca i32, align 4
  tail call void @_ZNK7Surface4LockE16ESurfaceLockMode(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef 2)
  %4 = tail call noundef i32 @_ZNK7Surface16GetBytesPerPixelEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %5 = tail call noundef i32 @_ZNK7Surface8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %6 = tail call noundef i32 @_ZNK7Surface9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3)
  %7 = tail call noundef nonnull align 8 dereferenceable(48) ptr @_ZNK7Surface20GetFormatDescriptionEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %8 = tail call noundef i32 @_ZNK17FormatDescription6EncodeEN3JPH5ColorE(ptr noundef nonnull align 8 dereferenceable(48) %7, i32 %1)
  store i32 %8, ptr %3, align 4, !tbaa !5
  %9 = icmp sgt i32 %6, 0
  br i1 %9, label %.lr.ph18, label %._crit_edge19

.lr.ph18:                                         ; preds = %2
  %10 = mul nsw i32 %5, %4
  %11 = sext i32 %10 to i64
  %12 = sext i32 %4 to i64
  br label %13

._crit_edge19:                                    ; preds = %._crit_edge, %2
  tail call void @_ZNK7Surface6UnLockEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3)
  ret void

13:                                               ; preds = %.lr.ph18, %._crit_edge
  %.016 = phi i32 [ 0, %.lr.ph18 ], [ %20, %._crit_edge ]
  %14 = tail call noundef ptr @_ZN7Surface11GetScanLineEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %.016)
  %15 = tail call noundef ptr @_ZN7Surface11GetScanLineEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %.016)
  %16 = getelementptr inbounds i8, ptr %15, i64 %11
  %17 = icmp ult ptr %14, %16
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.01415 = phi ptr [ %18, %.lr.ph ], [ %14, %13 ]
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.01415, ptr nonnull align 4 %3, i64 %12, i1 false)
  %18 = getelementptr inbounds i8, ptr %.01415, i64 %12
  %19 = icmp ult ptr %18, %16
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %13
  %20 = add nuw nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %20, %6
  br i1 %exitcond.not, label %._crit_edge19, label %13, !llvm.loop !11
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK7Surface16GetBytesPerPixelEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Surface8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Surface9GetHeightEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(48) ptr @_ZNK7Surface20GetFormatDescriptionEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress 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) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN7Surface11GetScanLineEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) local_unnamed_addr #5 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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