; LLVM IR from NaokiHori/VerySimpleNSSolver :: src/dft/rdft (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.rdft_plan_t = type { i64, i64, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [47 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 uwtable
define dso_local i32 @rdft_init_plan(i64 noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %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 ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, 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
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = urem i64 %12, 2
  %14 = icmp ne i64 0, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %3
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %16)
  store i32 1, ptr %4, align 4
  br label %92

18:                                               ; preds = %3
  %19 = call ptr @memory_alloc(i64 noundef 40)
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %19, ptr %20, align 8, !tbaa !9
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.rdft_plan_t, ptr %23, i32 0, i32 0
  store i64 %21, ptr %24, align 8, !tbaa !11
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.rdft_plan_t, ptr %27, i32 0, i32 1
  store i64 %25, ptr %28, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %29 = load ptr, ptr %7, align 8, !tbaa !9
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.rdft_plan_t, ptr %30, i32 0, i32 2
  store ptr %31, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.rdft_plan_t, ptr %33, i32 0, i32 3
  store ptr %34, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.rdft_plan_t, ptr %36, i32 0, i32 4
  store ptr %37, ptr %10, align 8, !tbaa !9
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = udiv i64 %38, 2
  %40 = add i64 %39, 1
  %41 = mul i64 %40, 8
  %42 = call ptr @memory_alloc(i64 noundef %41)
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %42, ptr %43, align 8, !tbaa !9
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = udiv i64 %44, 2
  %46 = add i64 %45, 1
  %47 = mul i64 %46, 8
  %48 = call ptr @memory_alloc(i64 noundef %47)
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %48, ptr %49, align 8, !tbaa !9
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = udiv i64 %50, 2
  %52 = add i64 %51, 1
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = mul i64 %52, %53
  %55 = mul i64 %54, 16
  %56 = call ptr @memory_alloc(i64 noundef %55)
  %57 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %56, ptr %57, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %88, %18
  %59 = load i64, ptr %11, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = udiv i64 %60, 2
  %62 = add i64 %61, 1
  %63 = icmp ult i64 %59, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %91

65:                                               ; preds = %58
  %66 = load i64, ptr %11, align 8, !tbaa !5
  %67 = uitofp i64 %66 to double
  %68 = fmul double 0x401921FB54442D18, %67
  %69 = load i64, ptr %5, align 8, !tbaa !5
  %70 = uitofp i64 %69 to double
  %71 = fdiv double %68, %70
  %72 = call double @cos(double noundef %71) #4
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = load i64, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds double, ptr %74, i64 %75
  store double %72, ptr %76, align 8, !tbaa !14
  %77 = load i64, ptr %11, align 8, !tbaa !5
  %78 = uitofp i64 %77 to double
  %79 = fmul double 0x401921FB54442D18, %78
  %80 = load i64, ptr %5, align 8, !tbaa !5
  %81 = uitofp i64 %80 to double
  %82 = fdiv double %79, %81
  %83 = call double @sin(double noundef %82) #4
  %84 = load ptr, ptr %9, align 8, !tbaa !9
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = load i64, ptr %11, align 8, !tbaa !5
  %87 = getelementptr inbounds double, ptr %85, i64 %86
  store double %83, ptr %87, align 8, !tbaa !14
  br label %88

88:                                               ; preds = %65
  %89 = load i64, ptr %11, align 8, !tbaa !5
  %90 = add i64 %89, 1
  store i64 %90, ptr %11, align 8, !tbaa !5
  br label %58, !llvm.loop !16

91:                                               ; preds = %64
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %92

92:                                               ; preds = %91, %15
  %93 = load i32, ptr %4, align 4
  ret i32 %93
}

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

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

; Function Attrs: nounwind
declare double @cos(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 "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 = !{!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 = !{!"rdft_plan_t", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!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"

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @rdft_init_plan(i64 noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = and i64 %0, 1
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %7, label %5

5:                                                ; preds = %3
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %0)
  br label %.loopexit

7:                                                ; preds = %3
  %8 = tail call ptr @memory_alloc(i64 noundef 40)
  store ptr %8, ptr %2, align 8, !tbaa !5
  store i64 %0, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  store i64 %1, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %8, i64 16
  %11 = getelementptr inbounds i8, ptr %8, i64 24
  %12 = getelementptr inbounds i8, ptr %8, i64 32
  %13 = lshr exact i64 %0, 1
  %14 = add nuw i64 %13, 1
  %15 = shl i64 %14, 3
  %16 = tail call ptr @memory_alloc(i64 noundef %15)
  store ptr %16, ptr %10, align 8, !tbaa !5
  %17 = tail call ptr @memory_alloc(i64 noundef %15)
  store ptr %17, ptr %11, align 8, !tbaa !5
  %18 = shl i64 %1, 4
  %19 = mul i64 %18, %14
  %20 = tail call ptr @memory_alloc(i64 noundef %19)
  store ptr %20, ptr %12, align 8, !tbaa !5
  %21 = uitofp i64 %0 to double
  %22 = icmp eq i64 %0, 0
  br i1 %22, label %.loopexit.loopexit.unr-lcssa, label %.new

.new:                                             ; preds = %7
  %23 = add nuw i64 %13, 1
  %unroll_iter = and i64 %23, -2
  br label %24

24:                                               ; preds = %24, %.new
  %.030 = phi i64 [ 0, %.new ], [ %44, %24 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.1, %24 ]
  %25 = uitofp nneg i64 %.030 to double
  %26 = fmul double %25, 0x401921FB54442D18
  %27 = fdiv double %26, %21
  %28 = tail call double @cos(double noundef %27) #3
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i64 %.030
  store double %28, ptr %30, align 8, !tbaa !13
  %31 = tail call double @sin(double noundef %27) #3
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 %.030
  store double %31, ptr %33, align 8, !tbaa !13
  %34 = or disjoint i64 %.030, 1
  %35 = uitofp nneg i64 %34 to double
  %36 = fmul double %35, 0x401921FB54442D18
  %37 = fdiv double %36, %21
  %38 = tail call double @cos(double noundef %37) #3
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %39, i64 %34
  store double %38, ptr %40, align 8, !tbaa !13
  %41 = tail call double @sin(double noundef %37) #3
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds double, ptr %42, i64 %34
  store double %41, ptr %43, align 8, !tbaa !13
  %44 = add nuw i64 %.030, 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 %.loopexit.loopexit.unr-lcssa, label %24, !llvm.loop !15

.loopexit.loopexit.unr-lcssa:                     ; preds = %24, %7
  %.030.unr = phi i64 [ 0, %7 ], [ %44, %24 ]
  %45 = and i64 %0, 2
  %lcmp.mod.not.not = icmp eq i64 %45, 0
  br i1 %lcmp.mod.not.not, label %.loopexit.loopexit.epilog-lcssa, label %.loopexit

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %46 = uitofp nneg i64 %.030.unr to double
  %47 = fmul double %46, 0x401921FB54442D18
  %48 = fdiv double %47, %21
  %49 = tail call double @cos(double noundef %48) #3
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds double, ptr %50, i64 %.030.unr
  store double %49, ptr %51, align 8, !tbaa !13
  %52 = tail call double @sin(double noundef %48) #3
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %53, i64 %.030.unr
  store double %52, ptr %54, align 8, !tbaa !13
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %5
  %.028 = phi i32 [ 1, %5 ], [ 0, %.loopexit.loopexit.unr-lcssa ], [ 0, %.loopexit.loopexit.epilog-lcssa ]
  ret i32 %.028
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #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 = { 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 #2 = { 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 #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 = !{!"rdft_plan_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass