; LLVM IR from jgaeddert/liquid-dsp :: examples (flexframesync_debug_example)

; 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.flexframegenprops_s = type { i32, i32, i32, i32 }
%struct.framesyncstats_s = type { float, float, float, ptr, i32, i32, i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %struct.flexframegenprops_s, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 40, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 6, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 480, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr @.str, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %19 = call i32 @flexframegenprops_init_default(ptr noundef %12)
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = getelementptr inbounds %struct.flexframegenprops_s, ptr %12, i32 0, i32 3
  store i32 %20, ptr %21, align 4, !tbaa !11
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = getelementptr inbounds %struct.flexframegenprops_s, ptr %12, i32 0, i32 0
  store i32 %22, ptr %23, align 4, !tbaa !13
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = getelementptr inbounds %struct.flexframegenprops_s, ptr %12, i32 0, i32 1
  store i32 %24, ptr %25, align 4, !tbaa !14
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = getelementptr inbounds %struct.flexframegenprops_s, ptr %12, i32 0, i32 2
  store i32 %26, ptr %27, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %28 = call ptr @flexframegen_create(ptr noundef %12)
  store ptr %28, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %29 = load ptr, ptr %11, align 8, !tbaa !9
  %30 = call ptr @flexframesync_create(ptr noundef @callback, ptr noundef %29)
  store ptr %30, ptr %14, align 8, !tbaa !9
  %31 = load ptr, ptr %13, align 8, !tbaa !9
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = call i32 @flexframegen_assemble(ptr noundef %31, ptr noundef null, ptr noundef null, i32 noundef %32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 256, ptr %15, align 4, !tbaa !5
  %34 = load i32, ptr %15, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = call ptr @llvm.stacksave.p0()
  store ptr %36, ptr %16, align 8
  %37 = alloca { float, float }, i64 %35, align 16
  store i64 %35, ptr %17, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %42, %2
  %39 = load i32, ptr %18, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  %41 = xor i1 %40, true
  br i1 %41, label %42, label %49

42:                                               ; preds = %38
  %43 = load ptr, ptr %13, align 8, !tbaa !9
  %44 = load i32, ptr %15, align 4, !tbaa !5
  %45 = call i32 @flexframegen_write_samples(ptr noundef %43, ptr noundef %37, i32 noundef %44)
  store i32 %45, ptr %18, align 4, !tbaa !5
  %46 = load ptr, ptr %14, align 8, !tbaa !9
  %47 = load i32, ptr %15, align 4, !tbaa !5
  %48 = call i32 @flexframesync_execute(ptr noundef %46, ptr noundef %37, i32 noundef %47)
  br label %38, !llvm.loop !16

49:                                               ; preds = %38
  %50 = load ptr, ptr %13, align 8, !tbaa !9
  %51 = call i32 @flexframegen_destroy(ptr noundef %50)
  %52 = load ptr, ptr %14, align 8, !tbaa !9
  %53 = call i32 @flexframesync_destroy(ptr noundef %52)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  %54 = load ptr, ptr %16, align 8
  call void @llvm.stackrestore.p0(ptr %54)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

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

declare i32 @flexframegenprops_init_default(ptr noundef) #2

declare ptr @flexframegen_create(ptr noundef) #2

declare ptr @flexframesync_create(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @callback(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.framesyncstats_s) align 8, ptr noundef) #0

declare i32 @flexframegen_assemble(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

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

declare i32 @flexframegen_write_samples(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @flexframesync_execute(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @flexframegen_destroy(ptr noundef) #2

declare i32 @flexframesync_destroy(ptr noundef) #2

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

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn }
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 = !{!"int", !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 12}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !6, i64 8}
!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"

%struct.flexframegenprops_s = type { i32, i32, i32, i32 }
%struct.framesyncstats_s = type { float, float, float, ptr, i32, i32, i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.flexframegenprops_s, align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %4 = call i32 @flexframegenprops_init_default(ptr noundef nonnull %3) #4
  store <4 x i32> <i32 6, i32 1, i32 1, i32 40>, ptr %3, align 16, !tbaa !5
  %5 = call ptr @flexframegen_create(ptr noundef nonnull %3) #4
  %6 = call ptr @flexframesync_create(ptr noundef nonnull @callback, ptr noundef nonnull @.str) #4
  %7 = call i32 @flexframegen_assemble(ptr noundef %5, ptr noundef null, ptr noundef null, i32 noundef 480) #4
  %8 = call ptr @llvm.stacksave.p0()
  %9 = alloca [256 x { float, float }], align 16
  br label %10

10:                                               ; preds = %2, %10
  %11 = call i32 @flexframegen_write_samples(ptr noundef %5, ptr noundef nonnull %9, i32 noundef 256) #4
  %12 = call i32 @flexframesync_execute(ptr noundef %6, ptr noundef nonnull %9, i32 noundef 256) #4
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %10, label %13, !llvm.loop !9

13:                                               ; preds = %10
  %14 = call i32 @flexframegen_destroy(ptr noundef %5) #4
  %15 = call i32 @flexframesync_destroy(ptr noundef %6) #4
  call void @llvm.stackrestore.p0(ptr %8)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret i32 0
}

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

declare i32 @flexframegenprops_init_default(ptr noundef) local_unnamed_addr #2

declare ptr @flexframegen_create(ptr noundef) local_unnamed_addr #2

declare ptr @flexframesync_create(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @callback(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.framesyncstats_s) align 8, ptr noundef) #0

declare i32 @flexframegen_assemble(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

declare i32 @flexframegen_write_samples(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @flexframesync_execute(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @flexframegen_destroy(ptr noundef) local_unnamed_addr #2

declare i32 @flexframesync_destroy(ptr noundef) local_unnamed_addr #2

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

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass