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

; 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 uwtable
define dso_local i32 @bsequence_init(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  store i8 -128, ptr %8, align 1, !tbaa !11
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %41, %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.bsequence_s, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = icmp ult i32 %10, %13
  br i1 %14, label %15, label %44

15:                                               ; preds = %9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = urem i32 %16, 8
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %26

19:                                               ; preds = %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = add i32 %21, 1
  store i32 %22, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %21 to i64
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  store i8 %25, ptr %7, align 1, !tbaa !11
  store i8 -128, ptr %8, align 1, !tbaa !11
  br label %26

26:                                               ; preds = %19, %15
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i8, ptr %7, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = load i8, ptr %8, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = and i32 %29, %31
  %33 = icmp ne i32 %32, 0
  %34 = zext i1 %33 to i64
  %35 = select i1 %33, i32 1, i32 0
  %36 = call i32 @bsequence_push(ptr noundef %27, i32 noundef %35)
  %37 = load i8, ptr %8, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = ashr i32 %38, 1
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %8, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %26
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !14

44:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @bsequence_push(ptr noundef, i32 noundef) #1

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 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"bsequence_s", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!14 = distinct !{!14, !15}
!15 = !{!"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 i32 @bsequence_init(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not18 = icmp eq i32 %4, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %12
  %.017 = phi i32 [ %18, %12 ], [ 128, %2 ]
  %.0916 = phi i8 [ %.110, %12 ], [ 0, %2 ]
  %.01115 = phi i32 [ %.112, %12 ], [ 0, %2 ]
  %.01314 = phi i32 [ %19, %12 ], [ 0, %2 ]
  %5 = and i32 %.01314, 7
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %12

7:                                                ; preds = %.lr.ph
  %8 = add i32 %.01115, 1
  %9 = zext i32 %.01115 to i64
  %10 = getelementptr inbounds i8, ptr %1, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !11
  br label %12

12:                                               ; preds = %7, %.lr.ph
  %.112 = phi i32 [ %8, %7 ], [ %.01115, %.lr.ph ]
  %.110 = phi i8 [ %11, %7 ], [ %.0916, %.lr.ph ]
  %.1 = phi i32 [ 128, %7 ], [ %.017, %.lr.ph ]
  %13 = zext i8 %.110 to i32
  %14 = and i32 %.1, %13
  %.not = icmp ne i32 %14, 0
  %15 = zext i1 %.not to i32
  %16 = tail call i32 @bsequence_push(ptr noundef nonnull %0, i32 noundef %15)
  %17 = lshr i32 %.1, 1
  %18 = and i32 %17, 127
  %19 = add nuw i32 %.01314, 1
  %20 = load i32, ptr %3, align 8, !tbaa !5
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %12, %2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @bsequence_push(ptr noundef, i32 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" }

!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 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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