; LLVM IR from jgaeddert/liquid-dsp :: src/buffer/src (buffercf)

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

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [64 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @windowcf_create(i32 noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %1
  %8 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef @.str.8, i32 noundef 49, ptr noundef @.str.9, ptr noundef @.str.2)
  store ptr %8, ptr %2, align 8
  br label %53

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %10, ptr %4, align 8, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.windowcf_s, ptr %12, i32 0, i32 1
  store i32 %11, ptr %13, align 8, !tbaa !11
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = call i32 @liquid_msb_index(i32 noundef %14)
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.windowcf_s, ptr %16, i32 0, i32 2
  store i32 %15, ptr %17, align 4, !tbaa !13
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.windowcf_s, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = shl i32 1, %20
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.windowcf_s, ptr %22, i32 0, i32 3
  store i32 %21, ptr %23, align 8, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.windowcf_s, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !14
  %27 = sub i32 %26, 1
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.windowcf_s, ptr %28, i32 0, i32 4
  store i32 %27, ptr %29, align 4, !tbaa !15
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.windowcf_s, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.windowcf_s, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = add i32 %32, %35
  %37 = sub i32 %36, 1
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.windowcf_s, ptr %38, i32 0, i32 5
  store i32 %37, ptr %39, align 8, !tbaa !16
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.windowcf_s, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = zext i32 %42 to i64
  %44 = mul i64 %43, 8
  %45 = call noalias ptr @malloc(i64 noundef %44) #5
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.windowcf_s, ptr %46, i32 0, i32 0
  store ptr %45, ptr %47, align 8, !tbaa !17
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.windowcf_s, ptr %48, i32 0, i32 6
  store i32 0, ptr %49, align 4, !tbaa !18
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = call i32 @windowcf_reset(ptr noundef %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %52, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %53

53:                                               ; preds = %9, %7
  %54 = load ptr, ptr %2, align 8
  ret ptr %54
}

declare i32 @liquid_msb_index(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @windowcf_reset(ptr noundef) #3

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

!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 8}
!12 = !{!"windowcf_s", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28}
!13 = !{!12, !6, i64 12}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 20}
!16 = !{!12, !6, i64 24}
!17 = !{!12, !10, i64 0}
!18 = !{!12, !6, i64 28}


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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @windowcf_create(i32 noundef %0) local_unnamed_addr #2 {
  %2 = icmp eq i32 %0, 0
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef nonnull @.str.8, i32 noundef 49, ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.2) #3
  br label %21

5:                                                ; preds = %1
  %6 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %0, ptr %7, align 8, !tbaa !5
  %8 = tail call i32 @liquid_msb_index(i32 noundef %0) #3
  %9 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %8, ptr %9, align 4, !tbaa !11
  %10 = shl nuw i32 1, %8
  %11 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %10, ptr %11, align 8, !tbaa !12
  %12 = add i32 %10, -1
  %13 = getelementptr inbounds i8, ptr %6, i64 20
  store i32 %12, ptr %13, align 4, !tbaa !13
  %14 = add i32 %12, %0
  %15 = getelementptr inbounds i8, ptr %6, i64 24
  store i32 %14, ptr %15, align 8, !tbaa !14
  %16 = zext i32 %14 to i64
  %17 = shl nuw nsw i64 %16, 3
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #4
  store ptr %18, ptr %6, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %6, i64 28
  store i32 0, ptr %19, align 4, !tbaa !16
  %20 = tail call i32 @windowcf_reset(ptr noundef nonnull %6)
  br label %21

21:                                               ; preds = %5, %3
  %.0 = phi ptr [ %4, %3 ], [ %6, %5 ]
  ret ptr %.0
}

declare i32 @liquid_msb_index(i32 noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #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 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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, !10, i64 8}
!6 = !{!"windowcf_s", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 20}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 28}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass