; LLVM IR from Stephane-D/SGDK :: tools/xgmtool/src (ym2612)

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

%struct.YM2612 = type { [2 x [256 x i32]], [2 x [256 x i8]] }

; Function Attrs: nounwind uwtable
declare dso_local ptr @YM2612_create() #0

; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @YM2612_copy(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %5 = call ptr @YM2612_create()
  store ptr %5, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %66, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 256
  br i1 %8, label %9, label %69

9:                                                ; preds = %6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.YM2612, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [2 x [256 x i32]], ptr %11, i64 0, i64 0
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [256 x i32], ptr %12, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.YM2612, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds [2 x [256 x i32]], ptr %18, i64 0, i64 0
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [256 x i32], ptr %19, i64 0, i64 %21
  store i32 %16, ptr %22, align 4, !tbaa !9
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.YM2612, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [2 x [256 x i32]], ptr %24, i64 0, i64 1
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [256 x i32], ptr %25, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.YM2612, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [2 x [256 x i32]], ptr %31, i64 0, i64 1
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [256 x i32], ptr %32, i64 0, i64 %34
  store i32 %29, ptr %35, align 4, !tbaa !9
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.YM2612, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds [2 x [256 x i8]], ptr %37, i64 0, i64 0
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [256 x i8], ptr %38, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11, !range !13, !noundef !14
  %43 = trunc i8 %42 to i1
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.YM2612, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds [2 x [256 x i8]], ptr %45, i64 0, i64 0
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [256 x i8], ptr %46, i64 0, i64 %48
  %50 = zext i1 %43 to i8
  store i8 %50, ptr %49, align 1, !tbaa !11
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.YM2612, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds [2 x [256 x i8]], ptr %52, i64 0, i64 1
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [256 x i8], ptr %53, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11, !range !13, !noundef !14
  %58 = trunc i8 %57 to i1
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.YM2612, ptr %59, i32 0, i32 1
  %61 = getelementptr inbounds [2 x [256 x i8]], ptr %60, i64 0, i64 1
  %62 = load i32, ptr %4, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [256 x i8], ptr %61, i64 0, i64 %63
  %65 = zext i1 %58 to i8
  store i8 %65, ptr %64, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %9
  %67 = load i32, ptr %4, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !15

69:                                               ; preds = %6
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret ptr %70
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @YM2612_create() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @YM2612_copy(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
vector.memcheck:
  %1 = tail call ptr @YM2612_create()
  %2 = getelementptr inbounds i8, ptr %0, i64 1024
  %3 = getelementptr inbounds i8, ptr %1, i64 1024
  %4 = getelementptr inbounds i8, ptr %0, i64 2048
  %5 = getelementptr inbounds i8, ptr %1, i64 2048
  %6 = getelementptr inbounds i8, ptr %0, i64 2304
  %7 = getelementptr inbounds i8, ptr %1, i64 2304
  %scevgep = getelementptr i8, ptr %1, i64 2560
  %scevgep20 = getelementptr i8, ptr %0, i64 2560
  %bound0 = icmp ult ptr %1, %4
  %bound1 = icmp ugt ptr %5, %0
  %found.conflict = and i1 %bound0, %bound1
  %bound021 = icmp ult ptr %5, %scevgep20
  %bound122 = icmp ult ptr %4, %scevgep
  %found.conflict23 = and i1 %bound021, %bound122
  %conflict.rdx = or i1 %found.conflict, %found.conflict23
  br i1 %conflict.rdx, label %scalar.ph, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %8 = getelementptr inbounds [256 x i32], ptr %0, i64 0, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <4 x i32>, ptr %8, align 4, !tbaa !5, !alias.scope !9
  %wide.load24 = load <4 x i32>, ptr %9, align 4, !tbaa !5, !alias.scope !9
  %10 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %index
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %wide.load, ptr %10, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x i32> %wide.load24, ptr %11, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %12 = getelementptr inbounds [256 x i32], ptr %2, i64 0, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load25 = load <4 x i32>, ptr %12, align 4, !tbaa !5, !alias.scope !9
  %wide.load26 = load <4 x i32>, ptr %13, align 4, !tbaa !5, !alias.scope !9
  %14 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <4 x i32> %wide.load25, ptr %14, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x i32> %wide.load26, ptr %15, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %16 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %index
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %wide.load27 = load <4 x i8>, ptr %16, align 1, !tbaa !14, !alias.scope !16
  %wide.load28 = load <4 x i8>, ptr %17, align 1, !tbaa !14, !alias.scope !16
  %18 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  store <4 x i8> %wide.load27, ptr %18, align 1, !tbaa !14, !alias.scope !18, !noalias !16
  store <4 x i8> %wide.load28, ptr %19, align 1, !tbaa !14, !alias.scope !18, !noalias !16
  %20 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 4
  %wide.load29 = load <4 x i8>, ptr %20, align 1, !tbaa !14, !alias.scope !16
  %wide.load30 = load <4 x i8>, ptr %21, align 1, !tbaa !14, !alias.scope !16
  %22 = getelementptr inbounds [256 x i8], ptr %7, i64 0, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  store <4 x i8> %wide.load29, ptr %22, align 1, !tbaa !14, !alias.scope !18, !noalias !16
  store <4 x i8> %wide.load30, ptr %23, align 1, !tbaa !14, !alias.scope !18, !noalias !16
  %index.next = add nuw i64 %index, 8
  %24 = icmp eq i64 %index.next, 256
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !20

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ 0, %vector.memcheck ]
  %25 = getelementptr inbounds [256 x i32], ptr %0, i64 0, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %indvars.iv
  store i32 %26, ptr %27, align 4, !tbaa !5
  %28 = getelementptr inbounds [256 x i32], ptr %2, i64 0, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %indvars.iv
  store i32 %29, ptr %30, align 4, !tbaa !5
  %31 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !14, !range !24, !noundef !25
  %33 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %indvars.iv
  store i8 %32, ptr %33, align 1, !tbaa !14
  %34 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 %indvars.iv
  %35 = load i8, ptr %34, align 1, !tbaa !14, !range !24, !noundef !25
  %36 = getelementptr inbounds [256 x i8], ptr %7, i64 0, i64 %indvars.iv
  store i8 %35, ptr %36, align 1, !tbaa !14
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %37 = getelementptr inbounds [256 x i32], ptr %0, i64 0, i64 %indvars.iv.next
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %indvars.iv.next
  store i32 %38, ptr %39, align 4, !tbaa !5
  %40 = getelementptr inbounds [256 x i32], ptr %2, i64 0, i64 %indvars.iv.next
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %indvars.iv.next
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %indvars.iv.next
  %44 = load i8, ptr %43, align 1, !tbaa !14, !range !24, !noundef !25
  %45 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %indvars.iv.next
  store i8 %44, ptr %45, align 1, !tbaa !14
  %46 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 %indvars.iv.next
  %47 = load i8, ptr %46, align 1, !tbaa !14, !range !24, !noundef !25
  %48 = getelementptr inbounds [256 x i8], ptr %7, i64 0, i64 %indvars.iv.next
  store i8 %47, ptr %48, align 1, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 256
  br i1 %exitcond.not.1, label %middle.block, label %scalar.ph, !llvm.loop !26

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!17}
!17 = distinct !{!17, !11}
!18 = !{!19}
!19 = distinct !{!19, !11}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = distinct !{!26, !21, !22}


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