; LLVM IR from mist64/perfect6502 :: measure (setup_memory)

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

@memory = external global [65536 x i8], align 16
@initial_s = external dso_local global i16, align 2
@initial_p = external dso_local global i16, align 2
@initial_a = external dso_local global i16, align 2
@initial_x = external dso_local global i16, align 2
@initial_y = external dso_local global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local void @setup_memory(i8 noundef zeroext %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca i16, align 2
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @memory, i8 0, i64 65536, i1 false)
  store i8 0, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 65532), align 4, !tbaa !5
  store i8 -12, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 65533), align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  store i16 -3072, ptr %3, align 2, !tbaa !8
  %4 = load i16, ptr %3, align 2, !tbaa !8
  %5 = add i16 %4, 1
  store i16 %5, ptr %3, align 2, !tbaa !8
  %6 = zext i16 %4 to i64
  %7 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %6
  store i8 -94, ptr %7, align 1, !tbaa !5
  %8 = load i16, ptr %3, align 2, !tbaa !8
  store i16 %8, ptr @initial_s, align 2, !tbaa !8
  %9 = load i16, ptr %3, align 2, !tbaa !8
  %10 = add i16 %9, 1
  store i16 %10, ptr %3, align 2, !tbaa !8
  %11 = zext i16 %9 to i64
  %12 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %11
  store i8 127, ptr %12, align 1, !tbaa !5
  %13 = load i16, ptr %3, align 2, !tbaa !8
  %14 = add i16 %13, 1
  store i16 %14, ptr %3, align 2, !tbaa !8
  %15 = zext i16 %13 to i64
  %16 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %15
  store i8 -102, ptr %16, align 1, !tbaa !5
  %17 = load i16, ptr %3, align 2, !tbaa !8
  %18 = add i16 %17, 1
  store i16 %18, ptr %3, align 2, !tbaa !8
  %19 = zext i16 %17 to i64
  %20 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %19
  store i8 -87, ptr %20, align 1, !tbaa !5
  %21 = load i16, ptr %3, align 2, !tbaa !8
  store i16 %21, ptr @initial_p, align 2, !tbaa !8
  %22 = load i16, ptr %3, align 2, !tbaa !8
  %23 = add i16 %22, 1
  store i16 %23, ptr %3, align 2, !tbaa !8
  %24 = zext i16 %22 to i64
  %25 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %24
  store i8 0, ptr %25, align 1, !tbaa !5
  %26 = load i16, ptr %3, align 2, !tbaa !8
  %27 = add i16 %26, 1
  store i16 %27, ptr %3, align 2, !tbaa !8
  %28 = zext i16 %26 to i64
  %29 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %28
  store i8 72, ptr %29, align 1, !tbaa !5
  %30 = load i16, ptr %3, align 2, !tbaa !8
  %31 = add i16 %30, 1
  store i16 %31, ptr %3, align 2, !tbaa !8
  %32 = zext i16 %30 to i64
  %33 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %32
  store i8 -87, ptr %33, align 1, !tbaa !5
  %34 = load i16, ptr %3, align 2, !tbaa !8
  store i16 %34, ptr @initial_a, align 2, !tbaa !8
  %35 = load i16, ptr %3, align 2, !tbaa !8
  %36 = add i16 %35, 1
  store i16 %36, ptr %3, align 2, !tbaa !8
  %37 = zext i16 %35 to i64
  %38 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %37
  store i8 0, ptr %38, align 1, !tbaa !5
  %39 = load i16, ptr %3, align 2, !tbaa !8
  %40 = add i16 %39, 1
  store i16 %40, ptr %3, align 2, !tbaa !8
  %41 = zext i16 %39 to i64
  %42 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %41
  store i8 -94, ptr %42, align 1, !tbaa !5
  %43 = load i16, ptr %3, align 2, !tbaa !8
  store i16 %43, ptr @initial_x, align 2, !tbaa !8
  %44 = load i16, ptr %3, align 2, !tbaa !8
  %45 = add i16 %44, 1
  store i16 %45, ptr %3, align 2, !tbaa !8
  %46 = zext i16 %44 to i64
  %47 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !5
  %48 = load i16, ptr %3, align 2, !tbaa !8
  %49 = add i16 %48, 1
  store i16 %49, ptr %3, align 2, !tbaa !8
  %50 = zext i16 %48 to i64
  %51 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %50
  store i8 -96, ptr %51, align 1, !tbaa !5
  %52 = load i16, ptr %3, align 2, !tbaa !8
  store i16 %52, ptr @initial_y, align 2, !tbaa !8
  %53 = load i16, ptr %3, align 2, !tbaa !8
  %54 = add i16 %53, 1
  store i16 %54, ptr %3, align 2, !tbaa !8
  %55 = zext i16 %53 to i64
  %56 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %55
  store i8 0, ptr %56, align 1, !tbaa !5
  %57 = load i16, ptr %3, align 2, !tbaa !8
  %58 = add i16 %57, 1
  store i16 %58, ptr %3, align 2, !tbaa !8
  %59 = zext i16 %57 to i64
  %60 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %59
  store i8 40, ptr %60, align 1, !tbaa !5
  %61 = load i16, ptr %3, align 2, !tbaa !8
  %62 = add i16 %61, 1
  store i16 %62, ptr %3, align 2, !tbaa !8
  %63 = zext i16 %61 to i64
  %64 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %63
  store i8 76, ptr %64, align 1, !tbaa !5
  %65 = load i16, ptr %3, align 2, !tbaa !8
  %66 = add i16 %65, 1
  store i16 %66, ptr %3, align 2, !tbaa !8
  %67 = zext i16 %65 to i64
  %68 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %67
  store i8 0, ptr %68, align 1, !tbaa !5
  %69 = load i16, ptr %3, align 2, !tbaa !8
  %70 = add i16 %69, 1
  store i16 %70, ptr %3, align 2, !tbaa !8
  %71 = zext i16 %69 to i64
  %72 = getelementptr inbounds [65536 x i8], ptr @memory, i64 0, i64 %71
  store i8 -8, ptr %72, align 1, !tbaa !5
  %73 = load i8, ptr %2, align 1, !tbaa !5
  store i8 %73, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 63488), align 16, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 63489), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 63490), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 63491), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 65534), align 2, !tbaa !5
  store i8 -4, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 65535), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([65536 x i8], ptr @memory, i64 0, i64 64512), align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}


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

@memory = external local_unnamed_addr global [65536 x i8], align 16
@initial_s = external dso_local local_unnamed_addr global i16, align 2
@initial_p = external dso_local local_unnamed_addr global i16, align 2
@initial_a = external dso_local local_unnamed_addr global i16, align 2
@initial_x = external dso_local local_unnamed_addr global i16, align 2
@initial_y = external dso_local local_unnamed_addr global i16, align 2

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @setup_memory(i8 noundef zeroext %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(65536) @memory, i8 0, i64 65536, i1 false)
  store i8 -12, ptr getelementptr inbounds (i8, ptr @memory, i64 65533), align 1, !tbaa !5
  store i16 -3071, ptr @initial_s, align 2, !tbaa !8
  store <4 x i8> <i8 -94, i8 127, i8 -102, i8 -87>, ptr getelementptr inbounds (i8, ptr @memory, i64 62464), align 16, !tbaa !5
  store i16 -3068, ptr @initial_p, align 2, !tbaa !8
  store i8 72, ptr getelementptr inbounds (i8, ptr @memory, i64 62469), align 1, !tbaa !5
  store i8 -87, ptr getelementptr inbounds (i8, ptr @memory, i64 62470), align 2, !tbaa !5
  store i16 -3065, ptr @initial_a, align 2, !tbaa !8
  store i8 -94, ptr getelementptr inbounds (i8, ptr @memory, i64 62472), align 8, !tbaa !5
  store i16 -3063, ptr @initial_x, align 2, !tbaa !8
  store i8 -96, ptr getelementptr inbounds (i8, ptr @memory, i64 62474), align 2, !tbaa !5
  store i16 -3061, ptr @initial_y, align 2, !tbaa !8
  store i8 40, ptr getelementptr inbounds (i8, ptr @memory, i64 62476), align 4, !tbaa !5
  store i8 76, ptr getelementptr inbounds (i8, ptr @memory, i64 62477), align 1, !tbaa !5
  store i8 -8, ptr getelementptr inbounds (i8, ptr @memory, i64 62479), align 1, !tbaa !5
  store i8 %0, ptr getelementptr inbounds (i8, ptr @memory, i64 63488), align 16, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @memory, i64 63490), align 2, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @memory, i64 65534), align 2, !tbaa !5
  store i8 -4, ptr getelementptr inbounds (i8, ptr @memory, i64 65535), align 1, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass