; LLVM IR from jgaeddert/liquid-dsp :: src/fft/src (spgramcf)

; 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.spwaterfallcf_s = type { i32, i32, ptr, ptr, i32, i32, float, float, i32, i32, ptr }

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.58 = external hidden unnamed_addr constant [60 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

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @spgramcf_get_num_samples_total(ptr noundef) #3

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @spwaterfallcf_export_bin(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca i64, align 8
  %15 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i64 @strlen(ptr noundef %16) #7
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = add nsw i32 %19, 5
  %21 = zext i32 %20 to i64
  %22 = call ptr @llvm.stacksave.p0()
  store ptr %22, ptr %7, align 8
  %23 = alloca i8, i64 %21, align 16
  store i64 %21, ptr %8, align 8
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %23, ptr noundef @.str.57, ptr noundef %24) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %26 = call noalias ptr @fopen(ptr noundef %23, ptr noundef @.str.20)
  store ptr %26, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %31

29:                                               ; preds = %2
  %30 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str.40, i32 noundef 409, ptr noundef @.str.58, ptr noundef @.str.2, ptr noundef %23)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %101

31:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = uitofp i32 %34 to float
  store float %35, ptr %12, align 4, !tbaa !14
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call i64 @fwrite(ptr noundef %12, i64 noundef 4, i64 noundef 1, ptr noundef %36)
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %52, %31
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = icmp ult i32 %39, %42
  br i1 %43, label %44, label %55

44:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = uitofp i32 %45 to float
  %47 = load float, ptr %12, align 4, !tbaa !14
  %48 = fdiv float %46, %47
  %49 = fsub float %48, 5.000000e-01
  store float %49, ptr %13, align 4, !tbaa !14
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = call i64 @fwrite(ptr noundef %13, i64 noundef 4, i64 noundef 1, ptr noundef %50)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %52

52:                                               ; preds = %44
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %11, align 4, !tbaa !9
  br label %38, !llvm.loop !15

55:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = call i64 @spgramcf_get_num_samples_total(ptr noundef %58)
  store i64 %59, ptr %14, align 8, !tbaa !18
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %95, %55
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %62, i32 0, i32 4
  %64 = load i32, ptr %63, align 8, !tbaa !20
  %65 = icmp ult i32 %61, %64
  br i1 %65, label %66, label %98

66:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = uitofp i32 %67 to float
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %69, i32 0, i32 4
  %71 = load i32, ptr %70, align 8, !tbaa !20
  %72 = uitofp i32 %71 to float
  %73 = fdiv float %68, %72
  %74 = load i64, ptr %14, align 8, !tbaa !18
  %75 = uitofp i64 %74 to float
  %76 = fmul float %73, %75
  store float %76, ptr %15, align 4, !tbaa !14
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = call i64 @fwrite(ptr noundef %15, i64 noundef 4, i64 noundef 1, ptr noundef %77)
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !21
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 8, !tbaa !11
  %86 = mul i32 %82, %85
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds float, ptr %81, i64 %87
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.spwaterfallcf_s, ptr %89, i32 0, i32 0
  %91 = load i32, ptr %90, align 8, !tbaa !11
  %92 = zext i32 %91 to i64
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = call i64 @fwrite(ptr noundef %88, i64 noundef 4, i64 noundef %92, ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  br label %95

95:                                               ; preds = %66
  %96 = load i32, ptr %11, align 4, !tbaa !9
  %97 = add i32 %96, 1
  store i32 %97, ptr %11, align 4, !tbaa !9
  br label %60, !llvm.loop !22

98:                                               ; preds = %60
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = call i32 @fclose(ptr noundef %99)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %101

101:                                              ; preds = %98, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  %102 = load ptr, ptr %7, align 8
  call void @llvm.stackrestore.p0(ptr %102)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %103 = load i32, ptr %3, align 4
  ret i32 %103
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #5

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { nounwind willreturn memory(read) "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"spwaterfallcf_s", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !13, i64 32, !13, i64 36, !10, i64 40, !10, i64 44, !6, i64 48}
!13 = !{!"float", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!12, !10, i64 24}
!21 = !{!12, !6, i64 16}
!22 = distinct !{!22, !16}


; 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.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.58 = external hidden unnamed_addr constant [60 x i8], align 1

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

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

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @spgramcf_get_num_samples_total(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @spwaterfallcf_export_bin(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %7 = add i64 %6, 5
  %8 = and i64 %7, 4294967295
  %9 = alloca i8, i64 %8, align 16
  %10 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) @.str.57, ptr noundef %1) #6
  %11 = call noalias ptr @fopen(ptr noundef nonnull %9, ptr noundef nonnull @.str.20)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str.40, i32 noundef 409, ptr noundef nonnull @.str.58, ptr noundef nonnull @.str.2, ptr noundef nonnull %9) #6
  br label %54

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %16 = load i32, ptr %0, align 8, !tbaa !5
  %17 = uitofp i32 %16 to float
  store float %17, ptr %3, align 4, !tbaa !12
  %18 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %11)
  %19 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %20 = load float, ptr %3, align 4, !tbaa !12
  br label %21

