; LLVM IR from jgaeddert/liquid-dsp :: src/sequence/src (bsequence)

; 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.div_t = type { i32, i32 }
%struct.bsequence_s = type { ptr, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local ptr @bsequence_create(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.div_t, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %6 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %6, ptr %3, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.bsequence_s, ptr %7, i32 0, i32 4
  store i32 0, ptr %8, align 4, !tbaa !11
  %9 = load ptr, ptr %3, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.bsequence_s, ptr %9, i32 0, i32 0
  store ptr null, ptr %10, align 8, !tbaa !13
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.bsequence_s, ptr %12, i32 0, i32 1
  store i32 %11, ptr %13, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %14 = load ptr, ptr %3, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.bsequence_s, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = call i64 @div(i32 noundef %16, i32 noundef 32) #6
  store i64 %17, ptr %4, align 4
  %18 = getelementptr inbounds %struct.div_t, ptr %4, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = load ptr, ptr %3, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.bsequence_s, ptr %20, i32 0, i32 4
  store i32 %19, ptr %21, align 4, !tbaa !11
  %22 = getelementptr inbounds %struct.div_t, ptr %4, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = icmp sgt i32 %23, 0
  %25 = zext i1 %24 to i64
  %26 = select i1 %24, i32 1, i32 0
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.bsequence_s, ptr %27, i32 0, i32 4
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = add i32 %29, %26
  store i32 %30, ptr %28, align 4, !tbaa !11
  %31 = getelementptr inbounds %struct.div_t, ptr %4, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %1
  br label %39

35:                                               ; preds = %1
  %36 = getelementptr inbounds %struct.div_t, ptr %4, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %38 = zext i32 %37 to i64
  br label %39

39:                                               ; preds = %35, %34
  %40 = phi i64 [ 32, %34 ], [ %38, %35 ]
  %41 = trunc i64 %40 to i32
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.bsequence_s, ptr %42, i32 0, i32 2
  store i32 %41, ptr %43, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %44 = load ptr, ptr %3, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.bsequence_s, ptr %44, i32 0, i32 3
  store i32 0, ptr %45, align 8, !tbaa !19
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %61, %39
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.bsequence_s, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !18
  %51 = icmp ult i32 %47, %50
  br i1 %51, label %52, label %64

52:                                               ; preds = %46
  %53 = load ptr, ptr %3, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.bsequence_s, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !19
  %56 = shl i32 %55, 1
  store i32 %56, ptr %54, align 8, !tbaa !19
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.bsequence_s, ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 8, !tbaa !19
  %60 = or i32 %59, 1
  store i32 %60, ptr %58, align 8, !tbaa !19
  br label %61

61:                                               ; preds = %52
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !20

64:                                               ; preds = %46
  %65 = load ptr, ptr %3, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.bsequence_s, ptr %65, i32 0, i32 4
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = zext i32 %67 to i64
  %69 = mul i64 %68, 4
  %70 = call noalias ptr @malloc(i64 noundef %69) #5
  %71 = load ptr, ptr %3, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.bsequence_s, ptr %71, i32 0, i32 0
  store ptr %70, ptr %72, align 8, !tbaa !13
  %73 = load ptr, ptr %3, align 8, !tbaa !9
  %74 = call i32 @bsequence_reset(ptr noundef %73)
  %75 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %75
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare i64 @div(i32 noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @bsequence_reset(ptr noundef) #0

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

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 = { 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 #3 = { nounwind willreturn memory(none) "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) }
attributes #6 = { nounwind willreturn memory(none) }

!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 20}
!12 = !{!"bsequence_s", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4}
!17 = !{!16, !6, i64 4}
!18 = !{!12, !6, i64 12}
!19 = !{!12, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @bsequence_create(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  %3 = getelementptr inbounds i8, ptr %2, i64 20
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %0, ptr %4, align 8, !tbaa !5
  %5 = tail call i64 @div(i32 noundef %0, i32 noundef 32) #4
  %.sroa.0.0.extract.trunc = trunc i64 %5 to i32
  %.sroa.4.0.extract.shift = lshr i64 %5, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %6 = icmp sgt i32 %.sroa.4.0.extract.trunc, 0
  %7 = zext i1 %6 to i32
  %8 = add i32 %7, %.sroa.0.0.extract.trunc
  store i32 %8, ptr %3, align 4, !tbaa !11
  %9 = icmp ult i64 %5, 4294967296
  %10 = select i1 %9, i32 32, i32 %.sroa.4.0.extract.trunc
  %11 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 %10, ptr %11, align 4, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 0, ptr %12, align 8, !tbaa !13
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %20, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i32 %10, 7
  %13 = icmp ult i32 %10, 8
  br i1 %13, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %10, -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %14 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %16, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %15 = shl i32 %14, 8
  %16 = or disjoint i32 %15, 255
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !14

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %16, %.lr.ph ]
  %.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %16, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %17 = phi i32 [ %19, %.lr.ph.epil ], [ %.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %18 = shl i32 %17, 1
  %19 = or disjoint i32 %18, 1
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %19, %.lr.ph.epil ]
  store i32 %.lcssa, ptr %12, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %._crit_edge, %1
  %21 = zext i32 %8 to i64
  %22 = shl nuw nsw i64 %21, 2
  %23 = tail call noalias ptr @malloc(i64 noundef %22) #3
  store ptr %23, ptr %2, align 8, !tbaa !18
  %24 = tail call i32 @bsequence_reset(ptr noundef nonnull %2)
  ret ptr %2
}

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare i64 @div(i32 noundef, i32 noundef) local_unnamed_addr #2

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

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 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 #2 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 allocsize(0) }
attributes #4 = { nounwind willreturn memory(none) }

!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 = !{!"bsequence_s", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!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 20}
!12 = !{!6, !10, i64 12}
!13 = !{!6, !10, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass