; LLVM IR from alekmaul/pvsneslib :: snes-examples/maps/DynamicMap (DynamicMap)

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

@sprites_ram = external global i8, align 1

; 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: nounwind uwtable
define dso_local void @copySpriteToRAM64x64_alt(ptr noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %6

6:                                                ; preds = %25, %2
  %7 = load i16, ptr %5, align 2, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = icmp slt i32 %8, 128
  br i1 %9, label %10, label %28

10:                                               ; preds = %6
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load i16, ptr %5, align 2, !tbaa !9
  %13 = zext i16 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %11, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = load i16, ptr %4, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr @sprites_ram, i64 %19
  %21 = load i16, ptr %5, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  store i8 %16, ptr %24, align 1, !tbaa !11
  br label %25

25:                                               ; preds = %10
  %26 = load i16, ptr %5, align 2, !tbaa !9
  %27 = add i16 %26, 1
  store i16 %27, ptr %5, align 2, !tbaa !9
  br label %6, !llvm.loop !12

28:                                               ; preds = %6
  store i16 1024, ptr %5, align 2, !tbaa !9
  br label %29

29:                                               ; preds = %50, %28
  %30 = load i16, ptr %5, align 2, !tbaa !9
  %31 = zext i16 %30 to i32
  %32 = icmp slt i32 %31, 1152
  br i1 %32, label %33, label %53

33:                                               ; preds = %29
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i16, ptr %5, align 2, !tbaa !9
  %36 = zext i16 %35 to i32
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %34, i64 %37
  %39 = getelementptr inbounds i8, ptr %38, i64 -1024
  %40 = getelementptr inbounds i8, ptr %39, i64 128
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = load i16, ptr %4, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr @sprites_ram, i64 %44
  %46 = load i16, ptr %5, align 2, !tbaa !9
  %47 = zext i16 %46 to i32
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  store i8 %41, ptr %49, align 1, !tbaa !11
  br label %50

50:                                               ; preds = %33
  %51 = load i16, ptr %5, align 2, !tbaa !9
  %52 = add i16 %51, 1
  store i16 %52, ptr %5, align 2, !tbaa !9
  br label %29, !llvm.loop !14

53:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@sprites_ram = external local_unnamed_addr global i8, align 1

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @copySpriteToRAM64x64_alt(ptr nocapture noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
vector.memcheck:
  %2 = ptrtoint ptr %0 to i64
  %3 = zext i16 %1 to i64
  %4 = getelementptr inbounds i8, ptr @sprites_ram, i64 %3
  %5 = add i64 %3, ptrtoint (ptr @sprites_ram to i64)
  %6 = sub i64 %5, %2
  %diff.check = icmp ult i64 %6, 32
  br i1 %diff.check, label %scalar.ph, label %vector.body

vector.body:                                      ; preds = %vector.memcheck
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.load = load <16 x i8>, ptr %0, align 1, !tbaa !5
  %wide.load21 = load <16 x i8>, ptr %7, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store <16 x i8> %wide.load, ptr %4, align 1, !tbaa !5
  store <16 x i8> %wide.load21, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %wide.load.1 = load <16 x i8>, ptr %9, align 1, !tbaa !5
  %wide.load21.1 = load <16 x i8>, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %4, i64 32
  %12 = getelementptr inbounds i8, ptr %4, i64 48
  store <16 x i8> %wide.load.1, ptr %11, align 1, !tbaa !5
  store <16 x i8> %wide.load21.1, ptr %12, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = getelementptr inbounds i8, ptr %0, i64 80
  %wide.load.2 = load <16 x i8>, ptr %13, align 1, !tbaa !5
  %wide.load21.2 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %4, i64 64
  %16 = getelementptr inbounds i8, ptr %4, i64 80
  store <16 x i8> %wide.load.2, ptr %15, align 1, !tbaa !5
  store <16 x i8> %wide.load21.2, ptr %16, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 96
  %18 = getelementptr inbounds i8, ptr %0, i64 112
  %wide.load.3 = load <16 x i8>, ptr %17, align 1, !tbaa !5
  %wide.load21.3 = load <16 x i8>, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %4, i64 96
  %20 = getelementptr inbounds i8, ptr %4, i64 112
  store <16 x i8> %wide.load.3, ptr %19, align 1, !tbaa !5
  store <16 x i8> %wide.load21.3, ptr %20, align 1, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %scalar.ph, %vector.body
  %invariant.gep = getelementptr i8, ptr %0, i64 -896
  %21 = add i64 %3, add (i64 ptrtoint (ptr @sprites_ram to i64), i64 896)
  %22 = sub i64 %21, %2
  %diff.check23 = icmp ult i64 %22, 32
  br i1 %diff.check23, label %scalar.ph25, label %vector.body28

vector.body28:                                    ; preds = %.preheader
  %23 = getelementptr i8, ptr %0, i64 128
  %24 = getelementptr i8, ptr %0, i64 144
  %wide.load30 = load <16 x i8>, ptr %23, align 1, !tbaa !5
  %wide.load31 = load <16 x i8>, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %4, i64 1024
  %26 = getelementptr inbounds i8, ptr %4, i64 1040
  store <16 x i8> %wide.load30, ptr %25, align 1, !tbaa !5
  store <16 x i8> %wide.load31, ptr %26, align 1, !tbaa !5
  %27 = getelementptr i8, ptr %0, i64 160
  %28 = getelementptr i8, ptr %0, i64 176
  %wide.load30.1 = load <16 x i8>, ptr %27, align 1, !tbaa !5
  %wide.load31.1 = load <16 x i8>, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %4, i64 1056
  %30 = getelementptr inbounds i8, ptr %4, i64 1072
  store <16 x i8> %wide.load30.1, ptr %29, align 1, !tbaa !5
  store <16 x i8> %wide.load31.1, ptr %30, align 1, !tbaa !5
  %31 = getelementptr i8, ptr %0, i64 192
  %32 = getelementptr i8, ptr %0, i64 208
  %wide.load30.2 = load <16 x i8>, ptr %31, align 1, !tbaa !5
  %wide.load31.2 = load <16 x i8>, ptr %32, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %4, i64 1088
  %34 = getelementptr inbounds i8, ptr %4, i64 1104
  store <16 x i8> %wide.load30.2, ptr %33, align 1, !tbaa !5
  store <16 x i8> %wide.load31.2, ptr %34, align 1, !tbaa !5
  %35 = getelementptr i8, ptr %0, i64 224
  %36 = getelementptr i8, ptr %0, i64 240
  %wide.load30.3 = load <16 x i8>, ptr %35, align 1, !tbaa !5
  %wide.load31.3 = load <16 x i8>, ptr %36, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %4, i64 1120
  %38 = getelementptr inbounds i8, ptr %4, i64 1136
  store <16 x i8> %wide.load30.3, ptr %37, align 1, !tbaa !5
  store <16 x i8> %wide.load31.3, ptr %38, align 1, !tbaa !5
  br label %middle.block24

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %vector.memcheck ]
  %39 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  store i8 %40, ptr %41, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %42 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %43 = load i8, ptr %42, align 1, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next
  store i8 %43, ptr %44, align 1, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %45 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next.1
  store i8 %46, ptr %47, align 1, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %48 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %49 = load i8, ptr %48, align 1, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next.2
  store i8 %49, ptr %50, align 1, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 128
  br i1 %exitcond.not.3, label %.preheader, label %scalar.ph, !llvm.loop !8

scalar.ph25:                                      ; preds = %.preheader, %scalar.ph25
  %indvars.iv17 = phi i64 [ %indvars.iv.next18.3, %scalar.ph25 ], [ 1024, %.preheader ]
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv17
  %51 = load i8, ptr %gep, align 1, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv17
  store i8 %51, ptr %52, align 1, !tbaa !5
  %indvars.iv.next18 = or disjoint i64 %indvars.iv17, 1
  %gep.1 = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv.next18
  %53 = load i8, ptr %gep.1, align 1, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next18
  store i8 %53, ptr %54, align 1, !tbaa !5
  %indvars.iv.next18.1 = or disjoint i64 %indvars.iv17, 2
  %gep.2 = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv.next18.1
  %55 = load i8, ptr %gep.2, align 1, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next18.1
  store i8 %55, ptr %56, align 1, !tbaa !5
  %indvars.iv.next18.2 = or disjoint i64 %indvars.iv17, 3
  %gep.3 = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv.next18.2
  %57 = load i8, ptr %gep.3, align 1, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next18.2
  store i8 %57, ptr %58, align 1, !tbaa !5
  %indvars.iv.next18.3 = add nuw nsw i64 %indvars.iv17, 4
  %exitcond20.not.3 = icmp eq i64 %indvars.iv.next18.3, 1152
  br i1 %exitcond20.not.3, label %middle.block24, label %scalar.ph25, !llvm.loop !11

middle.block24:                                   ; preds = %scalar.ph25, %vector.body28
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: read, inaccessiblemem: none) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = distinct !{!11, !9, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass