; LLVM IR from jgaeddert/liquid-dsp :: src/framing/src (framesync64)

; 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.framesync64_s = type { ptr, ptr, %struct.framesyncstats_s, %struct.framedatastats_s, i32, float, ptr, [64 x { float, float }], [64 x { float, float }], [600 x { float, float }], [72 x i8], ptr, ptr, i32, ptr, ptr, ptr, i32 }
%struct.framesyncstats_s = type { float, float, float, ptr, i32, i32, i32, i32, i32, i32 }
%struct.framedatastats_s = type { i32, i32, i32, i64 }

@.str.1 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [70 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: nounwind uwtable
define dso_local i32 @framesync64_set_prefix(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %51

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call i64 @strlen(ptr noundef %12) #7
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp ugt i32 %15, 16384
  br i1 %16, label %17, label %19

17:                                               ; preds = %11
  %18 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str.1, i32 noundef 329, ptr noundef @.str.6)
  store i32 %18, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

19:                                               ; preds = %11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.framesync64_s, ptr %20, i32 0, i32 15
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add i32 %23, 1
  %25 = zext i32 %24 to i64
  %26 = call ptr @realloc(ptr noundef %22, i64 noundef %25) #8
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.framesync64_s, ptr %27, i32 0, i32 15
  store ptr %26, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.framesync64_s, ptr %29, i32 0, i32 16
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = add i32 %32, 15
  %34 = zext i32 %33 to i64
  %35 = call ptr @realloc(ptr noundef %31, i64 noundef %34) #8
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.framesync64_s, ptr %36, i32 0, i32 16
  store ptr %35, ptr %37, align 8, !tbaa !17
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.framesync64_s, ptr %38, i32 0, i32 15
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %40, ptr align 1 %41, i64 %43, i1 false)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.framesync64_s, ptr %44, i32 0, i32 15
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  store i8 0, ptr %49, align 1, !tbaa !18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

50:                                               ; preds = %19, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %51

51:                                               ; preds = %50, %10
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

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

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

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

!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, !6, i64 6032}
!12 = !{!"framesync64_s", !6, i64 0, !6, i64 8, !13, i64 16, !15, i64 64, !10, i64 88, !14, i64 92, !6, i64 96, !7, i64 104, !7, i64 616, !7, i64 1128, !7, i64 5928, !6, i64 6000, !6, i64 6008, !10, i64 6016, !6, i64 6024, !6, i64 6032, !6, i64 6040, !10, i64 6048}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!14 = !{!"float", !7, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !16, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !6, i64 6040}
!18 = !{!7, !7, i64 0}


; 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 [84 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [70 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @framesync64_set_prefix(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %25, label %4

4:                                                ; preds = %2
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %6 = trunc i64 %5 to i32
  %7 = icmp ugt i32 %6, 16384
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str.1, i32 noundef 329, ptr noundef nonnull @.str.6) #6
  br label %25

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 6032
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = add nuw nsw i64 %5, 1
  %14 = and i64 %13, 65535
  %15 = tail call ptr @realloc(ptr noundef %12, i64 noundef %14) #7
  store ptr %15, ptr %11, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 6040
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = add nuw nsw i64 %5, 15
  %19 = and i64 %18, 65535
  %20 = tail call ptr @realloc(ptr noundef %17, i64 noundef %19) #7
  store ptr %20, ptr %16, align 8, !tbaa !15
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = and i64 %5, 32767
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %21, ptr nonnull align 1 %1, i64 %22, i1 false)
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 %22
  store i8 0, ptr %24, align 1, !tbaa !16
  br label %25

25:                                               ; preds = %8, %10, %2
  %.1 = phi i32 [ 0, %2 ], [ %9, %8 ], [ 0, %10 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #4

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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #7 = { nounwind allocsize(1) }

!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 6032}
!6 = !{!"framesync64_s", !7, i64 0, !7, i64 8, !10, i64 16, !13, i64 64, !12, i64 88, !11, i64 92, !7, i64 96, !8, i64 104, !8, i64 616, !8, i64 1128, !8, i64 5928, !7, i64 6000, !7, i64 6008, !12, i64 6016, !7, i64 6024, !7, i64 6032, !7, i64 6040, !12, i64 6048}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!11 = !{!"float", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !14, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !7, i64 6040}
!16 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass