; LLVM IR from GPUOpen-LibrariesAndSDKs/TAN :: tan/common/wav.ll (ZN10WavContent12JoinChannelsEv)

; 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.WavContent = type <{ i16, i32, i16, i32, %"class.std::vector" }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE5frontEv(ptr noundef nonnull align 1 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10WavContent12JoinChannelsEv(ptr noundef nonnull align 1 dereferenceable(36) %0) #1 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %struct.WavContent, ptr %8, i32 0, i32 0
  %10 = load i16, ptr %9, align 1, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = icmp ne i32 2, %11
  br i1 %12, label %13, label %19

13:                                               ; preds = %1
  %14 = getelementptr inbounds %struct.WavContent, ptr %8, i32 0, i32 2
  %15 = load i16, ptr %14, align 1, !tbaa !17
  %16 = zext i16 %15 to i32
  %17 = icmp ne i32 16, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  store i1 false, ptr %2, align 1
  br label %62

19:                                               ; preds = %13, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %20 = getelementptr inbounds %struct.WavContent, ptr %8, i32 0, i32 4
  %21 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE5frontEv(ptr noundef nonnull align 1 dereferenceable(24) %20) #2
  store ptr %21, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !18
  br label %22

22:                                               ; preds = %58, %19
  %23 = load i32, ptr %5, align 4, !tbaa !18
  %24 = getelementptr inbounds %struct.WavContent, ptr %8, i32 0, i32 1
  %25 = load i32, ptr %24, align 1, !tbaa !19
  %26 = icmp ult i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %61

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %29 = load i32, ptr %5, align 4, !tbaa !18
  %30 = mul i32 %29, 2
  %31 = add i32 %30, 0
  store i32 %31, ptr %6, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %32 = load i32, ptr %5, align 4, !tbaa !18
  %33 = mul i32 %32, 2
  %34 = add i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !18
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !18
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i16, ptr %35, i64 %37
  %39 = load i16, ptr %38, align 2, !tbaa !20
  %40 = sext i16 %39 to i32
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !18
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i16, ptr %41, i64 %43
  %45 = load i16, ptr %44, align 2, !tbaa !20
  %46 = sext i16 %45 to i32
  %47 = add nsw i32 %40, %46
  %48 = sdiv i32 %47, 2
  %49 = trunc i32 %48 to i16
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !18
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i16, ptr %50, i64 %52
  store i16 %49, ptr %53, align 2, !tbaa !20
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !18
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i16, ptr %54, i64 %56
  store i16 %49, ptr %57, align 2, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %58

58:                                               ; preds = %28
  %59 = load i32, ptr %5, align 4, !tbaa !18
  %60 = add i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !18
  br label %22, !llvm.loop !21

61:                                               ; preds = %27
  store i1 true, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %62

62:                                               ; preds = %61, %18
  %63 = load i1, ptr %2, align 1
  ret i1 %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS10WavContent", !11, i64 0, !12, i64 2, !11, i64 6, !12, i64 8, !13, i64 12}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSSt6vectorIhSaIhEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!10, !11, i64 6}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !12, i64 2}
!20 = !{!11, !11, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE5frontEv(ptr noundef nonnull align 1 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10WavContent12JoinChannelsEv(ptr noundef nonnull align 1 dereferenceable(36) %0) local_unnamed_addr #0 align 2 {
  %2 = load i16, ptr %0, align 1, !tbaa !5
  %.not = icmp eq i16 %2, 2
  %3 = getelementptr inbounds i8, ptr %0, i64 6
  %4 = load i16, ptr %3, align 1
  %.not14 = icmp eq i16 %4, 16
  %or.cond = select i1 %.not, i1 true, i1 %.not14
  br i1 %or.cond, label %5, label %.loopexit

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE5frontEv(ptr noundef nonnull align 1 dereferenceable(24) %6) #1
  %8 = getelementptr inbounds i8, ptr %0, i64 2
  %9 = load i32, ptr %8, align 1, !tbaa !16
  %.not17 = icmp eq i32 %9, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext i32 %9 to i64
  %min.iters.check = icmp ult i32 %9, 12
  br i1 %min.iters.check, label %.lr.ph.preheader23, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph.preheader
  %10 = add nsw i64 %wide.trip.count, -1
  %11 = icmp ugt i64 %10, 4294967295
  %mul.result = shl nsw i64 %10, 2
  %12 = getelementptr i8, ptr %7, i64 %mul.result
  %13 = icmp ult ptr %12, %7
  %scevgep = getelementptr i8, ptr %7, i64 2
  %mul.result20 = shl nsw i64 %10, 2
  %14 = getelementptr i8, ptr %scevgep, i64 %mul.result20
  %15 = icmp ult ptr %14, %scevgep
  %16 = or i1 %13, %11
  %17 = or i1 %15, %16
  br i1 %17, label %.lr.ph.preheader23, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %wide.trip.count, 4294967292
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %18 = shl i64 %index, 1
  %19 = and i64 %18, 4294967288
  %20 = getelementptr inbounds i16, ptr %7, i64 %19
  %wide.vec = load <8 x i16>, ptr %20, align 2, !tbaa !17
  %strided.vec = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec22 = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %21 = sext <4 x i16> %strided.vec to <4 x i32>
  %22 = sext <4 x i16> %strided.vec22 to <4 x i32>
  %23 = add nsw <4 x i32> %22, %21
  %24 = sdiv <4 x i32> %23, <i32 2, i32 2, i32 2, i32 2>
  %25 = trunc nsw <4 x i32> %24 to <4 x i16>
  %26 = shufflevector <4 x i16> %25, <4 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
  %interleaved.vec = shufflevector <8 x i16> %26, <8 x i16> poison, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
  store <8 x i16> %interleaved.vec, ptr %20, align 2, !tbaa !17
  %index.next = add nuw i64 %index, 4
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader23

.lr.ph.preheader23:                               ; preds = %middle.block, %vector.scevcheck, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader23 ]
  %28 = trunc nuw i64 %indvars.iv to i32
  %29 = shl i32 %28, 1
  %30 = or disjoint i32 %29, 1
  %31 = zext i32 %29 to i64
  %32 = getelementptr inbounds i16, ptr %7, i64 %31
  %33 = load i16, ptr %32, align 2, !tbaa !17
  %34 = sext i16 %33 to i32
  %35 = zext i32 %30 to i64
  %36 = getelementptr inbounds i16, ptr %7, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !17
  %38 = sext i16 %37 to i32
  %39 = add nsw i32 %38, %34
  %40 = sdiv i32 %39, 2
  %41 = trunc nsw i32 %40 to i16
  store i16 %41, ptr %36, align 2, !tbaa !17
  store i16 %41, ptr %32, align 2, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !22

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %5, %1
  ret i1 %or.cond
}

attributes #0 = { 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 #1 = { 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, !7, i64 0}
!6 = !{!"_ZTS10WavContent", !7, i64 0, !10, i64 2, !7, i64 6, !10, i64 8, !11, i64 12}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSSt6vectorIhSaIhEE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!6, !10, i64 2}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !19, !20}


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