; LLVM IR from robertklee/C-Optimization-DCT :: src (dct)

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

@.str = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @run_dct(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca [8 x [8 x i8]], align 16
  %16 = alloca [8 x [8 x i16]], align 16
  %17 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = sdiv i64 %18, 8
  store i64 %19, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = sdiv i64 %20, 8
  store i64 %21, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %97, %4
  %23 = load i32, ptr %11, align 4, !tbaa !11
  %24 = sext i32 %23 to i64
  %25 = load i64, ptr %10, align 8, !tbaa !9
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %27, label %100

27:                                               ; preds = %22
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %93, %27
  %29 = load i32, ptr %12, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %33, label %96

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 64, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %16) #3
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %71, %33
  %35 = load i32, ptr %13, align 4, !tbaa !11
  %36 = icmp slt i32 %35, 8
  br i1 %36, label %37, label %74

37:                                               ; preds = %34
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %67, %37
  %39 = load i32, ptr %14, align 4, !tbaa !11
  %40 = icmp slt i32 %39, 8
  br i1 %40, label %41, label %70

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = mul nsw i32 %42, 8
  %44 = load i32, ptr %13, align 4, !tbaa !11
  %45 = add nsw i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = mul nsw i64 %46, %47
  %49 = load i32, ptr %12, align 4, !tbaa !11
  %50 = mul nsw i32 %49, 8
  %51 = load i32, ptr %14, align 4, !tbaa !11
  %52 = add nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = add nsw i64 %48, %53
  %55 = trunc i64 %54 to i32
  store i32 %55, ptr %17, align 4, !tbaa !11
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i32, ptr %17, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !13
  %61 = load i32, ptr %13, align 4, !tbaa !11
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [8 x [8 x i8]], ptr %15, i64 0, i64 %62
  %64 = load i32, ptr %14, align 4, !tbaa !11
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [8 x i8], ptr %63, i64 0, i64 %65
  store i8 %60, ptr %66, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %67

67:                                               ; preds = %41
  %68 = load i32, ptr %14, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %14, align 4, !tbaa !11
  br label %38, !llvm.loop !14

70:                                               ; preds = %38
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %13, align 4, !tbaa !11
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %13, align 4, !tbaa !11
  br label %34, !llvm.loop !16

74:                                               ; preds = %34
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds [8 x [8 x i8]], ptr %15, i64 0, i64 0
  %77 = getelementptr inbounds [8 x [8 x i16]], ptr %16, i64 0, i64 0
  call void %75(ptr noundef %76, ptr noundef %77)
  %78 = load i32, ptr %11, align 4, !tbaa !11
  %79 = load i32, ptr %12, align 4, !tbaa !11
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %78, i32 noundef %79)
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %89, %74
  %82 = load i32, ptr %13, align 4, !tbaa !11
  %83 = icmp slt i32 %82, 8
  br i1 %83, label %84, label %92

84:                                               ; preds = %81
  %85 = load i32, ptr %13, align 4, !tbaa !11
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [8 x [8 x i16]], ptr %16, i64 0, i64 %86
  %88 = getelementptr inbounds [8 x i16], ptr %87, i64 0, i64 0
  call void @print_line(ptr noundef %88, i32 noundef 1)
  br label %89

89:                                               ; preds = %84
  %90 = load i32, ptr %13, align 4, !tbaa !11
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %13, align 4, !tbaa !11
  br label %81, !llvm.loop !17

92:                                               ; preds = %81
  call void @llvm.lifetime.end.p0(i64 128, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %15) #3
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %12, align 4, !tbaa !11
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %12, align 4, !tbaa !11
  br label %28, !llvm.loop !18

96:                                               ; preds = %28
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %11, align 4, !tbaa !11
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %11, align 4, !tbaa !11
  br label %22, !llvm.loop !19

100:                                              ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
}

; 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

declare i32 @printf(ptr noundef, ...) #2

declare void @print_line(ptr noundef, i32 noundef) #2

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 = { "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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}
!19 = distinct !{!19, !15}


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

@.str = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @run_dct(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = alloca [8 x [8 x i8]], align 16
  %6 = alloca [8 x [8 x i16]], align 16
  %7 = sdiv i64 %1, 8
  %8 = sdiv i64 %2, 8
  %9 = icmp sgt i64 %2, 7
  br i1 %9, label %.preheader29.lr.ph, label %._crit_edge35

.preheader29.lr.ph:                               ; preds = %4
  %10 = icmp sgt i64 %1, 7
  %11 = trunc i64 %1 to i32
  br i1 %10, label %.preheader29.us.preheader, label %._crit_edge35

.preheader29.us.preheader:                        ; preds = %.preheader29.lr.ph
  %12 = getelementptr inbounds i8, ptr %6, i64 16
  %13 = getelementptr inbounds i8, ptr %6, i64 32
  %14 = getelementptr inbounds i8, ptr %6, i64 48
  %15 = getelementptr inbounds i8, ptr %6, i64 64
  %16 = getelementptr inbounds i8, ptr %6, i64 80
  %17 = getelementptr inbounds i8, ptr %6, i64 96
  %18 = getelementptr inbounds i8, ptr %6, i64 112
  br label %.preheader29.us

.preheader29.us:                                  ; preds = %.preheader29.us.preheader, %._crit_edge.us
  %indvars.iv48 = phi i64 [ 0, %.preheader29.us.preheader ], [ %indvars.iv.next49, %._crit_edge.us ]
  %19 = shl nsw i64 %indvars.iv48, 3
  %20 = trunc nuw nsw i64 %indvars.iv48 to i32
  br label %21

21:                                               ; preds = %.preheader29.us, %23
  %indvars.iv44 = phi i64 [ 0, %.preheader29.us ], [ %indvars.iv.next45, %23 ]
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #4
  %indvars.iv44.tr = trunc i64 %indvars.iv44 to i32
  %22 = shl i32 %indvars.iv44.tr, 3
  br label %.preheader.us

23:                                               ; preds = %.preheader.us
  call void %3(ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %24 = trunc nuw nsw i64 %indvars.iv44 to i32
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %20, i32 noundef %24)
  call void @print_line(ptr noundef nonnull %6, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %12, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %13, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %14, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %15, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %16, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %17, i32 noundef 1) #4
  call void @print_line(ptr noundef nonnull %18, i32 noundef 1) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #4
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next45, %7
  br i1 %exitcond47.not, label %._crit_edge.us, label %21, !llvm.loop !5

.preheader.us:                                    ; preds = %.preheader.us, %21
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader.us ], [ 0, %21 ]
  %26 = add nuw nsw i64 %indvars.iv, %19
  %27 = trunc nuw nsw i64 %26 to i32
  %28 = mul i32 %27, %11
  %29 = add i32 %28, %22
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !7
  %33 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 0
  store i8 %32, ptr %33, align 8, !tbaa !7
  %34 = add i32 %29, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !7
  %38 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 1
  store i8 %37, ptr %38, align 1, !tbaa !7
  %39 = add i32 %29, 2
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !7
  %43 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 2
  store i8 %42, ptr %43, align 2, !tbaa !7
  %44 = add i32 %29, 3
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !7
  %48 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 3
  store i8 %47, ptr %48, align 1, !tbaa !7
  %49 = add i32 %29, 4
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !7
  %53 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 4
  store i8 %52, ptr %53, align 4, !tbaa !7
  %54 = add i32 %29, 5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !7
  %58 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 5
  store i8 %57, ptr %58, align 1, !tbaa !7
  %59 = add i32 %29, 6
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !7
  %63 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 6
  store i8 %62, ptr %63, align 2, !tbaa !7
  %64 = add i32 %29, 7
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %0, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !7
  %68 = getelementptr inbounds [8 x [8 x i8]], ptr %5, i64 0, i64 %indvars.iv, i64 7
  store i8 %67, ptr %68, align 1, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 8
  br i1 %exitcond.not, label %23, label %.preheader.us, !llvm.loop !10

._crit_edge.us:                                   ; preds = %23
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next49, %8
  br i1 %exitcond51.not, label %._crit_edge35, label %.preheader29.us, !llvm.loop !11

._crit_edge35:                                    ; preds = %._crit_edge.us, %.preheader29.lr.ph, %4
  ret void
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @print_line(ptr noundef, i32 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 = { "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 #4 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !6}
!11 = distinct !{!11, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass