; LLVM IR from sp-nitech/SPTK :: third_party/REAPER/wave (wave_io)

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

%"class.sptk::reaper::WaveIO" = type { %"class.sptk::reaper::CodecApi", i32 }
%"class.sptk::reaper::CodecApi" = type { i32, i32, %"class.sptk::reaper::WavRiffCodec" }
%"class.sptk::reaper::WavRiffCodec" = type { i32 }

@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk6reaper6WaveIO10ReadHeaderEPNS0_12FileResourceEPiS4_(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  %13 = getelementptr inbounds %"class.sptk::reaper::WaveIO", ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  switch i32 %14, label %31 [
    i32 0, label %15
    i32 1, label %15
    i32 2, label %15
  ]

15:                                               ; preds = %4, %4, %4
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %16 = getelementptr inbounds %"class.sptk::reaper::WaveIO", ptr %12, i32 0, i32 0
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call noundef zeroext i1 @_ZN4sptk6reaper8CodecApiINS0_12WavRiffCodecEE10ReadHeaderEPNS0_12FileResourceE(ptr noundef nonnull align 4 dereferenceable(12) %16, ptr noundef %17)
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %10, align 1, !tbaa !15
  %20 = load i8, ptr %10, align 1, !tbaa !15, !range !17, !noundef !18
  %21 = trunc i8 %20 to i1
  br i1 %21, label %23, label %22

22:                                               ; preds = %15
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %30

23:                                               ; preds = %15
  %24 = getelementptr inbounds %"class.sptk::reaper::WaveIO", ptr %12, i32 0, i32 0
  %25 = call noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE27get_num_samples_per_channelEv(ptr noundef nonnull align 4 dereferenceable(12) %24)
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %25, ptr %26, align 4, !tbaa !19
  %27 = getelementptr inbounds %"class.sptk::reaper::WaveIO", ptr %12, i32 0, i32 0
  %28 = call noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE17get_sampling_rateEv(ptr noundef nonnull align 4 dereferenceable(12) %27)
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %28, ptr %29, align 4, !tbaa !19
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %30

30:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %37

31:                                               ; preds = %4
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.sptk::reaper::WaveIO", ptr %12, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.2, i32 noundef %34) #5
  br label %36

36:                                               ; preds = %31
  store i1 false, ptr %5, align 1
  br label %37

37:                                               ; preds = %36, %30
  %38 = load i1, ptr %5, align 1
  ret i1 %38
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4sptk6reaper8CodecApiINS0_12WavRiffCodecEE10ReadHeaderEPNS0_12FileResourceE(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE27get_num_samples_per_channelEv(ptr noundef nonnull align 4 dereferenceable(12)) #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE17get_sampling_rateEv(ptr noundef nonnull align 4 dereferenceable(12)) #4 align 2

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

attributes #0 = { nounwind "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 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !14, i64 12}
!10 = !{!"_ZTSN4sptk6reaper6WaveIOE", !11, i64 0, !14, i64 12}
!11 = !{!"_ZTSN4sptk6reaper8CodecApiINS0_12WavRiffCodecEEE", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSN4sptk6reaper12WavRiffCodecE", !14, i64 0}
!14 = !{!"_ZTSN4sptk6reaper14WaveCodingTypeE", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !12, i64 0}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk6reaper6WaveIO10ReadHeaderEPNS0_12FileResourceEPiS4_(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %switch = icmp ult i32 %6, 3
  br i1 %switch, label %7, label %12

7:                                                ; preds = %4
  %8 = tail call noundef zeroext i1 @_ZN4sptk6reaper8CodecApiINS0_12WavRiffCodecEE10ReadHeaderEPNS0_12FileResourceE(ptr noundef nonnull align 4 dereferenceable(12) %0, ptr noundef %1)
  br i1 %8, label %9, label %15

9:                                                ; preds = %7
  %10 = tail call noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE27get_num_samples_per_channelEv(ptr noundef nonnull align 4 dereferenceable(12) %0)
  store i32 %10, ptr %2, align 4, !tbaa !13
  %11 = tail call noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE17get_sampling_rateEv(ptr noundef nonnull align 4 dereferenceable(12) %0)
  store i32 %11, ptr %3, align 4, !tbaa !13
  br label %15

12:                                               ; preds = %4
  %13 = load ptr, ptr @stderr, align 8, !tbaa !14
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.2, i32 noundef %6) #4
  br label %15

15:                                               ; preds = %9, %7, %12
  %.1 = phi i1 [ false, %12 ], [ false, %7 ], [ true, %9 ]
  ret i1 %.1
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4sptk6reaper8CodecApiINS0_12WavRiffCodecEE10ReadHeaderEPNS0_12FileResourceE(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE27get_num_samples_per_channelEv(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6reaper8CodecApiINS0_12WavRiffCodecEE17get_sampling_rateEv(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #3 align 2

attributes #0 = { nofree nounwind "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 = { mustprogress 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 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 = { cold 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, !12, i64 12}
!6 = !{!"_ZTSN4sptk6reaper6WaveIOE", !7, i64 0, !12, i64 12}
!7 = !{!"_ZTSN4sptk6reaper8CodecApiINS0_12WavRiffCodecEEE", !8, i64 0, !8, i64 4, !11, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN4sptk6reaper12WavRiffCodecE", !12, i64 0}
!12 = !{!"_ZTSN4sptk6reaper14WaveCodingTypeE", !9, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !9, i64 0}


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