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

; 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 @startPlay(ptr noundef %0, i64 noundef %1, i8 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @Z80_requestBus(i8 noundef zeroext 1)
  store ptr inttoptr (i64 10486020 to ptr), ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = ptrtoint ptr %9 to i64
  store i64 %10, ptr %8, align 8, !tbaa !9
  %11 = load i64, ptr %8, align 8, !tbaa !9
  %12 = lshr i64 %11, 7
  %13 = trunc i64 %12 to i8
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  store volatile i8 %13, ptr %15, align 1, !tbaa !11
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = lshr i64 %16, 15
  %18 = trunc i64 %17 to i8
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  store volatile i8 %18, ptr %20, align 1, !tbaa !11
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = lshr i64 %21, 7
  %23 = trunc i64 %22 to i8
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 2
  store volatile i8 %23, ptr %25, align 1, !tbaa !11
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = lshr i64 %26, 15
  %28 = trunc i64 %27 to i8
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 3
  store volatile i8 %28, ptr %30, align 1, !tbaa !11
  store ptr inttoptr (i64 10486016 to ptr), ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load volatile i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = or i32 %33, 1
  %35 = trunc i32 %34 to i8
  store volatile i8 %35, ptr %31, align 1, !tbaa !11
  store ptr inttoptr (i64 10486018 to ptr), ptr %7, align 8, !tbaa !5
  %36 = load i8, ptr %6, align 1, !tbaa !11
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %45

38:                                               ; preds = %3
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 1
  %41 = load volatile i8, ptr %40, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = or i32 %42, 1
  %44 = trunc i32 %43 to i8
  store volatile i8 %44, ptr %40, align 1, !tbaa !11
  br label %52

45:                                               ; preds = %3
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 1
  %48 = load volatile i8, ptr %47, align 1, !tbaa !11
  %49 = zext i8 %48 to i32
  %50 = and i32 %49, -2
  %51 = trunc i32 %50 to i8
  store volatile i8 %51, ptr %47, align 1, !tbaa !11
  br label %52

52:                                               ; preds = %45, %38
  call void @Z80_releaseBus()
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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"

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 @startPlay(ptr noundef %0, i64 noundef %1, i8 noundef zeroext %2) local_unnamed_addr #1 {
  tail call void @Z80_requestBus(i8 noundef zeroext 1) #2
  %4 = ptrtoint ptr %0 to i64
  %5 = lshr i64 %4, 7
  %6 = trunc i64 %5 to i8
  store volatile i8 %6, ptr inttoptr (i64 10486020 to ptr), align 4, !tbaa !5
  %7 = lshr i64 %4, 15
  %8 = trunc i64 %7 to i8
  store volatile i8 %8, ptr inttoptr (i64 10486021 to ptr), align 1, !tbaa !5
  %9 = lshr i64 %1, 7
  %10 = trunc i64 %9 to i8
  store volatile i8 %10, ptr inttoptr (i64 10486022 to ptr), align 2, !tbaa !5
  %11 = lshr i64 %1, 15
  %12 = trunc i64 %11 to i8
  store volatile i8 %12, ptr inttoptr (i64 10486023 to ptr), align 1, !tbaa !5
  %13 = load volatile i8, ptr inttoptr (i64 10486016 to ptr), align 256, !tbaa !5
  %14 = or i8 %13, 1
  store volatile i8 %14, ptr inttoptr (i64 10486016 to ptr), align 256, !tbaa !5
  %.not = icmp ne i8 %2, 0
  %15 = load volatile i8, ptr inttoptr (i64 10486019 to ptr), align 1, !tbaa !5
  %16 = and i8 %15, -2
  %masksel = zext i1 %.not to i8
  %.sink = or disjoint i8 %16, %masksel
  store volatile i8 %.sink, 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,SimplifyCFGPass,TailCallElimPass