; LLVM IR from Stephane-D/SGDK :: sample/demo/bad-apple/src (pcm)

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

@smp_null_dpcm = external constant [128 x i8], align 16

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

declare void @Z80_requestBus(i8 noundef zeroext) #1

declare void @Z80_releaseBus() #1

; 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 @stopPlay() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @Z80_requestBus(i8 noundef zeroext 1)
  store ptr inttoptr (i64 10486036 to ptr), ptr %1, align 8, !tbaa !5
  store i64 ptrtoint (ptr @smp_null_dpcm to i64), ptr %2, align 8, !tbaa !9
  %3 = load i64, ptr %2, align 8, !tbaa !9
  %4 = lshr i64 %3, 7
  %5 = trunc i64 %4 to i8
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 0
  store volatile i8 %5, ptr %7, align 1, !tbaa !11
  %8 = load i64, ptr %2, align 8, !tbaa !9
  %9 = lshr i64 %8, 15
  %10 = trunc i64 %9 to i8
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  store volatile i8 %10, ptr %12, align 1, !tbaa !11
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 2
  store volatile i8 1, ptr %14, align 1, !tbaa !11
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 3
  store volatile i8 0, ptr %16, align 1, !tbaa !11
  store ptr inttoptr (i64 10486018 to ptr), ptr %1, align 8, !tbaa !5
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load volatile i8, ptr %18, align 1, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = and i32 %20, -2
  %22 = trunc i32 %21 to i8
  store volatile i8 %22, ptr %18, align 1, !tbaa !11
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 1
  %25 = load volatile i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = and i32 %26, -2
  %28 = trunc i32 %27 to i8
  store volatile i8 %28, ptr %24, align 1, !tbaa !11
  call void @Z80_releaseBus()
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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

@smp_null_dpcm = external constant [128 x i8], align 16

declare void @Z80_requestBus(i8 noundef zeroext) local_unnamed_addr #0

declare void @Z80_releaseBus() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @stopPlay() local_unnamed_addr #1 {
  tail call void @Z80_requestBus(i8 noundef zeroext 1) #2
  %1 = lshr i64 ptrtoint (ptr @smp_null_dpcm to i64), 7
  %2 = trunc i64 %1 to i8
  store volatile i8 %2, ptr inttoptr (i64 10486036 to ptr), align 4, !tbaa !5
  %3 = lshr i64 ptrtoint (ptr @smp_null_dpcm to i64), 15
  %4 = trunc i64 %3 to i8
  store volatile i8 %4, ptr inttoptr (i64 10486037 to ptr), align 1, !tbaa !5
  store volatile i8 1, ptr inttoptr (i64 10486038 to ptr), align 2, !tbaa !5
  store volatile i8 0, ptr inttoptr (i64 10486039 to ptr), align 1, !tbaa !5
  %5 = load volatile i8, ptr inttoptr (i64 10486018 to ptr), align 2, !tbaa !5
  %6 = and i8 %5, -2
  store volatile i8 %6, ptr inttoptr (i64 10486018 to ptr), align 2, !tbaa !5
  %7 = load volatile i8, ptr inttoptr (i64 10486019 to ptr), align 1, !tbaa !5
  %8 = and i8 %7, -2
  store volatile i8 %8, ptr inttoptr (i64 10486019 to ptr), align 1, !tbaa !5
  tail call void @Z80_releaseBus() #2
  ret void
}

attributes #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass