; LLVM IR from mackorone/mms :: old/v2/src/lib/tdogl/Bitmap.ll (ZN5tdogl6Bitmap24rotate90CounterClockwiseEv)

; 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.tdogl::Bitmap" = type { i32, i32, i32, ptr }

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #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) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5tdogl6Bitmap24rotate90CounterClockwiseEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %11 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = mul i32 %12, %14
  %16 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = mul i32 %15, %17
  %19 = zext i32 %18 to i64
  %20 = call noalias ptr @malloc(i64 noundef %19) #7
  store ptr %20, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %73, %1
  %22 = load i32, ptr %4, align 4, !tbaa !15
  %23 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = icmp ult i32 %22, %24
  br i1 %25, label %27, label %26

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

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

28:                                               ; preds = %69, %27
  %29 = load i32, ptr %6, align 4, !tbaa !15
  %30 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = icmp ult i32 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %72

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %35 = load i32, ptr %6, align 4, !tbaa !15
  %36 = load i32, ptr %4, align 4, !tbaa !15
  %37 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = call noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef %35, i32 noundef %36, i32 noundef %38, i32 noundef %40, i32 noundef %42)
  store i32 %43, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %44 = load i32, ptr %4, align 4, !tbaa !15
  %45 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = load i32, ptr %6, align 4, !tbaa !15
  %48 = sub i32 %46, %47
  %49 = sub i32 %48, 1
  %50 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !14
  %52 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !9
  %56 = call noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef %44, i32 noundef %49, i32 noundef %51, i32 noundef %53, i32 noundef %55)
  store i32 %56, ptr %8, align 4, !tbaa !15
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !15
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = load i32, ptr %7, align 4, !tbaa !15
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !9
  %68 = zext i32 %67 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %60, ptr align 1 %65, i64 %68, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %69

69:                                               ; preds = %34
  %70 = load i32, ptr %6, align 4, !tbaa !15
  %71 = add i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !15
  br label %28, !llvm.loop !17

72:                                               ; preds = %33
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %4, align 4, !tbaa !15
  %75 = add i32 %74, 1
  store i32 %75, ptr %4, align 4, !tbaa !15
  br label %21, !llvm.loop !19

76:                                               ; preds = %26
  %77 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  call void @free(ptr noundef %78) #6
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 3
  store ptr %79, ptr %80, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %81 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 2
  %82 = load i32, ptr %81, align 8, !tbaa !14
  store i32 %82, ptr %9, align 4, !tbaa !15
  %83 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  %84 = load i32, ptr %83, align 4, !tbaa !13
  %85 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 2
  store i32 %84, ptr %85, align 8, !tbaa !14
  %86 = load i32, ptr %9, align 4, !tbaa !15
  %87 = getelementptr inbounds %"class.tdogl::Bitmap", ptr %10, i32 0, i32 1
  store i32 %86, ptr %87, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

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

!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 0}
!10 = !{!"_ZTSN5tdogl6BitmapE", !11, i64 0, !12, i64 4, !12, i64 8, !6, i64 16}
!11 = !{!"_ZTSN5tdogl6Bitmap6FormatE", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 4}
!14 = !{!10, !12, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5tdogl6Bitmap24rotate90CounterClockwiseEv(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #3 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !12
  %5 = mul i32 %4, %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !13
  %8 = mul i32 %5, %7
  %9 = zext i32 %8 to i64
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge17, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %.not18 = icmp eq i32 %4, 0
  br i1 %.not18, label %._crit_edge17, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %12 = phi i32 [ %19, %._crit_edge ], [ %7, %.preheader.lr.ph ]
  %13 = phi i32 [ %20, %._crit_edge ], [ %2, %.preheader.lr.ph ]
  %14 = phi i32 [ %21, %._crit_edge ], [ %4, %.preheader.lr.ph ]
  %.016 = phi i32 [ %22, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.not19 = icmp eq i32 %14, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

._crit_edge17:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %1
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  tail call void @free(ptr noundef %16) #6
  store ptr %10, ptr %15, align 8, !tbaa !14
  %17 = load <2 x i32>, ptr %3, align 4, !tbaa !15
  %18 = shufflevector <2 x i32> %17, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i32> %18, ptr %3, align 4, !tbaa !15
  ret void

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %6, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %19 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %.preheader ]
  %20 = phi i32 [ %39, %._crit_edge.loopexit ], [ %13, %.preheader ]
  %21 = phi i32 [ %42, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %22 = add nuw i32 %.016, 1
  %23 = icmp ult i32 %22, %19
  br i1 %23, label %.preheader, label %._crit_edge17, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %24 = phi i32 [ %39, %.lr.ph ], [ %13, %.preheader ]
  %25 = phi i32 [ %42, %.lr.ph ], [ %14, %.preheader ]
  %.01315 = phi i32 [ %41, %.lr.ph ], [ 0, %.preheader ]
  %26 = load i32, ptr %6, align 8, !tbaa !13
  %27 = tail call noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef %.01315, i32 noundef %.016, i32 noundef %25, i32 noundef %26, i32 noundef %24)
  %28 = load i32, ptr %3, align 4, !tbaa !12
  %29 = xor i32 %.01315, -1
  %30 = add i32 %28, %29
  %31 = load i32, ptr %6, align 8, !tbaa !13
  %32 = load i32, ptr %0, align 8, !tbaa !5
  %33 = tail call noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef %.016, i32 noundef %30, i32 noundef %31, i32 noundef %28, i32 noundef %32)
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %10, i64 %34
  %36 = load ptr, ptr %11, align 8, !tbaa !14
  %37 = zext i32 %27 to i64
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i32, ptr %0, align 8, !tbaa !5
  %40 = zext i32 %39 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %35, ptr align 1 %38, i64 %40, i1 false)
  %41 = add nuw i32 %.01315, 1
  %42 = load i32, ptr %3, align 4, !tbaa !12
  %43 = icmp ult i32 %41, %42
  br i1 %43, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !19
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
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, !7, i64 0}
!6 = !{!"_ZTSN5tdogl6BitmapE", !7, i64 0, !10, i64 4, !10, i64 8, !11, i64 16}
!7 = !{!"_ZTSN5tdogl6Bitmap6FormatE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !11, i64 16}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17, !18}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.unswitch.partial.disable"}
!19 = distinct !{!19, !17}


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