; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/modules/juce_graphics/image_formats/jpglib (jutils)

; 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: nounwind uwtable
define dso_local void @jcopy_sample_rows(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %17 = load i32, ptr %12, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = mul i64 %18, 1
  store i64 %19, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds ptr, ptr %21, i64 %22
  store ptr %23, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  store ptr %27, ptr %9, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %28, ptr %16, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %42, %6
  %30 = load i32, ptr %16, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %32, label %45

32:                                               ; preds = %29
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds ptr, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %35, ptr %13, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds ptr, ptr %36, i32 1
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %38, ptr %14, align 8, !tbaa !5
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = load i64, ptr %15, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 1 %40, i64 %41, i1 false)
  br label %42

42:                                               ; preds = %32
  %43 = load i32, ptr %16, align 4, !tbaa !9
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %16, align 4, !tbaa !9
  br label %29, !llvm.loop !13

45:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret void
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree 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 = !{!"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 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @jcopy_sample_rows(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = zext i32 %5 to i64
  %8 = icmp sgt i32 %4, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %9 = sext i32 %3 to i64
  %10 = getelementptr inbounds ptr, ptr %2, i64 %9
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds ptr, ptr %0, i64 %11
  %xtraiter = and i32 %4, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load ptr, ptr %12, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %10, i64 8
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr align 1 %14, i64 %7, i1 false)
  %17 = add nsw i32 %4, -1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.016.unr = phi i32 [ %4, %.lr.ph.preheader ], [ %17, %.lr.ph.prol ]
  %.01215.unr = phi ptr [ %12, %.lr.ph.preheader ], [ %13, %.lr.ph.prol ]
  %.01314.unr = phi ptr [ %10, %.lr.ph.preheader ], [ %15, %.lr.ph.prol ]
  %18 = icmp eq i32 %4, 1
  br i1 %18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.016 = phi i32 [ %27, %.lr.ph ], [ %.016.unr, %.lr.ph.prol.loopexit ]
  %.01215 = phi ptr [ %23, %.lr.ph ], [ %.01215.unr, %.lr.ph.prol.loopexit ]
  %.01314 = phi ptr [ %25, %.lr.ph ], [ %.01314.unr, %.lr.ph.prol.loopexit ]
  %19 = getelementptr inbounds i8, ptr %.01215, i64 8
  %20 = load ptr, ptr %.01215, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.01314, i64 8
  %22 = load ptr, ptr %.01314, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr align 1 %20, i64 %7, i1 false)
  %23 = getelementptr inbounds i8, ptr %.01215, i64 16
  %24 = load ptr, ptr %19, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.01314, i64 16
  %26 = load ptr, ptr %21, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %26, ptr align 1 %24, i64 %7, i1 false)
  %27 = add nsw i32 %.016, -2
  %28 = add i32 %.016, -3
  %29 = icmp ult i32 %28, -2
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %6
  ret void
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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: readwrite) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass