; 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(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 = %48, %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 %51

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 = load i8, ptr %38, align 1, !tbaa !11
  %40 = load i16, ptr %4, align 2, !tbaa !9
  %41 = zext i16 %40 to i32
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr @sprites_ram, i64 %42
  %44 = load i16, ptr %5, align 2, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %43, i64 %46
  store i8 %39, ptr %47, align 1, !tbaa !11
  br label %48

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

51:                                               ; 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(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 %vector.memcheck22

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %vector.memcheck ]
  %21 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  store i8 %22, ptr %23, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %24 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next
  store i8 %25, ptr %26, align 1, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %27 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next.1
  store i8 %28, ptr %29, align 1, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %30 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next.2
  store i8 %31, ptr %32, 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 %vector.memcheck22, label %scalar.ph, !llvm.loop !8

vector.memcheck22:                                ; preds = %scalar.ph, %vector.body
  %33 = add i64 %3, ptrtoint (ptr @sprites_ram to i64)
  %34 = sub i64 %33, %2
  %diff.check23 = icmp ult i64 %34, 32
  br i1 %diff.check23, label %.preheader, label %vector.body28

vector.body28:                                    ; preds = %vector.memcheck22
  %35 = getelementptr inbounds i8, ptr %0, i64 1024
  %36 = getelementptr inbounds i8, ptr %0, i64 1040
  %wide.load30 = load <16 x i8>, ptr %35, align 1, !tbaa !5
  %wide.load31 = load <16 x i8>, ptr %36, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %4, i64 1024
  %38 = getelementptr inbounds i8, ptr %4, i64 1040
  store <16 x i8> %wide.load30, ptr %37, align 1, !tbaa !5
  store <16 x i8> %wide.load31, ptr %38, align 1, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %0, i64 1056
  %40 = getelementptr inbounds i8, ptr %0, i64 1072
  %wide.load30.1 = load <16 x i8>, ptr %39, align 1, !tbaa !5
  %wide.load31.1 = load <16 x i8>, ptr %40, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %4, i64 1056
  %42 = getelementptr inbounds i8, ptr %4, i64 1072
  store <16 x i8> %wide.load30.1, ptr %41, align 1, !tbaa !5
  store <16 x i8> %wide.load31.1, ptr %42, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %0, i64 1088
  %44 = getelementptr inbounds i8, ptr %0, i64 1104
  %wide.load30.2 = load <16 x i8>, ptr %43, align 1, !tbaa !5
  %wide.load31.2 = load <16 x i8>, ptr %44, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %4, i64 1088
  %46 = getelementptr inbounds i8, ptr %4, i64 1104
  store <16 x i8> %wide.load30.2, ptr %45, align 1, !tbaa !5
  store <16 x i8> %wide.load31.2, ptr %46, align 1, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %0, i64 1120
  %48 = getelementptr inbounds i8, ptr %0, i64 1136
  %wide.load30.3 = load <16 x i8>, ptr %47, align 1, !tbaa !5
  %wide.load31.3 = load <16 x i8>, ptr %48, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %4, i64 1120
  %50 = getelementptr inbounds i8, ptr %4, i64 1136
  store <16 x i8> %wide.load30.3, ptr %49, align 1, !tbaa !5
  store <16 x i8> %wide.load31.3, ptr %50, align 1, !tbaa !5
  br label %middle.block24

.preheader:                                       ; preds = %vector.memcheck22, %.preheader
  %indvars.iv17 = phi i64 [ %indvars.iv.next18.3, %.preheader ], [ 1024, %vector.memcheck22 ]
  %51 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv17
  %52 = load i8, ptr %51, align 1, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv17
  store i8 %52, ptr %53, align 1, !tbaa !5
  %indvars.iv.next18 = or disjoint i64 %indvars.iv17, 1
  %54 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next18
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next18
  store i8 %55, ptr %56, align 1, !tbaa !5
  %indvars.iv.next18.1 = or disjoint i64 %indvars.iv17, 2
  %57 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next18.1
  %58 = load i8, ptr %57, align 1, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next18.1
  store i8 %58, ptr %59, align 1, !tbaa !5
  %indvars.iv.next18.2 = or disjoint i64 %indvars.iv17, 3
  %60 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next18.2
  %61 = load i8, ptr %60, align 1, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv.next18.2
  store i8 %61, ptr %62, 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 %.preheader, !llvm.loop !11

middle.block24:                                   ; preds = %.preheader, %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