21:                                               ; preds = %.lr.ph, %21
  %.02628 = phi i32 [ 0, %.lr.ph ], [ %26, %21 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  %22 = uitofp i32 %.02628 to float
  %23 = fdiv float %22, %20
  %24 = fadd float %23, -5.000000e-01
  store float %24, ptr %4, align 4, !tbaa !12
  %25 = call i64 @fwrite(ptr noundef nonnull %4, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  %26 = add nuw i32 %.02628, 1
  %27 = load i32, ptr %0, align 8, !tbaa !5
  %28 = icmp ult i32 %26, %27
  br i1 %28, label %21, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %21, %15
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = tail call i64 @spgramcf_get_num_samples_total(ptr noundef %30)
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %.not33 = icmp eq i32 %33, 0
  br i1 %.not33, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %._crit_edge
  %34 = uitofp i64 %31 to float
  %35 = getelementptr inbounds i8, ptr %0, i64 16
  br label %36

36:                                               ; preds = %.lr.ph31, %36
  %37 = phi i32 [ %33, %.lr.ph31 ], [ %51, %36 ]
  %.129 = phi i32 [ 0, %.lr.ph31 ], [ %50, %36 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  %38 = uitofp i32 %.129 to float
  %39 = uitofp i32 %37 to float
  %40 = fdiv float %38, %39
  %41 = fmul float %40, %34
  store float %41, ptr %5, align 4, !tbaa !12
  %42 = call i64 @fwrite(ptr noundef nonnull %5, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %11)
  %43 = load ptr, ptr %35, align 8, !tbaa !17
  %44 = load i32, ptr %0, align 8, !tbaa !5
  %45 = mul i32 %44, %.129
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %43, i64 %46
  %48 = zext i32 %44 to i64
  %49 = tail call i64 @fwrite(ptr noundef %47, i64 noundef 4, i64 noundef %48, ptr noundef nonnull %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  %50 = add nuw i32 %.129, 1
  %51 = load i32, ptr %32, align 8, !tbaa !16
  %52 = icmp ult i32 %50, %51
  br i1 %52, label %36, label %._crit_edge32, !llvm.loop !18

._crit_edge32:                                    ; preds = %36, %._crit_edge
  %53 = tail call i32 @fclose(ptr noundef nonnull %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  br label %54

54:                                               ; preds = %._crit_edge32, %13
  %.0 = phi i32 [ -1, %13 ], [ 0, %._crit_edge32 ]
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"spwaterfallcf_s", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !7, i64 44, !10, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 24}
!17 = !{!6, !10, i64 16}
!18 = distinct !{!18, !14}


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