; 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_b(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 %81

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 = %77, %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 %80

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %10, align 8, !tbaa !12
  %39 = load i64, ptr %6, align 8, !tbaa !12
  %40 = mul i64 %38, %39
  %41 = add i64 %40, 0
  %42 = getelementptr inbounds double, ptr %37, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !16
  %44 = fmul double %43, 5.000000e-01
  store double %44, ptr %42, align 8, !tbaa !16
  %45 = load i64, ptr %6, align 8, !tbaa !12
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !12
  %49 = load i64, ptr %6, align 8, !tbaa !12
  %50 = mul i64 %48, %49
  %51 = getelementptr inbounds double, ptr %47, i64 %50
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i64, ptr %10, align 8, !tbaa !12
  %54 = load i64, ptr %6, align 8, !tbaa !12
  %55 = mul i64 %53, %54
  %56 = getelementptr inbounds double, ptr %52, i64 %55
  %57 = call i32 @dct3(i64 noundef %45, i64 noundef 1, ptr noundef %46, ptr noundef %51, ptr noundef %56)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !12
  br label %58

58:                                               ; preds = %73, %36
  %59 = load i64, ptr %12, align 8, !tbaa !12
  %60 = load i64, ptr %6, align 8, !tbaa !12
  %61 = icmp ult i64 %59, %60
  br i1 %61, label %63, label %62

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

63:                                               ; preds = %58
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i64, ptr %10, align 8, !tbaa !12
  %66 = load i64, ptr %6, align 8, !tbaa !12
  %67 = mul i64 %65, %66
  %68 = load i64, ptr %12, align 8, !tbaa !12
  %69 = add i64 %67, %68
  %70 = getelementptr inbounds double, ptr %64, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !16
  %72 = fmul double %71, 2.000000e+00
  store double %72, ptr %70, align 8, !tbaa !16
  br label %73

73:                                               ; preds = %63
  %74 = load i64, ptr %12, align 8, !tbaa !12
  %75 = add i64 %74, 1
  store i64 %75, ptr %12, align 8, !tbaa !12
  br label %58, !llvm.loop !18

76:                                               ; preds = %62
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %10, align 8, !tbaa !12
  %79 = add i64 %78, 1
  store i64 %79, ptr %10, align 8, !tbaa !12
  br label %31, !llvm.loop !20

80:                                               ; 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 %81

81:                                               ; preds = %80, %15
  %82 = load i32, ptr %3, align 4
  ret i32 %82
}

; Function Attrs: nounwind uwtable
declare hidden i32 @dct3(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_b(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
  %.fr33 = 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.ph32

.lr.ph32:                                         ; preds = %7
  %.not34 = icmp eq i64 %.fr33, 0
  br i1 %.not34, label %.lr.ph32.split, label %.lr.ph.us.preheader

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

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.02630.us = phi i64 [ %30, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %15 = mul i64 %.02630.us, %.fr33
  %16 = getelementptr inbounds double, ptr %1, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !15
  %18 = fmul double %17, 5.000000e-01
  store double %18, ptr %16, align 8, !tbaa !15
  %19 = getelementptr inbounds double, ptr %14, i64 %15
  %20 = tail call i32 @dct3(i64 noundef %.fr33, i64 noundef 1, ptr noundef %12, ptr noundef nonnull %16, ptr noundef %19)
  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 ]
  %21 = getelementptr double, ptr %16, i64 %index
  %22 = getelementptr i8, ptr %21, i64 16
  %wide.load = load <2 x double>, ptr %21, align 8, !tbaa !15
  %wide.load40 = load <2 x double>, ptr %22, align 8, !tbaa !15
  %23 = fmul <2 x double> %wide.load, <double 2.000000e+00, double 2.000000e+00>
  %24 = fmul <2 x double> %wide.load40, <double 2.000000e+00, double 2.000000e+00>
  store <2 x double> %23, ptr %21, align 8, !tbaa !15
  store <2 x double> %24, ptr %22, align 8, !tbaa !15
  %index.next = add nuw i64 %index, 4
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, 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
  %.029.us.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

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

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

.lr.ph32.split:                                   ; preds = %.lr.ph32, %.lr.ph32.split
  %.02630 = phi i64 [ %34, %.lr.ph32.split ], [ 0, %.lr.ph32 ]
  %31 = load double, ptr %1, align 8, !tbaa !15
  %32 = fmul double %31, 5.000000e-01
  store double %32, ptr %1, align 8, !tbaa !15
  %33 = tail call i32 @dct3(i64 noundef 0, i64 noundef 1, ptr noundef %12, ptr noundef nonnull %1, ptr noundef %14)
  %34 = add nuw i64 %.02630, 1
  %exitcond37.not = icmp eq i64 %34, %10
  br i1 %exitcond37.not, label %.loopexit, label %.lr.ph32.split, !llvm.loop !22

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

; Function Attrs: nounwind uwtable
declare hidden i32 @dct3(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