; LLVM IR from drohmer/cgp :: library/third_party/src/jpeg/jpgd.ll (ZN4jpgd8idct_4x4EPKsPh)

; 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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4jpgd8idct_4x4EPKsPh(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [64 x i32], align 16
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = getelementptr inbounds [64 x i32], ptr %5, i64 0, i64 0
  store ptr %10, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 4, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %23, %2
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %26

16:                                               ; preds = %12
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef %17, ptr noundef %18)
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds i16, ptr %19, i64 8
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 8
  store ptr %22, ptr %6, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %16
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !11

26:                                               ; preds = %15
  %27 = getelementptr inbounds [64 x i32], ptr %5, i64 0, i64 0
  store ptr %27, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 8, ptr %9, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %39, %26
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %42

32:                                               ; preds = %28
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef %33, ptr noundef %34)
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds i32, ptr %35, i32 1
  store ptr %36, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %4, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %32
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr %9, align 4, !tbaa !9
  br label %28, !llvm.loop !13

42:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 256, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef, ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef, ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4jpgd8idct_4x4EPKsPh(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
.preheader.preheader:
  %2 = alloca [64 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %2) #2
  call void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef nonnull %2, ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %2, i64 32
  call void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef nonnull %4, ptr noundef nonnull %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %2, i64 64
  call void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef nonnull %6, ptr noundef nonnull %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = getelementptr inbounds i8, ptr %2, i64 96
  call void @_ZN4jpgd3RowILi4EE4idctEPiPKs(ptr noundef nonnull %8, ptr noundef nonnull %7)
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef %1, ptr noundef nonnull %2)
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = getelementptr inbounds i8, ptr %1, i64 1
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %10, ptr noundef nonnull %9)
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = getelementptr inbounds i8, ptr %1, i64 2
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %12, ptr noundef nonnull %11)
  %13 = getelementptr inbounds i8, ptr %2, i64 12
  %14 = getelementptr inbounds i8, ptr %1, i64 3
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %14, ptr noundef nonnull %13)
  %15 = getelementptr inbounds i8, ptr %2, i64 16
  %16 = getelementptr inbounds i8, ptr %1, i64 4
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %16, ptr noundef nonnull %15)
  %17 = getelementptr inbounds i8, ptr %2, i64 20
  %18 = getelementptr inbounds i8, ptr %1, i64 5
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %18, ptr noundef nonnull %17)
  %19 = getelementptr inbounds i8, ptr %2, i64 24
  %20 = getelementptr inbounds i8, ptr %1, i64 6
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %20, ptr noundef nonnull %19)
  %21 = getelementptr inbounds i8, ptr %2, i64 28
  %22 = getelementptr inbounds i8, ptr %1, i64 7
  call void @_ZN4jpgd3ColILi4EE4idctEPhPKi(ptr noundef nonnull %22, ptr noundef nonnull %21)
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %2) #2
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass