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

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

18:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %74

19:                                               ; preds = %3
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.dct_plan_t, ptr %22, i32 0, i32 0
  store i64 %20, ptr %23, align 8, !tbaa !11
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.dct_plan_t, ptr %26, i32 0, i32 1
  store i64 %24, ptr %27, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.dct_plan_t, ptr %29, i32 0, i32 2
  store ptr %30, ptr %8, align 8, !tbaa !9
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = mul i64 %31, 8
  %33 = call ptr @memory_alloc(i64 noundef %32)
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %33, ptr %34, align 8, !tbaa !9
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = icmp eq ptr null, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %19
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %73

39:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %60, %39
  %41 = load i64, ptr %10, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %63

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %46 = load i64, ptr %10, align 8, !tbaa !5
  %47 = uitofp i64 %46 to double
  %48 = fmul double 0x400921FB54442D18, %47
  %49 = load i64, ptr %5, align 8, !tbaa !5
  %50 = uitofp i64 %49 to double
  %51 = fmul double 2.000000e+00, %50
  %52 = fdiv double %48, %51
  store double %52, ptr %11, align 8, !tbaa !14
  %53 = load double, ptr %11, align 8, !tbaa !14
  %54 = call double @cos(double noundef %53) #3
  %55 = fdiv double 5.000000e-01, %54
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = load i64, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds double, ptr %57, i64 %58
  store double %55, ptr %59, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %60

60:                                               ; preds = %45
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = add i64 %61, 1
  store i64 %62, ptr %10, align 8, !tbaa !5
  br label %40, !llvm.loop !16

63:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.dct_plan_t, ptr %65, i32 0, i32 3
  store ptr %66, ptr %12, align 8, !tbaa !9
  %67 = load i64, ptr %5, align 8, !tbaa !5
  %68 = load i64, ptr %6, align 8, !tbaa !5
  %69 = mul i64 %67, %68
  %70 = mul i64 %69, 8
  %71 = call ptr @memory_alloc(i64 noundef %70)
  %72 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %71, ptr %72, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %73

73:                                               ; preds = %63, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %74

74:                                               ; preds = %73, %18
  %75 = load i32, ptr %4, align 4
  ret i32 %75
}

; Function Attrs: nounwind uwtable
declare hidden ptr @memory_alloc(i64 noundef) #0

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

; Function Attrs: nounwind
declare double @cos(double noundef) #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 = { 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 = { 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, !6, i64 0}
!12 = !{!"dct_plan_t", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @dct_init_plan(i64 noundef %0, i64 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @memory_alloc(i64 noundef 32)
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %43, label %6

6:                                                ; preds = %3
  store i64 %0, ptr %4, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %1, ptr %7, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  %9 = shl i64 %0, 3
  %10 = tail call ptr @memory_alloc(i64 noundef %9)
  store ptr %10, ptr %8, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %43, label %.preheader

.preheader:                                       ; preds = %6
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = uitofp i64 %0 to double
  %13 = fmul double %12, 2.000000e+00
  %xtraiter = and i64 %0, 1
  %14 = icmp eq i64 %0, 1
  br i1 %14, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %0, -2
  br label %26

._crit_edge.loopexit.unr-lcssa:                   ; preds = %26, %.lr.ph
  %.02226.unr = phi i64 [ 0, %.lr.ph ], [ %42, %26 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %15 = uitofp i64 %.02226.unr to double
  %16 = fmul double %15, 0x400921FB54442D18
  %17 = fdiv double %16, %13
  %18 = tail call double @cos(double noundef %17) #2
  %19 = fdiv double 5.000000e-01, %18
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i64 %.02226.unr
  store double %19, ptr %21, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 24
  %24 = mul i64 %9, %1
  %25 = tail call ptr @memory_alloc(i64 noundef %24)
  store ptr %25, ptr %23, align 8, !tbaa !5
  br label %43

26:                                               ; preds = %26, %.lr.ph.new
  %.02226 = phi i64 [ 0, %.lr.ph.new ], [ %42, %26 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %26 ]
  %27 = uitofp i64 %.02226 to double
  %28 = fmul double %27, 0x400921FB54442D18
  %29 = fdiv double %28, %13
  %30 = tail call double @cos(double noundef %29) #2
  %31 = fdiv double 5.000000e-01, %30
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 %.02226
  store double %31, ptr %33, align 8, !tbaa !13
  %34 = or disjoint i64 %.02226, 1
  %35 = uitofp i64 %34 to double
  %36 = fmul double %35, 0x400921FB54442D18
  %37 = fdiv double %36, %13
  %38 = tail call double @cos(double noundef %37) #2
  %39 = fdiv double 5.000000e-01, %38
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds double, ptr %40, i64 %34
  store double %39, ptr %41, align 8, !tbaa !13
  %42 = add nuw i64 %.02226, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %26, !llvm.loop !15

43:                                               ; preds = %._crit_edge, %6, %3
  %.1 = phi i32 [ 1, %3 ], [ 0, %._crit_edge ], [ 1, %6 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden ptr @memory_alloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!"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 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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