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

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

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

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

21:                                               ; preds = %64, %1
  %22 = load i32, ptr %6, align 4, !tbaa !17
  %23 = load i32, ptr %5, align 4, !tbaa !17
  %24 = icmp ult i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %67

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

64:                                               ; preds = %26
  %65 = load i32, ptr %6, align 4, !tbaa !17
  %66 = add i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !17
  br label %21, !llvm.loop !19

67:                                               ; preds = %25
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = icmp eq ptr %68, null
  br i1 %69, label %71, label %70

70:                                               ; preds = %67
  call void @_ZdlPvm(ptr noundef %68, i64 noundef 1) #8
  br label %71

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nobuiltin 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 #5 = { nobuiltin 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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 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 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !12, i64 8}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"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"

; 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 #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5tdogl6Bitmap14flipVerticallyEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0) local_unnamed_addr #2 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 = zext i32 %5 to i64
  %7 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %6) #5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = lshr i32 %9, 1
  %.not = icmp ult i32 %9, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %.016 = phi i32 [ 0, %.lr.ph ], [ %29, %12 ]
  %13 = load ptr, ptr %11, align 8, !tbaa !14
  %14 = load i32, ptr %3, align 4, !tbaa !12
  %15 = load i32, ptr %8, align 8, !tbaa !13
  %16 = load i32, ptr %0, align 8, !tbaa !5
  %17 = tail call noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef 0, i32 noundef %.016, i32 noundef %14, i32 noundef %15, i32 noundef %16)
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %13, i64 %18
  %20 = load ptr, ptr %11, align 8, !tbaa !14
  %21 = load i32, ptr %8, align 8, !tbaa !13
  %22 = xor i32 %.016, -1
  %23 = add i32 %21, %22
  %24 = load i32, ptr %3, align 4, !tbaa !12
  %25 = load i32, ptr %0, align 8, !tbaa !5
  %26 = tail call noundef i32 @_Z14GetPixelOffsetjjjjN5tdogl6Bitmap6FormatE(i32 noundef 0, i32 noundef %23, i32 noundef %24, i32 noundef %21, i32 noundef %25)
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %20, i64 %27
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %7, ptr align 1 %19, i64 %6, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %19, ptr align 1 %28, i64 %6, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %28, ptr nonnull align 1 %7, i64 %6, i1 false)
  %29 = add nuw nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %29, %10
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !15

._crit_edge:                                      ; preds = %12, %1
  tail call void @_ZdlPvm(ptr noundef nonnull %7, i64 noundef 1) #6
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nobuiltin 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 #4 = { nobuiltin 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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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