; LLVM IR from jgaeddert/liquid-dsp :: src/utility/src (pack_bytes)

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

@.str = external hidden unnamed_addr constant [83 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

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

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

32:                                               ; preds = %5
  %33 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 9, ptr noundef @.str, i32 noundef 192, ptr noundef @.str.5)
  store i32 %33, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %88

34:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %17) #4
  store i8 0, ptr %17, align 1, !tbaa !14
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %68, %34
  %36 = load i32, ptr %15, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ult i32 %36, %37
  br i1 %38, label %39, label %71

39:                                               ; preds = %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !14
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 1
  %47 = load i8, ptr %17, align 1, !tbaa !14
  %48 = zext i8 %47 to i32
  %49 = or i32 %48, %46
  %50 = trunc i32 %49 to i8
  store i8 %50, ptr %17, align 1, !tbaa !14
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = add i32 %51, 1
  %53 = urem i32 %52, 8
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %39
  %56 = load i8, ptr %17, align 1, !tbaa !14
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i32, ptr %16, align 4, !tbaa !9
  %59 = add i32 %58, 1
  store i32 %59, ptr %16, align 4, !tbaa !9
  %60 = zext i32 %58 to i64
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  store i8 %56, ptr %61, align 1, !tbaa !14
  store i8 0, ptr %17, align 1, !tbaa !14
  br label %67

62:                                               ; preds = %39
  %63 = load i8, ptr %17, align 1, !tbaa !14
  %64 = zext i8 %63 to i32
  %65 = shl i32 %64, 1
  %66 = trunc i32 %65 to i8
  store i8 %66, ptr %17, align 1, !tbaa !14
  br label %67

67:                                               ; preds = %62, %55
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = add i32 %69, 1
  store i32 %70, ptr %15, align 4, !tbaa !9
  br label %35, !llvm.loop !15

71:                                               ; preds = %35
  %72 = load i32, ptr %15, align 4, !tbaa !9
  %73 = urem i32 %72, 8
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %85

75:                                               ; preds = %71
  %76 = load i8, ptr %17, align 1, !tbaa !14
  %77 = zext i8 %76 to i32
  %78 = ashr i32 %77, 1
  %79 = trunc i32 %78 to i8
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load i32, ptr %16, align 4, !tbaa !9
  %82 = add i32 %81, 1
  store i32 %82, ptr %16, align 4, !tbaa !9
  %83 = zext i32 %81 to i64
  %84 = getelementptr inbounds i8, ptr %80, i64 %83
  store i8 %79, ptr %84, align 1, !tbaa !14
  br label %85

85:                                               ; preds = %75, %71
  %86 = load i32, ptr %16, align 4, !tbaa !9
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %86, ptr %87, align 4, !tbaa !9
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %88

88:                                               ; preds = %85, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %89 = load i32, ptr %6, align 4
  ret i32 %89
}

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 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 = !{!"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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [31 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_pack_bytes(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2, i32 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %6 = tail call i64 @div(i32 noundef %1, i32 noundef 8) #3
  %.sroa.0.0.extract.trunc = trunc i64 %6 to i32
  %.sroa.4.0.extract.shift = lshr i64 %6, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %7 = icmp sgt i32 %.sroa.4.0.extract.trunc, 0
  %8 = zext i1 %7 to i32
  %9 = add i32 %8, %.sroa.0.0.extract.trunc
  %10 = icmp ugt i32 %9, %3
  br i1 %10, label %12, label %.preheader

.preheader:                                       ; preds = %5
  %.not30 = icmp eq i32 %1, 0
  br i1 %.not30, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %1, 1
  br i1 %11, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %.lr.ph

12:                                               ; preds = %5
  %13 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 9, ptr noundef nonnull @.str, i32 noundef 192, ptr noundef nonnull @.str.5) #4
  br label %51

.lr.ph:                                           ; preds = %31, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %31 ]
  %.027 = phi i8 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %31 ]
  %.02126 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %.122.1, %31 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %31 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = and i8 %15, 1
  %17 = or i8 %16, %.027
  %18 = shl i8 %17, 1
  %19 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = and i8 %20, 1
  %22 = or i8 %21, %18
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %23 = and i64 %indvars.iv.next.1, 6
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %27, label %25

25:                                               ; preds = %.lr.ph
  %26 = shl i8 %22, 1
  br label %31

27:                                               ; preds = %.lr.ph
  %28 = add i32 %.02126, 1
  %29 = zext i32 %.02126 to i64
  %30 = getelementptr inbounds i8, ptr %2, i64 %29
  store i8 %22, ptr %30, align 1, !tbaa !5
  br label %31

31:                                               ; preds = %27, %25
  %.122.1 = phi i32 [ %28, %27 ], [ %.02126, %25 ]
  %.1.1 = phi i8 [ 0, %27 ], [ %26, %25 ]
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !8

._crit_edge.unr-lcssa:                            ; preds = %31, %.lr.ph.preheader
  %.122.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.122.1, %31 ]
  %.1.lcssa.ph = phi i8 [ poison, %.lr.ph.preheader ], [ %.1.1, %31 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %31 ]
  %.027.unr = phi i8 [ 0, %.lr.ph.preheader ], [ %.1.1, %31 ]
  %.02126.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %.122.1, %31 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %32 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.unr
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = and i8 %33, 1
  %35 = or i8 %34, %.027.unr
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.unr, 1
  %36 = and i64 %indvars.iv.next.epil, 7
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %40, label %38

38:                                               ; preds = %.lr.ph.epil
  %39 = shl i8 %35, 1
  br label %._crit_edge

40:                                               ; preds = %.lr.ph.epil
  %41 = add i32 %.02126.unr, 1
  %42 = zext i32 %.02126.unr to i64
  %43 = getelementptr inbounds i8, ptr %2, i64 %42
  store i8 %35, ptr %43, align 1, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %38, %40, %._crit_edge.unr-lcssa
  %.122.lcssa = phi i32 [ %.122.lcssa.ph, %._crit_edge.unr-lcssa ], [ %41, %40 ], [ %.02126.unr, %38 ]
  %.1.lcssa = phi i8 [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ 0, %40 ], [ %39, %38 ]
  %44 = and i32 %1, 7
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %._crit_edge.thread, label %46

46:                                               ; preds = %._crit_edge
  %47 = lshr exact i8 %.1.lcssa, 1
  %48 = add i32 %.122.lcssa, 1
  %49 = zext i32 %.122.lcssa to i64
  %50 = getelementptr inbounds i8, ptr %2, i64 %49
  store i8 %47, ptr %50, align 1, !tbaa !5
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader, %46, %._crit_edge
  %.2 = phi i32 [ %48, %46 ], [ %.122.lcssa, %._crit_edge ], [ 0, %.preheader ]
  store i32 %.2, ptr %4, align 4, !tbaa !10
  br label %51

51:                                               ; preds = %._crit_edge.thread, %12
  %.024 = phi i32 [ %13, %12 ], [ 0, %._crit_edge.thread ]
  ret i32 %.024
}

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

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 = { 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 willreturn memory(none) }
attributes #4 = { 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


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