; LLVM IR from AnzoDK/RPAudio :: includes/minimp3 (minimp3_test)

; 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.mp3dec_frame_info_t = type { i32, i32, i32, i32, i32, i32 }
%struct.mp3dec_ex_t = type { %struct.mp3dec_t, %struct.mp3dec_map_info_t, ptr, %struct.mp3dec_index_t, i64, i64, i64, i64, i64, i64, %struct.mp3dec_frame_info_t, [2304 x i16], i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.mp3dec_t = type { [2 x [288 x float]], [960 x float], i32, i32, [4 x i8], [511 x i8] }
%struct.mp3dec_map_info_t = type { ptr, i64 }
%struct.mp3dec_index_t = type { ptr, i64, i64 }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 dso_local i64 @mp3dec_ex_read_frame(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i64 @mp3dec_ex_read(ptr noundef %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca %struct.mp3dec_frame_info_t, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %25, label %18

18:                                               ; preds = %15, %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mp3dec_ex_t, ptr %22, i32 0, i32 23
  store i32 -1, ptr %23, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %21, %18
  store i64 0, ptr %4, align 8
  br label %55

25:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 4 %8, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %26, ptr %9, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %50, %25
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %51

30:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = call i64 @mp3dec_ex_read_frame(ptr noundef %31, ptr noundef %10, ptr noundef %8, i64 noundef %32)
  store i64 %33, ptr %11, align 8, !tbaa !9
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  store i32 3, ptr %12, align 4
  br label %48

37:                                               ; preds = %30
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = mul i64 %40, 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %38, ptr align 2 %39, i64 %41, i1 false)
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds i16, ptr %43, i64 %42
  store ptr %44, ptr %6, align 8, !tbaa !5
  %45 = load i64, ptr %11, align 8, !tbaa !9
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = sub i64 %46, %45
  store i64 %47, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %48

48:                                               ; preds = %37, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %49 = load i32, ptr %12, align 4
  switch i32 %49, label %57 [
    i32 0, label %50
    i32 3, label %51
  ]

50:                                               ; preds = %48
  br label %27, !llvm.loop !18

51:                                               ; preds = %48, %27
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = sub i64 %52, %53
  store i64 %54, ptr %4, align 8
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #4
  br label %55

55:                                               ; preds = %51, %24
  %56 = load i64, ptr %4, align 8
  ret i64 %56

57:                                               ; preds = %48
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !14, i64 11452}
!12 = !{!"", !13, i64 0, !15, i64 6672, !6, i64 6688, !16, i64 6696, !10, i64 6720, !10, i64 6728, !10, i64 6736, !10, i64 6744, !10, i64 6752, !10, i64 6760, !17, i64 6768, !7, i64 6792, !10, i64 11400, !10, i64 11408, !14, i64 11416, !14, i64 11420, !14, i64 11424, !14, i64 11428, !14, i64 11432, !14, i64 11436, !14, i64 11440, !14, i64 11444, !14, i64 11448, !14, i64 11452}
!13 = !{!"", !7, i64 0, !7, i64 2304, !14, i64 6144, !14, i64 6148, !7, i64 6152, !7, i64 6156}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !6, i64 0, !10, i64 8}
!16 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16}
!17 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.mp3dec_frame_info_t = type { i32, i32, i32, i32, i32, i32 }

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @mp3dec_ex_read_frame(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @mp3dec_ex_read(ptr noundef %0, ptr noundef writeonly %1, i64 noundef %2) local_unnamed_addr #3 {
  %4 = alloca %struct.mp3dec_frame_info_t, align 4
  %5 = alloca ptr, align 8
  %6 = icmp ne ptr %0, null
  %7 = icmp ne ptr %1, null
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %11, label %8

8:                                                ; preds = %3
  br i1 %6, label %9, label %19

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %0, i64 11452
  store i32 -1, ptr %10, align 4, !tbaa !5
  br label %19

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %4, i8 0, i64 24, i1 false)
  %.not34 = icmp eq i64 %2, 0
  br i1 %.not34, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %11, %13
  %.02036 = phi ptr [ %16, %13 ], [ %1, %11 ]
  %.02135 = phi i64 [ %17, %13 ], [ %2, %11 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store ptr null, ptr %5, align 8, !tbaa !16
  %12 = call i64 @mp3dec_ex_read_frame(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef nonnull %4, i64 noundef %.02135)
  %.not27 = icmp eq i64 %12, 0
  br i1 %.not27, label %.thread, label %13

.thread:                                          ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %.loopexit

13:                                               ; preds = %.lr.ph
  %14 = load ptr, ptr %5, align 8, !tbaa !16
  %15 = shl i64 %12, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %.02036, ptr align 2 %14, i64 %15, i1 false)
  %16 = getelementptr inbounds i16, ptr %.02036, i64 %12
  %17 = sub i64 %.02135, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  %.not = icmp eq i64 %17, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %13, %11, %.thread
  %.02133 = phi i64 [ %.02135, %.thread ], [ 0, %11 ], [ 0, %13 ]
  %18 = sub i64 %2, %.02133
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  br label %19

19:                                               ; preds = %8, %9, %.loopexit
  %.019 = phi i64 [ %18, %.loopexit ], [ 0, %9 ], [ 0, %8 ]
  ret i64 %.019
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !10, i64 11452}
!6 = !{!"", !7, i64 0, !11, i64 6672, !12, i64 6688, !14, i64 6696, !13, i64 6720, !13, i64 6728, !13, i64 6736, !13, i64 6744, !13, i64 6752, !13, i64 6760, !15, i64 6768, !8, i64 6792, !13, i64 11400, !13, i64 11408, !10, i64 11416, !10, i64 11420, !10, i64 11424, !10, i64 11428, !10, i64 11432, !10, i64 11436, !10, i64 11440, !10, i64 11444, !10, i64 11448, !10, i64 11452}
!7 = !{!"", !8, i64 0, !8, i64 2304, !10, i64 6144, !10, i64 6148, !8, i64 6152, !8, i64 6156}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !12, i64 0, !13, i64 8}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"", !12, i64 0, !13, i64 8, !13, i64 16}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!16 = !{!12, !12, i64 0}


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