; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/modules/juce_audio_formats/codecs/flac/libFLAC/str_1c39f355_FLAC (fixed)

; 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.FLAC__Subframe_Fixed = type { %struct.FLAC__EntropyCodingMethod, i32, [4 x i32], ptr }
%struct.FLAC__EntropyCodingMethod = type { i32, %union.anon.1 }
%union.anon.1 = type { %struct.FLAC__EntropyCodingMethod_PartitionedRice }
%struct.FLAC__EntropyCodingMethod_PartitionedRice = type { i32, ptr }
%struct.FLAC__EntropyCodingMethod_PartitionedRiceContents = type { ptr, ptr, i32 }

@FLAC__SUBFRAME_ZERO_PAD_LEN = external constant i32, align 4
@FLAC__SUBFRAME_TYPE_LEN = external constant i32, align 4
@FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = external constant i32, align 4
@FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = external constant i32, align 4

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

declare i32 @FLAC__bitwriter_write_raw_uint32(ptr noundef, i32 noundef, i32 noundef) #1

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

declare i32 @FLAC__bitwriter_write_unary_unsigned(ptr noundef, i32 noundef) #1

declare i32 @FLAC__bitwriter_write_raw_int32(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @FLAC__subframe_add_fixed(ptr noundef %0, i32 noundef %1, i32 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 i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  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 4, ptr %12) #3
  %14 = load ptr, ptr %11, align 8, !tbaa !5
  %15 = load i32, ptr @FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK, align 4, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = shl i32 %18, 1
  %20 = or i32 %15, %19
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, i32 1, i32 0
  %25 = or i32 %20, %24
  %26 = load i32, ptr @FLAC__SUBFRAME_ZERO_PAD_LEN, align 4, !tbaa !9
  %27 = load i32, ptr @FLAC__SUBFRAME_TYPE_LEN, align 4, !tbaa !9
  %28 = add i32 %26, %27
  %29 = load i32, ptr @FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN, align 4, !tbaa !9
  %30 = add i32 %28, %29
  %31 = call i32 @FLAC__bitwriter_write_raw_uint32(ptr noundef %14, i32 noundef %25, i32 noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %120

34:                                               ; preds = %5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %45

37:                                               ; preds = %34
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = sub i32 %39, 1
  %41 = call i32 @FLAC__bitwriter_write_unary_unsigned(ptr noundef %38, i32 noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %120

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44, %34
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %65, %45
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = icmp ult i32 %47, %50
  br i1 %51, label %52, label %68

52:                                               ; preds = %46
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds [4 x i32], ptr %55, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = call i32 @FLAC__bitwriter_write_raw_int32(ptr noundef %53, i32 noundef %59, i32 noundef %60)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %64, label %63

63:                                               ; preds = %52
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %120

64:                                               ; preds = %52
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = add i32 %66, 1
  store i32 %67, ptr %12, align 4, !tbaa !9
  br label %46, !llvm.loop !14

68:                                               ; preds = %46
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %70, i32 0, i32 0
  %72 = call i32 @add_entropy_coding_method_(ptr noundef %69, ptr noundef %71)
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %75, label %74

74:                                               ; preds = %68
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %120

75:                                               ; preds = %68
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %78, align 8, !tbaa !16
  switch i32 %79, label %118 [
    i32 0, label %80
    i32 1, label %80
  ]

80:                                               ; preds = %75, %75
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %82, i32 0, i32 3
  %84 = load ptr, ptr %83, align 8, !tbaa !17
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 8, !tbaa !11
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod, ptr %90, i32 0, i32 1
  %92 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod_PartitionedRice, ptr %91, i32 0, i32 1
  %93 = load ptr, ptr %92, align 8, !tbaa !18
  %94 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod_PartitionedRiceContents, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !19
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %96, i32 0, i32 0
  %98 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod, ptr %97, i32 0, i32 1
  %99 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod_PartitionedRice, ptr %98, i32 0, i32 1
  %100 = load ptr, ptr %99, align 8, !tbaa !18
  %101 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod_PartitionedRiceContents, ptr %100, i32 0, i32 1
  %102 = load ptr, ptr %101, align 8, !tbaa !21
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %103, i32 0, i32 0
  %105 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod, ptr %104, i32 0, i32 1
  %106 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod_PartitionedRice, ptr %105, i32 0, i32 0
  %107 = load i32, ptr %106, align 8, !tbaa !18
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.FLAC__Subframe_Fixed, ptr %108, i32 0, i32 0
  %110 = getelementptr inbounds %struct.FLAC__EntropyCodingMethod, ptr %109, i32 0, i32 0
  %111 = load i32, ptr %110, align 8, !tbaa !16
  %112 = icmp eq i32 %111, 1
  %113 = zext i1 %112 to i32
  %114 = call i32 @add_residual_partitioned_rice_(ptr noundef %81, ptr noundef %84, i32 noundef %85, i32 noundef %88, ptr noundef %95, ptr noundef %102, i32 noundef %107, i32 noundef %113)
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %117, label %116

116:                                              ; preds = %80
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %120

117:                                              ; preds = %80
  br label %119

118:                                              ; preds = %75
  br label %119

119:                                              ; preds = %118, %117
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %120

120:                                              ; preds = %119, %116, %74, %63, %43, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %121 = load i32, ptr %6, align 4
  ret i32 %121
}

; Function Attrs: nounwind uwtable
declare hidden i32 @add_entropy_coding_method_(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @add_residual_partitioned_rice_(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

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


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

@FLAC__SUBFRAME_ZERO_PAD_LEN = external local_unnamed_addr constant i32, align 4
@FLAC__SUBFRAME_TYPE_LEN = external local_unnamed_addr constant i32, align 4
@FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = external local_unnamed_addr constant i32, align 4
@FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = external local_unnamed_addr constant i32, align 4

declare i32 @FLAC__bitwriter_write_raw_uint32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @FLAC__bitwriter_write_unary_unsigned(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @FLAC__bitwriter_write_raw_int32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @FLAC__subframe_add_fixed(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = load i32, ptr @FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = shl i32 %8, 1
  %.not = icmp ne i32 %3, 0
  %10 = zext i1 %.not to i32
  %11 = or i32 %6, %10
  %12 = or i32 %11, %9
  %13 = load i32, ptr @FLAC__SUBFRAME_ZERO_PAD_LEN, align 4, !tbaa !5
  %14 = load i32, ptr @FLAC__SUBFRAME_TYPE_LEN, align 4, !tbaa !5
  %15 = add i32 %14, %13
  %16 = load i32, ptr @FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN, align 4, !tbaa !5
  %17 = add i32 %15, %16
  %18 = tail call i32 @FLAC__bitwriter_write_raw_uint32(ptr noundef %4, i32 noundef %12, i32 noundef %17) #2
  %.not26 = icmp eq i32 %18, 0
  br i1 %.not26, label %.loopexit, label %19

19:                                               ; preds = %5
  br i1 %.not, label %20, label %23

20:                                               ; preds = %19
  %21 = add i32 %3, -1
  %22 = tail call i32 @FLAC__bitwriter_write_unary_unsigned(ptr noundef %4, i32 noundef %21) #2
  %.not27 = icmp eq i32 %22, 0
  br i1 %.not27, label %.loopexit, label %23

23:                                               ; preds = %20, %19
  %24 = load i32, ptr %7, align 8, !tbaa !9
  %.not32 = icmp eq i32 %24, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %23
  %25 = getelementptr inbounds i8, ptr %0, i64 28
  br label %30

26:                                               ; preds = %30
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = load i32, ptr %7, align 8, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %indvars.iv.next, %28
  br i1 %29, label %30, label %._crit_edge, !llvm.loop !13

30:                                               ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %31 = getelementptr inbounds [4 x i32], ptr %25, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = tail call i32 @FLAC__bitwriter_write_raw_int32(ptr noundef %4, i32 noundef %32, i32 noundef %2) #2
  %.not30 = icmp eq i32 %33, 0
  br i1 %.not30, label %.loopexit, label %26

._crit_edge:                                      ; preds = %26, %23
  %34 = tail call i32 @add_entropy_coding_method_(ptr noundef %4, ptr noundef nonnull %0)
  %.not28 = icmp eq i32 %34, 0
  br i1 %.not28, label %.loopexit, label %35

35:                                               ; preds = %._crit_edge
  %36 = load i32, ptr %0, align 8, !tbaa !15
  %switch = icmp ult i32 %36, 2
  br i1 %switch, label %37, label %51

37:                                               ; preds = %35
  %38 = getelementptr inbounds i8, ptr %0, i64 48
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load i32, ptr %7, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %0, i64 8
  %42 = getelementptr inbounds i8, ptr %0, i64 16
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = getelementptr inbounds i8, ptr %43, i64 8
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = load i32, ptr %41, align 8, !tbaa !17
  %48 = icmp eq i32 %36, 1
  %49 = zext i1 %48 to i32
  %50 = tail call i32 @add_residual_partitioned_rice_(ptr noundef %4, ptr noundef %39, i32 noundef %1, i32 noundef %40, ptr noundef %44, ptr noundef %46, i32 noundef %47, i32 noundef %49)
  %.not29 = icmp eq i32 %50, 0
  br i1 %.not29, label %.loopexit, label %51

51:                                               ; preds = %35, %37
  br label %.loopexit

.loopexit:                                        ; preds = %30, %37, %._crit_edge, %20, %5, %51
  %.024 = phi i32 [ 1, %51 ], [ 0, %5 ], [ 0, %20 ], [ 0, %._crit_edge ], [ 0, %37 ], [ 0, %30 ]
  ret i32 %.024
}

; Function Attrs: nounwind uwtable
declare hidden i32 @add_entropy_coding_method_(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @add_residual_partitioned_rice_(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"", !11, i64 0, !6, i64 24, !7, i64 28, !12, i64 48}
!11 = !{!"", !6, i64 0, !7, i64 8}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !12, i64 48}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !12, i64 0}
!19 = !{!"", !12, i64 0, !12, i64 8, !6, i64 16}
!20 = !{!19, !12, i64 8}


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