; LLVM IR from NaokiHori/VerySimpleNSSolver :: src/dft/dct (main)

; 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.dct_plan_t = type { i64, i64, ptr, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [18 x i8], align 1

; 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @dct_exec_f(ptr noundef %0, ptr noalias noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr null, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %2
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str) #3
  store i32 1, ptr %3, align 4
  br label %73

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.dct_plan_t, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !9
  store i64 %21, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.dct_plan_t, ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !13
  store i64 %24, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.dct_plan_t, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.dct_plan_t, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  store ptr %30, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !12
  br label %31

31:                                               ; preds = %69, %18
  %32 = load i64, ptr %10, align 8, !tbaa !12
  %33 = load i64, ptr %7, align 8, !tbaa !12
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %72

36:                                               ; preds = %31
  %37 = load i64, ptr %6, align 8, !tbaa !12
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %10, align 8, !tbaa !12
  %41 = load i64, ptr %6, align 8, !tbaa !12
  %42 = mul i64 %40, %41
  %43 = getelementptr inbounds double, ptr %39, i64 %42
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i64, ptr %10, align 8, !tbaa !12
  %46 = load i64, ptr %6, align 8, !tbaa !12
  %47 = mul i64 %45, %46
  %48 = getelementptr inbounds double, ptr %44, i64 %47
  %49 = call i32 @dct2(i64 noundef %37, i64 noundef 1, ptr noundef %38, ptr noundef %43, ptr noundef %48)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !12
  br label %50

50:                                               ; preds = %65, %36
  %51 = load i64, ptr %12, align 8, !tbaa !12
  %52 = load i64, ptr %6, align 8, !tbaa !12
  %53 = icmp ult i64 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %68

55:                                               ; preds = %50
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i64, ptr %10, align 8, !tbaa !12
  %58 = load i64, ptr %6, align 8, !tbaa !12
  %59 = mul i64 %57, %58
  %60 = load i64, ptr %12, align 8, !tbaa !12
  %61 = add i64 %59, %60
  %62 = getelementptr inbounds double, ptr %56, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !16
  %64 = fmul double %63, 2.000000e+00
  store double %64, ptr %62, align 8, !tbaa !16
  br label %65

65:                                               ; preds = %55
  %66 = load i64, ptr %12, align 8, !tbaa !12
  %67 = add i64 %66, 1
  store i64 %67, ptr %12, align 8, !tbaa !12
  br label %50, !llvm.loop !18

68:                                               ; preds = %54
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %10, align 8, !tbaa !12
  %71 = add i64 %70, 1
  store i64 %71, ptr %10, align 8, !tbaa !12
  br label %31, !llvm.loop !20

72:                                               ; preds = %35
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %73

73:                                               ; preds = %72, %15
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

; Function Attrs: nounwind uwtable
declare hidden i32 @dct2(i64 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"dct_plan_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [18 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @dct_exec_f(ptr noundef readonly %0, ptr noalias noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str) #2
  br label %.loopexit

7:                                                ; preds = %2
  %8 = load i64, ptr %0, align 8, !tbaa !9
  %.fr30 = freeze i64 %8
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %.loopexit, label %.lr.ph29

.lr.ph29:                                         ; preds = %7
  %.not31 = icmp eq i64 %.fr30, 0
  br i1 %.not31, label %.lr.ph29.split, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph29
  %min.iters.check = icmp ult i64 %.fr30, 4
  %n.vec = and i64 %.fr30, -4
  %cmp.n = icmp eq i64 %.fr30, %n.vec
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.02327.us = phi i64 [ %28, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %15 = mul i64 %.02327.us, %.fr30
  %16 = getelementptr inbounds double, ptr %1, i64 %15
  %17 = getelementptr inbounds double, ptr %14, i64 %15
  %18 = tail call i32 @dct2(i64 noundef %.fr30, i64 noundef 1, ptr noundef %12, ptr noundef %16, ptr noundef %17)
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.lr.ph.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph.us ]
  %19 = getelementptr double, ptr %16, i64 %index
  %20 = getelementptr i8, ptr %19, i64 16
  %wide.load = load <2 x double>, ptr %19, align 8, !tbaa !15
  %wide.load37 = load <2 x double>, ptr %20, align 8, !tbaa !15
  %21 = fmul <2 x double> %wide.load, <double 2.000000e+00, double 2.000000e+00>
  %22 = fmul <2 x double> %wide.load37, <double 2.000000e+00, double 2.000000e+00>
  store <2 x double> %21, ptr %19, align 8, !tbaa !15
  store <2 x double> %22, ptr %20, align 8, !tbaa !15
  %index.next = add nuw i64 %index, 4
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph.us
  %.026.us.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.026.us = phi i64 [ %27, %scalar.ph ], [ %.026.us.ph, %scalar.ph.preheader ]
  %24 = getelementptr double, ptr %16, i64 %.026.us
  %25 = load double, ptr %24, align 8, !tbaa !15
  %26 = fmul double %25, 2.000000e+00
  store double %26, ptr %24, align 8, !tbaa !15
  %27 = add nuw i64 %.026.us, 1
  %exitcond.not = icmp eq i64 %27, %.fr30
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !21

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %28 = add nuw i64 %.02327.us, 1
  %exitcond33.not = icmp eq i64 %28, %10
  br i1 %exitcond33.not, label %.loopexit, label %.lr.ph.us, !llvm.loop !22

.lr.ph29.split:                                   ; preds = %.lr.ph29, %.lr.ph29.split
  %.02327 = phi i64 [ %30, %.lr.ph29.split ], [ 0, %.lr.ph29 ]
  %29 = tail call i32 @dct2(i64 noundef 0, i64 noundef 1, ptr noundef %12, ptr noundef %1, ptr noundef %14)
  %30 = add nuw i64 %.02327, 1
  %exitcond34.not = icmp eq i64 %30, %10
  br i1 %exitcond34.not, label %.loopexit, label %.lr.ph29.split, !llvm.loop !22

.loopexit:                                        ; preds = %._crit_edge.us, %.lr.ph29.split, %7, %4
  %.024 = phi i32 [ 1, %4 ], [ 0, %7 ], [ 0, %.lr.ph29.split ], [ 0, %._crit_edge.us ]
  ret i32 %.024
}

; Function Attrs: nounwind uwtable
declare hidden i32 @dct2(i64 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { 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 = { cold 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, !11, i64 0}
!10 = !{!"dct_plan_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18, !20, !19}
!22 = distinct !{!22, !18}


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