; 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: nounwind uwtable
define dso_local void @copySpriteToRAM_32x32(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %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, 256
  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
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret void
}

; 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

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


; 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 @copySpriteToRAM_32x32(ptr nocapture noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
vector.memcheck:
  %2 = zext i16 %1 to i64
  %3 = getelementptr inbounds i8, ptr @sprites_ram, i64 %2
  %4 = ptrtoint ptr %0 to i64
  %5 = add i64 %2, ptrtoint (ptr @sprites_ram to i64)
  %6 = sub i64 %5, %4
  %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.load8 = load <16 x i8>, ptr %7, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 16
  store <16 x i8> %wide.load, ptr %3, align 1, !tbaa !5
  store <16 x i8> %wide.load8, 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.load8.1 = load <16 x i8>, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %3, i64 32
  %12 = getelementptr inbounds i8, ptr %3, i64 48
  store <16 x i8> %wide.load.1, ptr %11, align 1, !tbaa !5
  store <16 x i8> %wide.load8.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.load8.2 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %3, i64 64
  %16 = getelementptr inbounds i8, ptr %3, i64 80
  store <16 x i8> %wide.load.2, ptr %15, align 1, !tbaa !5
  store <16 x i8> %wide.load8.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.load8.3 = load <16 x i8>, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %3, i64 96
  %20 = getelementptr inbounds i8, ptr %3, i64 112
  store <16 x i8> %wide.load.3, ptr %19, align 1, !tbaa !5
  store <16 x i8> %wide.load8.3, ptr %20, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 128
  %22 = getelementptr inbounds i8, ptr %0, i64 144
  %wide.load.4 = load <16 x i8>, ptr %21, align 1, !tbaa !5
  %wide.load8.4 = load <16 x i8>, ptr %22, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %3, i64 128
  %24 = getelementptr inbounds i8, ptr %3, i64 144
  store <16 x i8> %wide.load.4, ptr %23, align 1, !tbaa !5
  store <16 x i8> %wide.load8.4, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 160
  %26 = getelementptr inbounds i8, ptr %0, i64 176
  %wide.load.5 = load <16 x i8>, ptr %25, align 1, !tbaa !5
  %wide.load8.5 = load <16 x i8>, ptr %26, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %3, i64 160
  %28 = getelementptr inbounds i8, ptr %3, i64 176
  store <16 x i8> %wide.load.5, ptr %27, align 1, !tbaa !5
  store <16 x i8> %wide.load8.5, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 192
  %30 = getelementptr inbounds i8, ptr %0, i64 208
  %wide.load.6 = load <16 x i8>, ptr %29, align 1, !tbaa !5
  %wide.load8.6 = load <16 x i8>, ptr %30, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %3, i64 192
  %32 = getelementptr inbounds i8, ptr %3, i64 208
  store <16 x i8> %wide.load.6, ptr %31, align 1, !tbaa !5
  store <16 x i8> %wide.load8.6, ptr %32, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %0, i64 224
  %34 = getelementptr inbounds i8, ptr %0, i64 240
  %wide.load.7 = load <16 x i8>, ptr %33, align 1, !tbaa !5
  %wide.load8.7 = load <16 x i8>, ptr %34, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %3, i64 224
  %36 = getelementptr inbounds i8, ptr %3, i64 240
  store <16 x i8> %wide.load.7, ptr %35, align 1, !tbaa !5
  store <16 x i8> %wide.load8.7, ptr %36, align 1, !tbaa !5
  br label %middle.block

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %vector.memcheck ]
  %37 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv
  store i8 %38, ptr %39, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %40 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv.next
  store i8 %41, ptr %42, align 1, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %43 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv.next.1
  store i8 %44, ptr %45, align 1, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %46 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %47 = load i8, ptr %46, align 1, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv.next.2
  store i8 %47, ptr %48, 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, 256
  br i1 %exitcond.not.3, label %middle.block, label %scalar.ph, !llvm.loop !8

middle.block:                                     ; preds = %scalar.ph, %vector.body
  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}


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