; LLVM IR from Stephane-D/SGDK :: src (dma)

; 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 @VDP_setAutoInc(i8 noundef zeroext) #1

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

; Function Attrs: noinline nounwind uwtable
define dso_local void @DMA_doCPUCopyDirect(i64 noundef %0, ptr noundef %1, i16 noundef zeroext %2, i16 noundef signext %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i16, align 2
  %15 = alloca i16, align 2
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i16 %2, ptr %7, align 2, !tbaa !11
  store i16 %3, ptr %8, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %15) #3
  %16 = load i16, ptr %8, align 2, !tbaa !11
  %17 = sext i16 %16 to i32
  %18 = icmp ne i32 %17, -1
  br i1 %18, label %19, label %22

19:                                               ; preds = %4
  %20 = load i16, ptr %8, align 2, !tbaa !11
  %21 = trunc i16 %20 to i8
  call void @VDP_setAutoInc(i8 noundef zeroext %21)
  br label %22

22:                                               ; preds = %19, %4
  store ptr inttoptr (i64 12582916 to ptr), ptr %9, align 8, !tbaa !9
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !9
  store volatile i64 %23, ptr %24, align 8, !tbaa !5
  %25 = load i16, ptr %7, align 2, !tbaa !11
  %26 = zext i16 %25 to i32
  %27 = sdiv i32 %26, 16
  %28 = trunc i32 %27 to i16
  store i16 %28, ptr %14, align 2, !tbaa !11
  %29 = load i16, ptr %7, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, 15
  %32 = trunc i32 %31 to i16
  store i16 %32, ptr %15, align 2, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %33, ptr %13, align 8, !tbaa !9
  store ptr inttoptr (i64 12582912 to ptr), ptr %11, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %38, %22
  %35 = load i16, ptr %14, align 2, !tbaa !11
  %36 = add i16 %35, -1
  store i16 %36, ptr %14, align 2, !tbaa !11
  %37 = icmp ne i16 %35, 0
  br i1 %37, label %38, label %71

38:                                               ; preds = %34
  %39 = load ptr, ptr %13, align 8, !tbaa !9
  %40 = getelementptr inbounds i64, ptr %39, i32 1
  store ptr %40, ptr %13, align 8, !tbaa !9
  %41 = load i64, ptr %39, align 8, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %41, ptr %42, align 8, !tbaa !5
  %43 = load ptr, ptr %13, align 8, !tbaa !9
  %44 = getelementptr inbounds i64, ptr %43, i32 1
  store ptr %44, ptr %13, align 8, !tbaa !9
  %45 = load i64, ptr %43, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %45, ptr %46, align 8, !tbaa !5
  %47 = load ptr, ptr %13, align 8, !tbaa !9
  %48 = getelementptr inbounds i64, ptr %47, i32 1
  store ptr %48, ptr %13, align 8, !tbaa !9
  %49 = load i64, ptr %47, align 8, !tbaa !5
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %49, ptr %50, align 8, !tbaa !5
  %51 = load ptr, ptr %13, align 8, !tbaa !9
  %52 = getelementptr inbounds i64, ptr %51, i32 1
  store ptr %52, ptr %13, align 8, !tbaa !9
  %53 = load i64, ptr %51, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %53, ptr %54, align 8, !tbaa !5
  %55 = load ptr, ptr %13, align 8, !tbaa !9
  %56 = getelementptr inbounds i64, ptr %55, i32 1
  store ptr %56, ptr %13, align 8, !tbaa !9
  %57 = load i64, ptr %55, align 8, !tbaa !5
  %58 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %57, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %13, align 8, !tbaa !9
  %60 = getelementptr inbounds i64, ptr %59, i32 1
  store ptr %60, ptr %13, align 8, !tbaa !9
  %61 = load i64, ptr %59, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %61, ptr %62, align 8, !tbaa !5
  %63 = load ptr, ptr %13, align 8, !tbaa !9
  %64 = getelementptr inbounds i64, ptr %63, i32 1
  store ptr %64, ptr %13, align 8, !tbaa !9
  %65 = load i64, ptr %63, align 8, !tbaa !5
  %66 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %65, ptr %66, align 8, !tbaa !5
  %67 = load ptr, ptr %13, align 8, !tbaa !9
  %68 = getelementptr inbounds i64, ptr %67, i32 1
  store ptr %68, ptr %13, align 8, !tbaa !9
  %69 = load i64, ptr %67, align 8, !tbaa !5
  %70 = load ptr, ptr %11, align 8, !tbaa !9
  store volatile i64 %69, ptr %70, align 8, !tbaa !5
  br label %34, !llvm.loop !13

71:                                               ; preds = %34
  %72 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %72, ptr %12, align 8, !tbaa !9
  store ptr inttoptr (i64 12582912 to ptr), ptr %10, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %77, %71
  %74 = load i16, ptr %15, align 2, !tbaa !11
  %75 = add i16 %74, -1
  store i16 %75, ptr %15, align 2, !tbaa !11
  %76 = icmp ne i16 %74, 0
  br i1 %76, label %77, label %82

77:                                               ; preds = %73
  %78 = load ptr, ptr %12, align 8, !tbaa !9
  %79 = getelementptr inbounds i16, ptr %78, i32 1
  store ptr %79, ptr %12, align 8, !tbaa !9
  %80 = load i16, ptr %78, align 2, !tbaa !11
  %81 = load ptr, ptr %10, align 8, !tbaa !9
  store volatile i16 %80, ptr %81, align 2, !tbaa !11
  br label %73, !llvm.loop !15

82:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #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 = { noinline 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 @VDP_setAutoInc(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: noinline nounwind uwtable
define dso_local void @DMA_doCPUCopyDirect(i64 noundef %0, ptr nocapture noundef readonly %1, i16 noundef zeroext %2, i16 noundef signext %3) local_unnamed_addr #1 {
  %.not = icmp eq i16 %3, -1
  br i1 %.not, label %7, label %5

5:                                                ; preds = %4
  %6 = trunc i16 %3 to i8
  tail call void @VDP_setAutoInc(i8 noundef zeroext %6) #2
  br label %7

7:                                                ; preds = %5, %4
  store volatile i64 %0, ptr inttoptr (i64 12582916 to ptr), align 8, !tbaa !5
  %8 = and i16 %2, 15
  %.not3032 = icmp ult i16 %2, 16
  br i1 %.not3032, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %9 = lshr i16 %2, 4
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %7
  %.028.lcssa = phi ptr [ %1, %7 ], [ %29, %.lr.ph ]
  %.not3135 = icmp eq i16 %8, 0
  br i1 %.not3135, label %._crit_edge, label %.lr.ph38.preheader

.lr.ph38.preheader:                               ; preds = %.preheader
  %xtraiter = and i16 %2, 7
  %lcmp.mod.not = icmp eq i16 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph38.prol.loopexit, label %.lr.ph38.prol

.lr.ph38.prol:                                    ; preds = %.lr.ph38.preheader, %.lr.ph38.prol
  %.037.prol = phi i16 [ %10, %.lr.ph38.prol ], [ %8, %.lr.ph38.preheader ]
  %.02936.prol = phi ptr [ %11, %.lr.ph38.prol ], [ %.028.lcssa, %.lr.ph38.preheader ]
  %prol.iter = phi i16 [ %prol.iter.next, %.lr.ph38.prol ], [ 0, %.lr.ph38.preheader ]
  %10 = add nsw i16 %.037.prol, -1
  %11 = getelementptr inbounds i8, ptr %.02936.prol, i64 2
  %12 = load i16, ptr %.02936.prol, align 2, !tbaa !9
  store volatile i16 %12, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %prol.iter.next = add i16 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i16 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph38.prol.loopexit, label %.lr.ph38.prol, !llvm.loop !11

.lr.ph38.prol.loopexit:                           ; preds = %.lr.ph38.prol, %.lr.ph38.preheader
  %.037.unr = phi i16 [ %8, %.lr.ph38.preheader ], [ %10, %.lr.ph38.prol ]
  %.02936.unr = phi ptr [ %.028.lcssa, %.lr.ph38.preheader ], [ %11, %.lr.ph38.prol ]
  %13 = icmp ult i16 %8, 8
  br i1 %13, label %._crit_edge, label %.lr.ph38

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.02734 = phi i16 [ %14, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %.02833 = phi ptr [ %29, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %14 = add nsw i16 %.02734, -1
  %15 = getelementptr inbounds i8, ptr %.02833, i64 8
  %16 = load i64, ptr %.02833, align 8, !tbaa !5
  store volatile i64 %16, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.02833, i64 16
  %18 = load i64, ptr %15, align 8, !tbaa !5
  store volatile i64 %18, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.02833, i64 24
  %20 = load i64, ptr %17, align 8, !tbaa !5
  store volatile i64 %20, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.02833, i64 32
  %22 = load i64, ptr %19, align 8, !tbaa !5
  store volatile i64 %22, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %.02833, i64 40
  %24 = load i64, ptr %21, align 8, !tbaa !5
  store volatile i64 %24, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.02833, i64 48
  %26 = load i64, ptr %23, align 8, !tbaa !5
  store volatile i64 %26, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.02833, i64 56
  %28 = load i64, ptr %25, align 8, !tbaa !5
  store volatile i64 %28, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.02833, i64 64
  %30 = load i64, ptr %27, align 8, !tbaa !5
  store volatile i64 %30, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %.not30 = icmp eq i16 %14, 0
  br i1 %.not30, label %.preheader, label %.lr.ph, !llvm.loop !13

.lr.ph38:                                         ; preds = %.lr.ph38.prol.loopexit, %.lr.ph38
  %.037 = phi i16 [ %45, %.lr.ph38 ], [ %.037.unr, %.lr.ph38.prol.loopexit ]
  %.02936 = phi ptr [ %46, %.lr.ph38 ], [ %.02936.unr, %.lr.ph38.prol.loopexit ]
  %31 = getelementptr inbounds i8, ptr %.02936, i64 2
  %32 = load i16, ptr %.02936, align 2, !tbaa !9
  store volatile i16 %32, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %.02936, i64 4
  %34 = load i16, ptr %31, align 2, !tbaa !9
  store volatile i16 %34, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %.02936, i64 6
  %36 = load i16, ptr %33, align 2, !tbaa !9
  store volatile i16 %36, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %.02936, i64 8
  %38 = load i16, ptr %35, align 2, !tbaa !9
  store volatile i16 %38, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %.02936, i64 10
  %40 = load i16, ptr %37, align 2, !tbaa !9
  store volatile i16 %40, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %.02936, i64 12
  %42 = load i16, ptr %39, align 2, !tbaa !9
  store volatile i16 %42, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %.02936, i64 14
  %44 = load i16, ptr %41, align 2, !tbaa !9
  store volatile i16 %44, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %45 = add nsw i16 %.037, -8
  %46 = getelementptr inbounds i8, ptr %.02936, i64 16
  %47 = load i16, ptr %43, align 2, !tbaa !9
  store volatile i16 %47, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !9
  %.not31.7 = icmp eq i16 %45, 0
  br i1 %.not31.7, label %._crit_edge, label %.lr.ph38, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph38.prol.loopexit, %.lr.ph38, %.preheader
  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 = { noinline 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 = !{!"long", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass