; LLVM IR from jgaeddert/liquid-dsp :: src/modem/src (modem_utilities)

; 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"

@.str.105 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.112 = external hidden unnamed_addr constant [60 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

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

; 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 @liquid_unpack_soft_bits(i32 noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = icmp ugt i32 %9, 8
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef @.str.105, i32 noundef 304, ptr noundef @.str.112, i32 noundef 8)
  store i32 %12, ptr %4, align 4
  br label %38

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %34, %13
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %18, label %37

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sub i32 %20, %21
  %23 = sub i32 %22, 1
  %24 = lshr i32 %19, %23
  %25 = and i32 %24, 1
  %26 = icmp ne i32 %25, 0
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 255, i32 0
  %29 = trunc i32 %28 to i8
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  store i8 %29, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %18
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = add i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !12

37:                                               ; preds = %14
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %38

38:                                               ; preds = %37, %11
  %39 = load i32, ptr %4, align 4
  ret i32 %39
}

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

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str.105 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.112 = external hidden unnamed_addr constant [60 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @liquid_unpack_soft_bits(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = icmp ugt i32 %1, 8
  br i1 %4, label %61, label %.preheader

.preheader:                                       ; preds = %3
  %.not12 = icmp eq i32 %1, 0
  br i1 %.not12, label %.loopexit, label %vector.body

vector.body:                                      ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %1 to i64
  %trip.count.minus.1 = add nsw i64 %wide.trip.count, -1
  %broadcast.splatinsert = insertelement <8 x i64> poison, i64 %trip.count.minus.1, i64 0
  %broadcast.splat = shufflevector <8 x i64> %broadcast.splatinsert, <8 x i64> poison, <8 x i32> zeroinitializer
  %5 = icmp uge <8 x i64> %broadcast.splat, <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7>
  %6 = extractelement <8 x i1> %5, i64 0
  br i1 %6, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %7 = add nsw i32 %1, -1
  %8 = shl nuw i32 1, %7
  %9 = and i32 %8, %0
  %10 = icmp ne i32 %9, 0
  %11 = sext i1 %10 to i8
  store i8 %11, ptr %2, align 1, !tbaa !5
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %12 = extractelement <8 x i1> %5, i64 1
  br i1 %12, label %pred.store.if14, label %pred.store.continue15

pred.store.if14:                                  ; preds = %pred.store.continue
  %13 = add nsw i32 %1, -2
  %14 = shl nuw i32 1, %13
  %15 = and i32 %14, %0
  %16 = icmp ne i32 %15, 0
  %17 = getelementptr inbounds i8, ptr %2, i64 1
  %18 = sext i1 %16 to i8
  store i8 %18, ptr %17, align 1, !tbaa !5
  br label %pred.store.continue15

pred.store.continue15:                            ; preds = %pred.store.if14, %pred.store.continue
  %19 = extractelement <8 x i1> %5, i64 2
  br i1 %19, label %pred.store.if16, label %pred.store.continue17

pred.store.if16:                                  ; preds = %pred.store.continue15
  %20 = add nsw i32 %1, -3
  %21 = shl nuw i32 1, %20
  %22 = and i32 %21, %0
  %23 = icmp ne i32 %22, 0
  %24 = getelementptr inbounds i8, ptr %2, i64 2
  %25 = sext i1 %23 to i8
  store i8 %25, ptr %24, align 1, !tbaa !5
  br label %pred.store.continue17

pred.store.continue17:                            ; preds = %pred.store.if16, %pred.store.continue15
  %26 = extractelement <8 x i1> %5, i64 3
  br i1 %26, label %pred.store.if18, label %pred.store.continue19

pred.store.if18:                                  ; preds = %pred.store.continue17
  %27 = add nsw i32 %1, -4
  %28 = shl nuw i32 1, %27
  %29 = and i32 %28, %0
  %30 = icmp ne i32 %29, 0
  %31 = getelementptr inbounds i8, ptr %2, i64 3
  %32 = sext i1 %30 to i8
  store i8 %32, ptr %31, align 1, !tbaa !5
  br label %pred.store.continue19

pred.store.continue19:                            ; preds = %pred.store.if18, %pred.store.continue17
  %33 = extractelement <8 x i1> %5, i64 4
  br i1 %33, label %pred.store.if20, label %pred.store.continue21

pred.store.if20:                                  ; preds = %pred.store.continue19
  %34 = add nsw i32 %1, -5
  %35 = shl nuw i32 1, %34
  %36 = and i32 %35, %0
  %37 = icmp ne i32 %36, 0
  %38 = getelementptr inbounds i8, ptr %2, i64 4
  %39 = sext i1 %37 to i8
  store i8 %39, ptr %38, align 1, !tbaa !5
  br label %pred.store.continue21

pred.store.continue21:                            ; preds = %pred.store.if20, %pred.store.continue19
  %40 = extractelement <8 x i1> %5, i64 5
  br i1 %40, label %pred.store.if22, label %pred.store.continue23

pred.store.if22:                                  ; preds = %pred.store.continue21
  %41 = add nsw i32 %1, -6
  %42 = shl nuw i32 1, %41
  %43 = and i32 %42, %0
  %44 = icmp ne i32 %43, 0
  %45 = getelementptr inbounds i8, ptr %2, i64 5
  %46 = sext i1 %44 to i8
  store i8 %46, ptr %45, align 1, !tbaa !5
  br label %pred.store.continue23

pred.store.continue23:                            ; preds = %pred.store.if22, %pred.store.continue21
  %47 = extractelement <8 x i1> %5, i64 6
  br i1 %47, label %pred.store.if24, label %pred.store.continue25

pred.store.if24:                                  ; preds = %pred.store.continue23
  %48 = add nsw i32 %1, -7
  %49 = shl nuw i32 1, %48
  %50 = and i32 %49, %0
  %51 = icmp ne i32 %50, 0
  %52 = getelementptr inbounds i8, ptr %2, i64 6
  %53 = sext i1 %51 to i8
  store i8 %53, ptr %52, align 1, !tbaa !5
  br label %pred.store.continue25

pred.store.continue25:                            ; preds = %pred.store.if24, %pred.store.continue23
  %54 = extractelement <8 x i1> %5, i64 7
  br i1 %54, label %pred.store.if26, label %.loopexit

pred.store.if26:                                  ; preds = %pred.store.continue25
  %55 = add nsw i32 %1, -8
  %56 = shl nuw i32 1, %55
  %57 = and i32 %56, %0
  %58 = icmp ne i32 %57, 0
  %59 = getelementptr inbounds i8, ptr %2, i64 7
  %60 = sext i1 %58 to i8
  store i8 %60, ptr %59, align 1, !tbaa !5
  br label %.loopexit

61:                                               ; preds = %3
  %62 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef nonnull @.str.105, i32 noundef 304, ptr noundef nonnull @.str.112, i32 noundef 8) #2
  br label %.loopexit

.loopexit:                                        ; preds = %pred.store.continue25, %pred.store.if26, %.preheader, %61
  %.09 = phi i32 [ %62, %61 ], [ 0, %.preheader ], [ 0, %pred.store.if26 ], [ 0, %pred.store.continue25 ]
  ret i32 %.09
}

attributes #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass