; LLVM IR from dbry/wavpack-stream :: src (pack_utils)

; 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.WavpackContext = type { %struct.WavpackStreamConfig, ptr, i32, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i8, ptr, ptr, i32, i32, ptr, [8 x i8], ptr, [80 x i8] }
%struct.WavpackStreamConfig = type { float, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x i8], i8, i32, ptr }

; 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
declare hidden i32 @add_to_metadata(ptr noundef, ptr noundef, i32 noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @WavpackStreamAddWrapper(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i64 @WavpackStreamGetSampleIndex64(ptr noundef %9)
  store i64 %10, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %11 = load i64, ptr %7, align 8, !tbaa !11
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %16

13:                                               ; preds = %3
  %14 = load i64, ptr %7, align 8, !tbaa !11
  %15 = icmp eq i64 %14, -1
  br i1 %15, label %16, label %27

16:                                               ; preds = %13, %3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.WavpackContext, ptr %17, i32 0, i32 31
  store i32 1, ptr %18, align 4, !tbaa !13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.WavpackContext, ptr %19, i32 0, i32 38
  %21 = load i8, ptr %20, align 8, !tbaa !17
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 35, i32 33
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %8, align 1, !tbaa !18
  br label %41

27:                                               ; preds = %13
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.WavpackContext, ptr %29, i32 0, i32 29
  %31 = load i32, ptr %30, align 4, !tbaa !19
  %32 = add i32 %31, %28
  store i32 %32, ptr %30, align 4, !tbaa !19
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.WavpackContext, ptr %33, i32 0, i32 38
  %35 = load i8, ptr %34, align 8, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = icmp ne i32 %36, 0
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 36, i32 34
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %8, align 1, !tbaa !18
  br label %41

41:                                               ; preds = %27, %16
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load i8, ptr %8, align 1, !tbaa !18
  %46 = call i32 @add_to_metadata(ptr noundef %42, ptr noundef %43, i32 noundef %44, i8 noundef zeroext %45)
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %46
}

declare i64 @WavpackStreamGetSampleIndex64(ptr noundef) #2

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 = { "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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 268}
!14 = !{!"WavpackContext", !15, i64 0, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !10, i64 216, !10, i64 220, !10, i64 224, !10, i64 228, !10, i64 232, !10, i64 236, !10, i64 240, !10, i64 244, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !6, i64 288, !6, i64 296, !7, i64 304, !6, i64 312, !6, i64 320, !10, i64 328, !10, i64 332, !6, i64 336, !7, i64 344, !6, i64 352, !7, i64 360}
!15 = !{!"", !16, i64 0, !16, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 72, !10, i64 76, !6, i64 80}
!16 = !{!"float", !7, i64 0}
!17 = !{!14, !7, i64 304}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !10, i64 260}


; 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
declare hidden i32 @add_to_metadata(ptr noundef, ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @WavpackStreamAddWrapper(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @WavpackStreamGetSampleIndex64(ptr noundef %0) #2
  %5 = add i64 %4, 1
  %or.cond = icmp ult i64 %5, 2
  br i1 %or.cond, label %6, label %11

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 268
  store i32 1, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 304
  %9 = load i8, ptr %8, align 8, !tbaa !14
  %.not12 = icmp eq i8 %9, 0
  %10 = select i1 %.not12, i8 33, i8 35
  br label %18

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 260
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = add i32 %13, %2
  store i32 %14, ptr %12, align 4, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %0, i64 304
  %16 = load i8, ptr %15, align 8, !tbaa !14
  %.not = icmp eq i8 %16, 0
  %17 = select i1 %.not, i8 34, i8 36
  br label %18

18:                                               ; preds = %11, %6
  %.0 = phi i8 [ %10, %6 ], [ %17, %11 ]
  %19 = tail call i32 @add_to_metadata(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %2, i8 noundef zeroext %.0)
  ret i32 %19
}

declare i64 @WavpackStreamGetSampleIndex64(ptr noundef) local_unnamed_addr #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 = { "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, !11, i64 268}
!6 = !{!"WavpackContext", !7, i64 0, !12, i64 88, !11, i64 96, !11, i64 100, !12, i64 104, !11, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !13, i64 168, !13, i64 176, !13, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !11, i64 232, !11, i64 236, !11, i64 240, !11, i64 244, !11, i64 248, !11, i64 252, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !12, i64 288, !12, i64 296, !9, i64 304, !12, i64 312, !12, i64 320, !11, i64 328, !11, i64 332, !12, i64 336, !9, i64 344, !12, i64 352, !9, i64 360}
!7 = !{!"", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !9, i64 56, !9, i64 72, !11, i64 76, !12, i64 80}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!6, !9, i64 304}
!15 = !{!6, !11, i64 260}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass